[pg.65][Content] Example 4.5.7 Compilation Error
garciaadrian opened this issue · comments
I can't compile example 4.5.7 to look at the assembled code. I'm compiling with nasm and it's giving me an invalid effective address error. I'm using the latest version of the book
bits 16
_start:
jmp [eax * 4 + eax + esi]
nasm -f elf32 start.asm -o start
For this section, you should not use elf32
but bin
format to see the generated an assembly instruction in its binary form. So, the content of the file should be like this, just a single line in the file:
jmp [eax * 4 + eax + esi]
Then, compile it with bin
format:
nasm -f bin start.asm -o start
Still doesn't compile. here's the error
start.asm:1: error: invalid effective address
DId you change elf32
to bin
? With bin
output, there should be no address calculation, just the raw binary form of instructions.
jmp [eax * 4 + eax + esi]
nasm -f bin start.asm -o start
The above fails on nasm 2.13.03 and yasm 1.3.0 with binary output format
I just tried compiling the test asm in your screenshot and it worked fine but nasm complains on example 4.5.7
Sorry I was mistaken. It's true that the example was incorrect. This should be the correct example:
You can't have more than 2 registers in an effective address calculation. This is shown with the table 4.5.3
, where the first column Effective Address
provides possible indexing methods: multiply by 1, 2, 4 and 8.
The next two column, SS
and R/M
when combined, provides a unique encoding of each method, For example, any register multiplied by 2 has the SS
value 10
. but for specific EAX*4
, the R/M
value needs to be 000
, together provides a unique 5-bit binary string 10000
.
Finally, the last 8 columns provides the offset stored in a register. In the provided screen above, the register chosen was esi
, thus the last 3-bit should be 110
(written on the ESI
column in the table 4.5.3
).
Together, a unique 8-bit string that identify this specific instruction jmp [eax * 4 + esi]
is formed. The 8-bit string is 10000110
, which is equivalent to 0x86
. You can look up the value 86
in table 4.5.3
to verify.
The example confused me since it had 3 registers, Thanks for clarifying and for this great book.