3

An instruction from the instruction set of intel 8085 that is SBI data (Subtract immediate with borrow) . This instruction says "The contents of the second byte of the instruction and the contents of the CY flag are both subtracted from the accumulator. The result is placed in the accumulator."

Or

(A) <-- (A) -(byte 2) - (CY)

In this what does second byte or byte mean ?

Also in the instruction STA addr (Store immediate address) which says "The content of the accumulator is moved to the memory location whose address is specified in byte 2 and byte 3 of the instruction." What does byte 2 and byte 3 mean ?

Suhail Gupta
  • 278
  • 1
  • 5
  • 14
  • If this is a wrong place to post this question please tell appropriate one – Suhail Gupta Jan 17 '12 at 19:30
  • 3
    Seems completely appropriate to me. – Olin Lathrop Jan 17 '12 at 20:41
  • 1
    This is actually a programming topic and I would move it to stackoverflow. – Al Kepp Jan 19 '12 at 07:08
  • 2
    Assembly on a processor is so close to firmware that I am not sure making the distinction is valuable. A few questions on the boundary for us are okay as long as they stay technical and can get good answers. We do all have to read some assembly to do firmware, what is the harm here. I would enjoy hearing other views if someone dissents on this opinion. – Kortuk Jan 19 '12 at 12:47

4 Answers4

3

Instructions are made up of a variable number of "words" and those words are made up of bits. In the case of the 8085 architecture, you can have instructions that are one, two, or three words long, and each word is 8-bits. Those bits are divided up into fields based on your instruction set. What fields there are and what those fields mean is usually contextually sensitive based on the value of one field that always has the same meaning. Typically this field is referred to as the "op code." You should read in detail at least chapter 8 of the linked pdf to get a thorough understanding.

In the case of instructions that operate on registers and store their results in a register, the source and target registers need to be identified in some fields in the instruction. In the case of an instruction that adds a constant to a register and stores the result in a register, the registers still need to be identified, but the constant also needs to be encoded in the instruction in its own field. In instruction set architectures, the term "immediate" is often used to mean a "constant value." In case of instructions that read from or write to memory, the location in memory may have to be encoded within the instruction.

That's the basic idea, hope this helps. For future reference, a good search term for questions like this is "Instruction Set Architecture" for your processor.


Edit Re: STA 4200

The STA instruction is described on page 3-61 (pg 117) of this Assembly Language Programming guide for 8080/8085 processors.The three bytes are:

  • Byte 1 = OpCode (00110010)
  • Byte 2 = Low Address Byte
  • Byte 3 = High Address Byte

STA is the "Store Accumulator Direct" instruction, and what it does is copies the value of the Accumulator into memory at the 16-bit address composed from Bytes 2 and 3.

vicatcu
  • 22,499
  • 13
  • 79
  • 155
  • can you please explain STA 4200 which stores the content of accumulator at 4200, w.r.t the terms _byte 2_ and _byte 3_ . I understand the instruction is 3 bytes long and the opcode is STA , but i don't understand the other two fields which make byte 2 and byte 3 – Suhail Gupta Jan 18 '12 at 04:40
  • @SuhailGupta have a look through chapter three of http://www.tramm.li/i8080/Intel%208080-8085%20Assembly%20Language%20Programming%201977%20Intel.pdf – vicatcu Jan 18 '12 at 18:11
1

You apparently have 2-byte and 3-byte instructions. The first byte is apparently the opcode in these cases. The SBI instruction only has a single byte of data beyond the opcode, so the data byte is the second byte of the instruction. Similarly, the address the STA instruction operates on is in the second and third bytes of the instruction, with the first byte presumably being the opcode.

Note this is all speculation from what you said and vague memories of the x86 instruction set. I have not looked up anything to confirm it. That's your job.

Olin Lathrop
  • 310,974
  • 36
  • 428
  • 915
0

The second byte presumably contains the value that is to be subtracted from the value in the accumulator.

The second and third bytes that you ask about in connection with the STA instruction contain an address - a 16-bit value which has to be specified as two 8-bit bytes.

Examining some assembled code using those instructions should help.

Leon Heller
  • 38,774
  • 2
  • 60
  • 96
0

Let's look at a fragment of machine code: (This is from stoned-b, but most executable code for many processors looks similar).

...
1000:0148 BB0002        MOV     BX,0200
1000:014B 33C9          XOR     CX,CX
1000:014D 8BD1          MOV     DX,CX
1000:014F 41            INC     CX
...

In most computers, "byte" means a single addressable unit of memory containing 8 bytes.

This example shows that the byte value "BB" is stored in location 1000:0148, the byte value "00" is stored in 1000:0149, the byte "02" is stored in 1000:014A, the byte "33" is stored in 1000:014B, and so on.

Programs are stored in memory. Some processors have variable-length instructions -- as you can see in this example, the first instruction occupies 3 bytes, the next instructions occupy 2 bytes each, and the last instruction requires only 1 byte.

The "byte 1" of the first instruction in this example is "BB", "byte 2" is "00", and "byte 3" is "02".

The "byte 1" of the next instruction in this example is "33", "byte 2" is "C9", and it doesn't have a "byte 3".

Variable-length instruction sets, such as the 8085 and the one in this example, typically encode the opcode and the format of the instruction in the first byte. By examining only the first byte, the CPU can decode how many bytes long is the entire instruction, and what function this instruction does, and the "meaning" of the following bytes.

I hope that you and others will keep improving assembly language books, such as the "x86 Assembly" book, until they gives clear, easy-to-understand answers to this and related questions.

davidcary
  • 17,426
  • 11
  • 66
  • 115