【发布时间】:2014-11-17 03:40:14
【问题描述】:
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 错误。感觉就像我已经尝试了几十种组合,但没有真正的运气。将变量添加到 sum 变量后,我还需要将结果打印到 stdout。
【问题讨论】:
标签: variables add nasm system-calls