-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharithmetic.asm
More file actions
145 lines (120 loc) · 2.13 KB
/
Copy patharithmetic.asm
File metadata and controls
145 lines (120 loc) · 2.13 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
EXIT equ 1
READ equ 3
WRITE equ 4
STDIN equ 0
STDOUT equ 1
section .data
msg1 db "Enter a digit: ",
len1 equ $-msg1
msg2 db "Enter another digit: ",
len2 equ $-msg2
msg3 db "The sum is: "
len3 equ $-msg3
msg4 db 0xA, 'Multiply of 3 and 2 is: '
len4 equ $-msg4
msg5 db 0xA, 'Division of 8 by 2 gives: '
len5 equ $-msg5
segment .bss
num1 resb 1
num2 resb 1
res resb 1
section .text
global _start
_start:
; read num1
mov eax, WRITE
mov ebx, STDOUT
mov ecx, msg1
mov edx, len1
int 0x80
mov eax, READ
mov ebx, STDIN
mov ecx, num1
mov edx, 1
int 0x80
; Read newline (discard)
mov eax, READ
mov ebx, STDIN
mov ecx, res
mov edx, 1
int 0x80
; read num2
mov eax, WRITE
mov ebx, STDOUT
mov ecx, msg2
mov edx, len2
int 0x80
mov eax, READ
mov ebx, STDIN
mov ecx, num2
mov edx, 1
int 0x80
; Read newline (discard)
mov eax, READ
mov ebx, STDIN
mov ecx, res
mov edx, 1
int 0x80
addsub:
mov eax, WRITE
mov ebx, STDOUT
mov ecx, msg3
mov edx, len3
int 0x80
mov al, [num1]
sub al, '0'
mov bl, [num2]
sub bl, '0'
add al, bl
add al, '0'
mov [res], al
mov eax, WRITE
mov ebx, STDOUT
mov ecx, res
mov edx, 1
int 0x80
multiply:
mov byte [num1], '3'
mov byte [num2], '2'
mov al, [num1]
sub al, '0'
mov bl, [num2]
sub bl, '0'
mul bl
add al, '0'
mov [res], al
mov ecx, msg4
mov edx, len4
mov ebx, STDOUT
mov eax, WRITE
int 0x80
mov ecx, res
mov edx, 1
mov ebx, STDOUT
mov eax, WRITE
int 0x80
divide:
mov byte [num1], '8'
mov byte [num2], '2'
mov al, [num1]
sub al, '0'
mov bl, [num2]
sub bl, '0'
xor ah, ah
div bl
add al, '0'
mov [res], al
mov ecx, msg5
mov edx, len5
mov ebx, STDOUT
mov eax, WRITE
int 0x80
mov ecx, res
mov edx, 1
mov ebx, STDOUT
mov eax, WRITE
int 0x80
exit:
xor ebx, ebx
mov eax, EXIT
int 0x80