我有以下代码
section .bss
num1 resb 2
num2 resb 2
res1 resb 2
res2 resb 2
section .data
fir dw 'Ingrese el primer numero: '
lfir equ $ - fir
sec dw 'Ingrese el segundo numero: '
lsec equ $ - sec
newline db 10
section .text
global _start
_start:
mov dl,lfir ;print "Ingrese el primer numero: "
mov ecx,fir
mov bl,1
mov al,4
int 0x80
mov dl,5 ;read the first number
mov ecx,num1
mov bl,2
mov al,3
int 0x80
mov dl,lsec ;print "Ingrese el segundo numero: "
mov ecx,sec
mov bl,1
mov al,4
int 0x80
mov dl,5 ;read the second number
mov ecx,num2
mov bl,2
mov al,3
int 0x80
mov eax,[num1] ;move the first number into eax
mov ebx,[num2] ;move the second number to ebx
sub ebx,48 ;conver the number to decimal
add eax,ebx ;add the 2 numbers
mov [res1],eax ;move the result into "res1"
cmp eax, 57 ;check if the result has 2 digits
jle singledigit ;instructions when it has 2 digits
mov eax,[res1]
sub eax,10
mov [res1],eax
mov ebx,'1'
mov [res2],ebx
mov dl,2 ;print res2
mov ecx,res2
mov ebx,1
mov eax,4
int 0x80
mov dl,2 ;print res1
mov ecx,res1
mov ebx,1
mov eax,4
int 0x80
jmp finish
singledigit:
mov dl,2 ;print res1
mov ecx,res1
mov ebx,1
mov eax,4
int 0x80
jmp finish
finish:
mov dl,1 ;new line
mov ecx,newline
mov ebx,1
mov eax,4
int 0x80
mov al,1
int 0x80
它似乎总是会忽略个位数标签,因此当总和小于10时打印低于48的ascii字符(ascii 0),但当总和大于10时它工作正常
就像迈克尔说的,替换每一个
mov eax,[num1] 与
movzx eax,字节[num1];
对于 ebx 和 num2 来说也是如此,确实解决了问题