我正在尝试添加 2 个两位数,这必然会产生一个两位数或三位数的数字。
这是我到目前为止所拥有的,当我尝试打印进位时,它显示浮点异常(核心转储)
section .data
msg db "Enter 2 numbers: "
msgLen equ $-msg
section .bss
numa1 resb 1
numa2 resb 1
numb1 resb 1
numb2 resb 1
carry resb 1
section .text
global _start
_start:
;print message
mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, msgLen
int 80h
;accept first number (1st digit)
mov eax, 3
mov ebx, 0
mov ecx, numa1
mov edx, 1
int 80h
;accept first number (2nd digit)
mov eax, 3
mov ebx, 0
mov ecx, numa2
mov edx, 2
int 80h
;accept second number (1st digit)
mov eax, 3
mov ebx, 0
mov ecx, numb1
mov edx, 1
int 80h
;accept second number (2nd digit)
mov eax, 3
mov ebx, 0
mov ecx, numb2
mov edx, 2
int 80h
;character to number conversion
sub byte[numa1], 30h
sub byte[numa2], 30h
sub byte[numb1], 30h
sub byte[numb2], 30h
sub byte[carry], 30h
;;;;;;;;;;;;;;;;;;;;;;;;;;
;add ones digit
mov al, [numa2]
add byte[numb2], al
add byte[numb2], 30h
;get carry of sum of ones digit
mov ax, [numb2]
mov byte[carry], 10
div byte[carry]
mov eax, 4
mov ebx, 1
mov ecx, carry
mov edx, 1
int 80h
mov eax, 1
mov ebx, 0
int 80h
carry
numa1 numa2
+ numb2 numb2
---------------
numb2
where numb2 = numb2 % 10
carry = numb2 / 10