Well, another typo in the getting of the second number. I probably altered this more than was strictly necessary, but I think it works now...
That's with an obedient user. If the pesky user enters one digit or three or a non-digit... you're borked.
Best,
Frank
extern printf
section .data
;; create the prompt and output format
prompt: db "Enter a number", 10, 0
fmt: db "%d plus %d equals %d", 10, 0
section .bss
;; create the variable that will hold the data
digit1: resb 2
digit2: resb 2
digit3: resb 2
digit4: resb 2
num0: resb 4
num1: resb 4
;; body of the program
section .text
global main
main:
push ebp
mov ebp, esp
push prompt ; push prompt to stack
call printf
mov eax, 3 ; read in the first digit, first number
mov ebx, 0
mov ecx, digit1
mov edx, 1
int 80h
mov eax, 3 ; read in second digit, first number
mov ebx, 0
mov ecx, digit2
mov edx, 2
int 80h
sub byte[digit1], 30h ; convert first digit to decimal value
sub byte[digit2], 30h ; convert second digit to decimal value
mov al, byte[digit1] ; move digit1 for multiplication
mov bl, 10 ; move 10 to bl for multiplication
; mov bl, 10 ; move 10 to bl for multiplication
mul bl ; multiply digit1 by 10 and save in al(ax!)
movzx bx, byte[digit2] ; extended move digit 2 to bx
add ax, bx ; add the first digit*10 and second digit
mov byte[num0], al ; put results in num0
push prompt ; display prompt
call printf
mov eax, 3 ; read in the first digit, second number
; mov eax, 0 ; whoa! where did that come from??? Oh.
mov ebx, 0
mov ecx, digit3
mov edx, 1
int 80h
mov eax, 3 ;read in the 2nd digit, second number
mov ebx, 0
mov ecx, digit4
mov edx, 2
int 80h ; !
sub byte[digit3], 30h ;convert digit3 to decimal value
sub byte[digit4], 30h ;convert digit4 to decimal value
mov al, byte[digit3] ; move digit3 for multiplication
mov bl, 10 ; move 10 to bl for multiplication
mul bl ; multiply digit 3 by 10
movzx bx, byte[digit4] ; extended move
add ax, bx ; combine digit 3 and 4
mov byte[num1], al ; save results in num1
mov eax, 0
add al, [num0]
add al, [num1] ; add number 1 and 2 to eax
push eax ; save result to stack
xor eax, eax ; or mov eax, 0
mov al, [num1] ; move result 2 to eax
push eax ; save to stack
xor eax, eax
mov al, [num0] ; move result 1 to eax
push eax ; save result 1 to stack
push fmt ; push the format to stack
call printf ; display the format with results
add esp, 24 ; return to where we were
mov esp, ebp
pop ebp
mov eax, 1 ; exit program
mov ebx, 0
ret