0
\$\begingroup\$

I have a doubt regarding the usage of the ADD instruction in Intel 8086 microprocessor.Don't ADD AX,BX and ADD AX,[BX] mean the same thing?

\$\endgroup\$
4
\$\begingroup\$

ADD AX, BX

This adds the contents of register BX to the contents of AX and leaves the result in AX.

ADD AX, [BX]

This one uses the contents of register BX as an offset address to a memory location. The 16-bit contents of that memory location is added to the contents of AX and leaves the result in AX.

\$\endgroup\$
  • \$\begingroup\$ Oh...ok..Thank you.So what do the square brackets indicate? \$\endgroup\$ – Susan Jun 16 '17 at 16:54
  • 1
    \$\begingroup\$ @Susan - The meaning of the square brackets should be very obvious from the description I gave in the answer. But to put into different words the [ and ] signify indirection. That means use the contained item "BX" in this case as an address instead of as direct data. \$\endgroup\$ – Michael Karas Jun 16 '17 at 17:02
  • \$\begingroup\$ Horse, water, take, you, to, can, a - rearrange to make the opening words of a well-known saying. \$\endgroup\$ – Andy aka Jun 16 '17 at 17:33
2
\$\begingroup\$

Just as a bit of added clarity: Those are instructions to an assembler. They are not machine instructions directly to an Intel 8086 CPU. The assembler translates them into machine instructions. But different assemblers might translate the same syntax into different instructions, depending on the assembler. Luckily, in the case of the 8088/8086 and later families, there was a great deal of standardization and the Microsoft assembler tended to accept very similar things to the Intel assembler. However, Borland went a bit far off the reservation, so to speak.

No, they don't do the same thing. The 8086 CPU supports an indirect mode, where a register is treated as holding an address of a value rather than the value itself. The brackets surrounding the register, as in [BX], were used by the assembler to signal that the assembler was to produce one of these addressing modes.

The 8086 only supported a few of the registers in this mode, though. And when using this mode, a segment register (which holds a selector value) was always paired up. The allowed registers for indirect mode in the 8086 were BX, SI, DI, and BP. By default (without an "override" given), the BX, SI, and DI registers were implicitly paired up with the DS (data) segment register and the BP register was implicitly paired up with the SS (stack) segment register.

In your example, ADD AX, BX would add the contents of BX into the contents of AX, leaving AX with the new result (destroying its old contents.) On the other hand, ADD AX, [BX], would fetch the 16-bit value located by the pairing of DS:BX, used as a segmented address, and add the value found there to the AX register.

On the 8086, the DS register also holds a 16-bit value. So, the first step used by the 8086 in combining the DS segment register with the address held in the indirect-mode BX register is to multiply the DS value by 16 and then add in the BX register in order to produce a 20-bit value (the carry is lost.) The 8086 supported only a 20-bit address bus, so this was sufficient to construct a full, external address to use in accessing memory.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.