简体   繁体   English

如何在我的汇编程序中打印数字

[英]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_2val_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 看来你刚刚从MASMTASM切换到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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM