60 lines
988 B
Text
60 lines
988 B
Text
section .text
|
|
global _start
|
|
|
|
_print:
|
|
mov ebx, 1
|
|
mov eax, 4
|
|
int 0x80
|
|
ret
|
|
|
|
_get_input:
|
|
mov edx, 4
|
|
mov ebx, 0
|
|
mov eax, 3
|
|
int 0x80
|
|
ret
|
|
|
|
_start:
|
|
mov edx, in_val_len
|
|
mov ecx, in_val_msg
|
|
call _print
|
|
mov ecx, a
|
|
call _get_input
|
|
;make 'a' an actual number rather than a char.
|
|
sub dword [a], 0x30
|
|
mov edx, in_val_len
|
|
mov ecx, in_val_msg
|
|
call _print
|
|
mov ecx, b
|
|
call _get_input
|
|
;calc real number for 'b'
|
|
sub dword [b], 0x30
|
|
mov eax, dword [a]
|
|
mov ebx, dword [b]
|
|
add eax, ebx
|
|
;get the character for our sum.
|
|
add eax, 0x30
|
|
mov dword [sum], eax
|
|
mov edx, out_val_len
|
|
mov ecx, out_val_msg
|
|
call _print
|
|
mov [sum+1], dword 0xa
|
|
mov edx, 4
|
|
mov ecx, sum
|
|
call _print
|
|
push 0x1
|
|
mov eax, 1
|
|
push eax
|
|
int 0x80
|
|
ret
|
|
|
|
section .data
|
|
in_val_msg db "Please input an integer:",0
|
|
in_val_len equ $-in_val_msg
|
|
out_val_msg db "The sum of a+b is: ",0
|
|
out_val_len equ $-out_val_msg
|
|
|
|
section .bss
|
|
a resd 1
|
|
b resd 1
|
|
sum resd 1
|