I have a problem with my assembly program. My assembly compiler is NASM. The source and the outputs are in this picture:
The problem is that I can't print numbers from calculations with the extern C
function printf()
. How can I do it?
The output should be "Ergebnis: 8" but it isn't correct.
In NASM documentation it is pointed that NASM Requires Square Brackets For Memory References . When you write label name without bracket NASM
gives its memory address (or offset as it is called sometimes). So, mov eax, val_1
it means that eax
register gets val_1
's offset. When you add eax, val_2
, val_2
offset is added to val_1
offset and you get the result you see.
Write instead:
mov eax, [val_1]
add eax, [val_2]
And you shoul get 8
in eax.
PS It seems that you have just switched to NASM
from MASM
or TASM
. There are a lot of guides for switchers like you. See for example nice tutorials here and here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.