我试图解决汇编中的一个问题,我设法编写了代码,但是在显示结果时,我得到了一个奇怪的输出。我想添加 3 个数字的平方,其中一个是负数。这是我的代码,这是我用来组装、链接和运行的代码。谢谢!
编译和执行步骤:
nasm -g -f elf lab1.asm
gcc -o lab1 lab1.o
./lab
SECTION .data
message: db "Hello, this is Iva.", 0AH
anothermsg db "The sum of the numbers %d, %d and %d is %d", 0AH
len: equ $-message
variable1: dw 7
variable2: dw -11
variable3: dw 19
SECTION .text
extern printf
global main
main:
mov eax, dword [variable1]
movzx ebx, al
mov eax, ebx
imul eax
push eax
mov eax, dword [variable2]
movzx ebx,al
mov eax,ebx
imul eax
push eax
mov eax, dword [variable3]
movzx ebx,al
mov eax,ebx
imul eax
pop ebx
add eax,ebx
pop ebx
add eax,ebx
push eax
push dword [variable3]
push dword [variable2]
push dword [variable1]
push anothermsg
call printf
mov eax,1
mov ebx,0
int 80h