Question

I am reading a book about 80x86 assembly language entitled "Introduction to 80x86 Assembly Language and Computer Architecture Second Edition" by Richard C. Detmer. I am having a hard time understand Register Indirect Mode, my book says this:

"Our example program has no instruction with a register indirect memory operand. Here is what one looks like. The comment gives the object code you would see in a listing file.

add eax, [edx] ; 03 02

The first operand EAX obviously is register mode, and the second operand is register indirect mode. Notice that there only 2 bytes of object code, not enough to contain a 32-bit memory address. Instead, the second byte contains bits that say to use the address in the EDX register to locate the second doubleword operand. In other words, the second number is not in EDX, but its address is. The square bracket notation ([ ]) indicates indirect addressing in assembly language." -page 65 at the bottom (if you may have the textbook).

The book shows a picture of memory slots and the address of EDX's (address of operand) location in memory and its highlighted.

Okay I typed out that tiny section because I don't understand it, it says use the address in EDX to locate the second dword, but it says the second number isn't in EDX but its address is. What?? So we take the address of EDX, but how does that give us a number in memory? I thought the address just addresses EDX, and whatever contains in the register, so how can you not get a number from EDX and use only the memory address? The address points to EDX and what it contains, so if you use the address arent you typically getting the value in EDX? So wouldn't this statement below be the same?:

add eax, edx

If someone could give me some more insight on register indirect mode, with some examples, explanations, and answers to my questions above I would really appreciate that.

Was it helpful?

Solution

It's saying that EDX contains the address. That is, EDX is a pointer into memory. The [] is indicating that the assembler should choose the instruction opcode/addressing-mode that will dereference EDX and load the word of data at that location in memory into EAX. In C-like pseudocode:

eax = eax + *(uint32_t *)edx;

EDX, being a register, does not itself have an address - that concept is meaningless.

Your second example (add eax, edx) is something like:

eax = eax + edx;

Memory isn't accessed at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top