global _start
_start:
section .text			
%macro disp 2			; macro for system call for write
	mov rax,1
	mov rdi,1
	mov rsi,%1
	mov rdx,%2
	syscall
%endmacro

%macro accept 2			; macro for system call for accept
	mov rax,0
	mov rdi,0
	mov rsi,%1
	mov rdx,%2
	syscall
%endmacro

%macro addn 2           ;macro for addition
    mov rax, %1
    add rax, %2
	call display
%endmacro

%macro subbn 2          ;macro for subtraction
    mov rax,%1
    sub rax,%2
	call display
%endmacro 
%macro muln 2           ;macro for multiplication
    mov rax,[number1]
    mov rbx,[number2]
    mul rbx
    call display
%endmacro  

%macro divn 2           ;macro for division
    mov rdx,0
    mov rax,%1
    mov ebx,%2
    div ebx
    call display
%endmacro

menu:
	disp msg8,len8          ;newline
	disp msg1,len1          ;menu 
	accept choice,02		;to accept choice
 
    cmp byte[choice],'+'
    je case1
    
    cmp byte[choice],'-'
    je case2
    
    cmp byte[choice],'*'
    je case3
    
    cmp byte[choice],'/'
    je case4
    
    cmp word[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 first number         
	accept num,17
	call convert
	mov [number1],rax
    call display            
    
	disp msg8,len8
	disp msg3,len3          ;accept second number
	accept num,17
	call convert
	mov [number2],rax
    call display
    



    ;addition code
    disp msg8,len8
    disp msg4,len4
    addn [number1],[number2]    ;calling macro for addition
    disp msg8,len8              ;newline
    ret

subtraction:
    disp msg8,len8
    disp msg2,len2         ;accepting first number
    accept num,17
	call convert
	mov [number1],rax
    call display
     
	disp msg8,len8
	disp msg3,len3         ;accepting second number
    accept num,17
	call convert
	mov [number2],rax
    call display
    
    ;subtraction
    disp msg8,len8
    disp msg5,len5
    subbn [number1],[number2]           ;calling macro for subtraction
    disp msg8,len8                      ;newline
    ret

multiplication:
    disp msg8,len8
    disp msg2,len2         ;accepting first number
    accept num,17
	call convert
	mov [number1],rax
    call display
     
	disp msg8,len8
	disp msg3,len3         ;accepting second number
    accept num,17
	call convert
	mov [number2],rax
    call display
    
    ;multiplication
    disp msg8,len8
    disp msg6,len6
    muln [number1],[number2]        ;calling macro for multiplication
    disp msg8,len8                  ;newline
    ret 
    


division:
    disp msg8,len8
    disp msg2,len2         ;accepting first number
    accept num,17
	call convert
	mov [number1],rax
    call display
     
	disp msg8,len8
	disp msg3,len3         ;accepting second number
    accept num,17
	call convert
	mov [number2],rax
    call display
    
    ;division
    disp msg8,len8
    disp msg7,len7
    divn [number1],[number2]    ;calling macro for division
    disp msg8,len8             ;newline
    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,16h

    l12:mov rdx,0
	    mov rbx,10h
        div rbx
	    cmp dl,09h
	    jle l3
	    add dl,07h
		l3: 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
no1 resb 20
no2 resb 20
number1 resb 20
number2 resb 20
choice resb 3
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: