0% found this document useful (0 votes)
34 views4 pages

Menu Driver Calci

Uploaded by

Janhvi Bhangale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views4 pages

Menu Driver Calci

Uploaded by

Janhvi Bhangale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

%macro write 2 ;macro for write

mov eax,4 ;syscall for write


mov ebx,1 ;stdout
mov ecx,%1 ;string to be accepted
mov edx,%2 ;length of string
int 80h
%endmacro

%macro read 2 ;macro for read


mov eax,3 ;read syscall
mov ebx,0 ;stdin
mov ecx,%1 ;to be saved in
mov edx,%2 ;length of variable
int 80h
%endmacro

section .data

new db " ",0xa ;our dear string


lenn equ $ - new ;length of our dear string

new1 db "First Number is: " ;our dear string


lenn1 equ $ - new1 ;length of our dear string

new2 db "Second Number is: " ;our dear string


lenn2 equ $ - new2 ;length of our dear string

str1 db "*Menu*",0xa ;our dear string


lenstr1 equ $ - str1 ;length of our dear string

str2 db "1.Addition",0xa ;our dear string


lenstr2 equ $ - str2 ;length of our dear string

str3 db "2.Subtraction",0xa ;our dear string


lenstr3 equ $ - str3 ;length of our dear string

str4 db "3.Multiplication",0xa ;our dear string


lenstr4 equ $ - str4 ;length of our dear string

str5 db "4.Division",0xa ;our dear string


lenstr5 equ $ - str5 ;length of our dear string

str6 db "****",0xa ;our dear string


lenstr6 equ $ - str6 ;length of our dear string

msg db "Sum is: " ;our dear string


len equ $ - msg ;length of our dear string

msg1 db "Difference is: " ;our dear string


len1 equ $ - msg1 ;length of our dear string

msg2 db "Multiplication is: " ;our dear string


len2 equ $ - msg2 ;length of our dear string

msg3 db "Division of Numbers" ;our dear string


len3 equ $ - msg3 ;length of our dear string

msg4 db "Quotient is: " ;our dear string


len4 equ $ - msg4 ;length of our dear string
strn db "Remainder is: " ;our dear string
newlen equ $ - strn ;length of our dear string

msg5 db "Enter your choice: " ;our dear string


len5 equ $ - msg5 ;length of our dear string

msg6 db "Invalid choice: " ;our dear string


len6 equ $ - msg6 ;length of our dear string

num1 dw '9'
num1len equ $ - num1 ;length of our dear string

num2 dw '9'
num2len equ $ - num2 ;length of our dear string

segment .bss

opt resb 5 ;declaring uninitialized variable opt


res1 resb 2 ;declaring uninitialized variable res1
res2 resb 2 ;declaring uninitialized variable res2
quot resb 2 ;declaring uninitialized variable quot
rem resb 2 ;declaring uninitialized variable rem

section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point

write new1,lenn1
write num1,num1len

write new,lenn ;write new line

write new2,lenn2
write num2,num2len

write new,lenn ;write new line

write str1,lenstr1
write str2,lenstr2 ;printing menu
write str3,lenstr3
write str4,lenstr4
write str5,lenstr5
write str6,lenstr6

write new,lenn ;write new line

write msg5,len5
read opt,5
write opt,5
write new,lenn ;write new line

cmp byte[opt],'1'
je case1 ;jump if equal to case1
cmp byte[opt],'2'
je case2
cmp byte[opt],'3'
je case3
cmp byte[opt],'4'
je case4
cmp byte[opt],'5'
je case5
cmp byte[opt],'6'
je case5
cmp byte[opt],'7'
je case5
cmp byte[opt],'8'
je case5
cmp byte[opt],'9'
je case5
cmp byte[opt],'0'
je case5

case1:
call addition
jmp exit

case2:
call subtraction
jmp exit

case3:
call multiplication
jmp exit

case4:
call division
jmp exit

case5:
write msg6,len6
jmp exit

exit:
mov eax, 1 ;system call number (sys_exit)
mov ebx,0
int 0x80 ;call kernel

addition: ;addition procedure

mov al, [num1] ;num1 to eax


sub al, 0x30 ;maintaining the ascii
mov bl, [num2] ;num2 to eax
sub bl, 0x30 ;maintaining the ascii
add al, bl ;adding ebx to eax
call display ;display 2 digit number
write msg,len
write quot,2
write rem,2
write new,lenn ;write new line
ret

subtraction:
mov al, [num1] ;num1 to eax
mov bl, [num2] ;num2 to eax
sub al, 0x30 ;maintaining the ascii
sub bl, 0x30 ;maintaining the ascii
sub al, bl ;subtracting eax and ebx
call display
write msg1,len1
write quot,2
write rem,2
write new,lenn ;write new line
ret

multiplication:
mov al, [num1] ;num1 to eax
mov bl, [num2] ;num2 to eax
sub al, 0x30 ;maintaining the ascii
sub bl, 0x30 ;maintaining the ascii
mul bl ;multiplying bl to al
call display ;calling display procedure
write msg2,len2 ;write msg
write quot,1 ;write quot
write rem,1 ;write rem
write new,lenn ;write new line
ret

division:
mov al, [num1] ;num1 to eax
sub al, 0x30 ;maintaining the ascii
mov bl, [num2] ;num2 to eax
sub bl, 0x30 ;maintaining the ascii
div bl ;divding al by bl
add al,0x30 ;maintaining the ascii
add ah,0x30 ;maintaining the ascii
mov [res1],al ;al to res3
mov [res2],ah
write msg3,len3 ;write msg
write new,lenn ;write new line
write msg4,len4 ;write msg
write res1,1 ;write res1
write new,lenn ;write new line
write strn,newlen ;write msg
write res2,1 ;write res2
write new,lenn ;write new line
ret

display: ;Procedure display


mov bl,10 ;10 to bl
div bl ;dividing by bl
;al=quot ah=rem
add al,30h ;maintaining the ascii
mov [quot],al ;al to quot
add ah,30h ;maintaining the ascii
mov [rem],ah ;ah to rem
ret

You might also like