-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArithmetic_Operations.txt
127 lines (112 loc) · 2.96 KB
/
Arithmetic_Operations.txt
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
%macro write_string 2
mov ebx, 1 ;file descriptor (stdout)
mov eax, 4 ;system call number (sys_write);tell linker entry
mov ecx, %1 ;message to write
mov edx, %2 ;message length
int 0x80 ;call kernel
%endmacro
%macro accept 2
mov ebx,0
mov eax,3
mov ecx,%1
mov edx,%2
int 0x80 ;call kernel
%endmacro
;======================================================================================;
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
; display title
write_string msg,len
write_string newline, len8
write_string msg1, len1
accept num1,1
write_string num1,1
write_string newline, len8
write_string msg2, len2
accept num2,1
write_string num2,1
write_string newline, len8
write_string newline, len8
mov al, byte[num1]
sub al,'0'
mov bl, byte[num2]
sub bl,'0'
add al,bl
add al,'0'
mov byte[ans],al
; print addition
write_string add_msg,len3
write_string ans,1
write_string newline,len8
mov al, byte[num1]
sub al,'0'
mov bl, byte[num2]
sub bl,'0'
sub al,bl
add al,'0'
mov byte[ans],al
; print subtraction
write_string sub_msg,len4
write_string ans,1
write_string newline,len8
mov al, byte[num1]
sub al,'0'
mov bl, byte[num2]
sub bl,'0'
mul bl
add al,'0'
mov byte[ans],al
; print multiplication
write_string mul_msg,len5
write_string ans,1
write_string newline,len8
; calculate division
mov al, byte[num1]
sub al,'0'
mov bl, byte[num2]
sub bl,'0'
div bl
add al,'0'
add ah,'0'
mov byte[ans],al
mov byte[rem],ah
; print division
write_string div_msg,len6
write_string ans,1
write_string newline,len8
; print remainder
write_string rem_msg,len7
write_string rem,1
write_string newline,len8
; end program
mov eax,1
mov ebx,0
int 0x80 ;call kernel
;========================================================================================;
section .data
msg db 'ARITHMETIC OPERATIONS', 0xa
len equ $ - msg
msg1 db 'Enter first number: '
len1 equ $ - msg1
msg2 db 'Enter second number: '
len2 equ $ - msg2
add_msg db 'Addition is: '
len3 equ $ - add_msg
sub_msg db 'Subtraction is: '
len4 equ $ - sub_msg
mul_msg db 'Multiplication is: '
len5 equ $ - mul_msg
div_msg db 'Division is: '
len6 equ $ - div_msg
rem_msg db 'Remainder is: '
len7 equ $ - rem_msg
newline db " ", 0xa
len8 equ $ - newline
num1 db '0'
num2 db '0'
;======================================================================================;
section .bss
ans: resb 2
rem: resb 1
;======================================================================================;