アセンブリの問題を解決しようとしていて、なんとかコードを記述できましたが、結果を表示しているときに奇妙な出力が得られます。3 つの数字の 2 乗を足すことになっていましたが、そのうちの 1 つがマイナスです。これが私のコードです。これは、アセンブル、リンク、および実行に使用するものです。ありがとう!
コンパイルと実行の手順:
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