[英]How can I print numbers in my assembly program
I have a problem with my assembly program.我的汇编程序有问题。 My assembly compiler is NASM.
我的汇编编译器是 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()
.问题是我无法使用
extern C
函数printf()
从计算中打印数字。 How can I do it?我该怎么做?
The output should be "Ergebnis: 8" but it isn't correct.输出应该是“Ergebnis: 8”,但它不正确。
In NASM documentation it is pointed that NASM Requires Square Brackets For Memory References .在NASM 文档中指出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).当你写不带括号的标签名称时,
NASM
给出它的内存地址(或有时称为偏移量)。 So, mov eax, val_1
it means that eax
register gets val_1
's offset.因此,
mov eax, val_1
表示eax
寄存器获取val_1
的偏移量。 When you add eax, val_2
, val_2
offset is added to val_1
offset and you get the result you see.当你
add eax, val_2
, val_2
偏移量被添加到val_1
偏移量,你会得到你看到的结果。
Write instead:改写:
mov eax, [val_1]
add eax, [val_2]
And you shoul get 8
in eax.你应该在 eax 中得到
8
。
PS It seems that you have just switched to NASM
from MASM
or TASM
. PS 看来你刚刚从
MASM
或TASM
切换到NASM
。 There are a lot of guides for switchers like you.像您这样的切换台有很多指南。 See for example nice tutorials here and here .
例如在这里和这里看到不错的教程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.