global _start
_start:
section .text
%macro disp 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endm

%macro accept 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endm

%macro addn 2
mov rax,%1
add rax,%2
call display
%endm

%macro subbn 2
mov rax,%1
sub rax,%2
call display
%endm

%macro muln 2
mov rax,%1
mov rbx,%2
mul rbx
call display
%endm
%macro divn 2
mov rdx,0
mov rax,%1
mov rbx,%2
div rbx
call display
%endm

menu:
disp msg8,len8
disp msg1,len1
accept choice,02
cmp byte[choice],'+'
je case1

cmp byte[choice],'-'
je case2

cmp byte[choice],'*'
je case3

cmp byte[choice],'/'
je case4

cmp byte[choice],'05'
je case5

case1:
call addition
jmp menu

case2:
call subtraction
jmp menu

case3:
call multiplication
jmp menu

case4:
call division
jmp menu

case5:
call exit

addition:
disp msg8,len8
disp msg2,len2
accept num,17
call convert
mov [num1],rax
call display

disp msg8,len8
disp msg3,len3
accept num,17
call convert
mov [num2],rax
call display

;addition code
disp msg8,len8
disp msg4,len4
addn [num1],[num2]
disp msg8,len8
ret

subtraction:
disp msg8,len8
disp msg2,len2
accept num,17
call convert
mov [num1],rax
call display

disp msg8,len8
disp msg3,len3
accept num,17
call convert
mov [num2],rax
call display

;subtraction
disp msg8,len8
disp msg5,len5
subbn [num1],[num2]
disp msg8,len8
ret

multiplication:
disp msg8,len8
disp msg2,len2
accept num,17
call convert
mov [num1],rax
call display

disp msg8,len8
disp msg3,len3
accept num,17
call convert
mov [num2],rax
call display

;multiplication
disp msg8,len8
disp msg6,len6
muln [num1],[num2]
disp msg8,len8
ret

division:
disp msg8,len8
disp msg2,len2
accept num,17
call convert
mov [num1],rax
call display

disp msg8,len8
disp msg3,len3
accept num,17
call convert
mov [num2],rax
call display

;division
disp msg8,len8
disp msg7,len7
divn [num1],[num2]
disp msg8,len8
ret

exit:
mov rax,60
mov rdi,0
syscall

convert:
mov rdi,temp+07
mov rsi,num
mov rcx,08
bk:
mov al,[rsi]
cmp al,39h
jbe l4 
sub al,07h
l4:
sub al,30h
Rol al,04h
mov bl,al
inc rsi
mov al,[rsi]
cmp al,39h
jbe l5 
sub al,07h
l5:
sub al,30h
add al,bl
mov [rdi],al
dec rdi
inc rsi
loop bk
mov rax,[temp]
ret

display:
mov rsi,disparr+15
mov rcx,16
l12:
mov rdx,0
mov rbx,10h
div rbx
cmp dl,09h
l13:
add dl,30h
mov [rsi],dl
dec rsi
dec rcx
jnz l12

mov rax,1
mov rdi,1
mov rsi,disparr
mov rdx,16
syscall
ret

section .data
msg1: db "**********Menu***********",10
    db "01.Addition(press +)",10
    db "02.subtraction(press -)",10
    db "03.multiplication(press *)",10
    db "04.Division(press /)",10
    db "05.Exit",10
    db " ",10
    db "Enter choice:"
    
len1: equ $-msg1

msg2: db "Enter First Number:"
len2: equ $-msg2

msg3: db "Enter Second Number:"
len3: equ $-msg3

msg4: db "Addition of the numbers is:"
len4: equ $-msg4

msg5: db "subtraction of the numbers is:"
len5: equ $-msg5

msg6: db "multiplication of the numbers is:"
len6: equ $-msg6

msg7: db "Division of the numbers is:"
len7: equ $-msg7

msg8: db "",10
len8: equ $-msg8

temp dq 0

section .bss
num resb 3
num1 resb 20
num2 resb 20
choice resb 10
res resb 4 
disparr resb 8

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: