-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.asm
More file actions
74 lines (52 loc) · 2.21 KB
/
add.asm
File metadata and controls
74 lines (52 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
; ********************************************************************************
; Program: Prints sum of two numbers taken from user
; ********************************************************************************
; custom libraries
%include "lib/io.asm"
%include "lib/cast.asm"
%define BUFFER_SIZE 16
section .bss
; used for io opertions
buffer resb BUFFER_SIZE
section .data
AskNum1 db "Num1: ", 0
len_AskNum1 equ $-AskNum1
AskNum2 db "Num2: ", 0
len_AskNum2 equ $-AskNum2
ShowNum db "Sum: ", 0
len_ShowNum equ $-ShowNum
chars_num1 dd 0
chars_num2 dd 0
chars_sum dd 0
num1 dd 0
num2 dd 0
sum dd 0
section .text
global _start
_start:
CallPrintStr AskNum1, len_AskNum1 ; prompt for num1
CallInputStr buffer, BUFFER_SIZE ; read input
mov [chars_num1], eax ; store input size
CallStr2Uint buffer, [chars_num1] ; convert from str to uint
mov [num1], eax ; store the uint value to num1
CallPrintStr AskNum2, len_AskNum2 ; prompt for num2
CallInputStr buffer, BUFFER_SIZE ; read input
mov [chars_num2], eax ; store input size
CallStr2Uint buffer, [chars_num2] ; convert from str to uint
mov [num2], eax ; store the uint value to num2
mov eax, [num1] ; load num1
add eax, [num2] ; add num2
mov [sum], eax ; store result in sum
CallUint2Str buffer, [sum] ; convert from uint to string
mov [chars_sum ], ecx ; storing the size of string
CallPrintStr ShowNum, len_ShowNum ; prompt for sum
mov eax, BUFFER_SIZE ; size of buffer
sub eax, [chars_sum] ; offset to start of number
lea ecx, [buffer+eax] ; get address of offset
mov edx, chars_sum ; size of sum
call PrintStr ; print buffer (sum)
Newline ; newline
exit:
mov eax, 1
xor ebx, ebx
int 0x80