0
global _start
section .data
section .bss ;declares 3 variables
num1: resb 4
num2: resb 4
sum: resb 4
section .text
_start:
mov ecx, num1
mov edx, 02h
call read
call write
mov ecx, num2
mov edx, 02h
call read2
call write2
;mov ecx, sum
;mov edx, 02h
mov ecx, num1
add ecx, num2
mov sum, ecx
je exit
exit: ;exits the program
mov eax, 01h ; exit()
xor ebx, ebx ; errno
int 80h
read: ;reads input from the keyboard and stores it in ecx
mov eax, 03h ; read()
mov ebx, 00h ; stdin
mov ecx, num1
int 80h
ret
read2: ;reads input from the keyboard and stores it in ecx
mov eax, 03h ; read()
mov ebx, 00h ; stdin
mov ecx, num2
int 80h
ret
write: ;outputs the contents of ecx to stdout
mov eax, 04h ; write()
mov ebx, 01h ; stdout
mov ecx, num1
int 80h
ret
write2: ;outputs the contents of ecx to stdout
mov eax, 04h ; write()
mov ebx, 01h ; stdout
mov ecx, num2
int 80h
ret
我需要添加2個變量一起幫忙。我一直從線mov sum, ecx
接收invalid combination of opcode and operands
錯誤。這感覺就像我嘗試了幾十種組合,沒有真正的運氣。一旦我得到加到總和變量的變量我還需要將結果打印到stdout
。NASM:如果添加2個變量