Menu Driver Calci
Menu Driver Calci
section .data
num1 dw '9'
num1len equ $ - num1 ;length of our dear string
num2 dw '9'
num2len equ $ - num2 ;length of our dear string
segment .bss
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
write new1,lenn1
write num1,num1len
write new2,lenn2
write num2,num2len
write str1,lenstr1
write str2,lenstr2 ;printing menu
write str3,lenstr3
write str4,lenstr4
write str5,lenstr5
write str6,lenstr6
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
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