0% found this document useful (0 votes)
39 views7 pages

P1-Arithmetic Operations

This document defines macros for input/output operations and contains code to implement a basic calculator. It displays a menu, accepts user input, performs arithmetic operations on two numbers based on the selection, and displays the result. The operations include addition, subtraction, multiplication, division, and exit. It uses syscalls to read/write and stores operands and results in memory locations.

Uploaded by

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

P1-Arithmetic Operations

This document defines macros for input/output operations and contains code to implement a basic calculator. It displays a menu, accepts user input, performs arithmetic operations on two numbers based on the selection, and displays the result. The operations include addition, subtraction, multiplication, division, and exit. It uses syscalls to read/write and stores operands and results in memory locations.

Uploaded by

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

%macro WRITE 02

mov rax,1

mov rdi,1

mov rsi,%1

mov rdx,%2

syscall

%endmacro

%macro READ 02

mov rax,0

mov rdi,0

mov rsi,%1

mov rdx,%2

syscall

%endmacro

section .data

menu db " ",10

db " 1.Add ",10

db " 2.Sub ",10

db " 3.Mul ",10

db " 4.Div ",10

db " 5.Exit ",10

db " Enter your choice: ",10

menu_len equ $-menu

msg db " Enter 2 numbers ",10


len equ $-msg

msg1 db " Addition is ",10

len1 equ $-msg1

msg2 db " Substraction is ",10

len2 equ $-msg2

msg3 db " Multiplication is ",10

len3 equ $-msg3

msg4 db " Qoutient is ",10

len4 equ $-msg4

msg5 db " Remainder is ",10

len5 equ $-msg5

msg6 db " Invalid choice! ",10

len6 equ $-msg6

section .bss

char_buff resb 17

a resq 1

b resq 1

c resq 1

d resq 1

choice resb 02

section .text

global _start

_start:
print_menu: WRITE menu,menu_len

READ choice,02

cmp byte[choice],31H

je addition

cmp byte[choice],32H

je substraction

cmp byte[choice],33H

je multiplication

cmp byte[choice],34H

je division

cmp byte[choice],35H

je exit

WRITE msg6,len6

jmp print_menu

exit: mov rax,60

mov rdi,0

syscall

addition: WRITE msg,len

READ char_buff,17

call accept

mov qword[a],rbx

READ char_buff,17

call accept

mov qword[b],rbx

mov rax,qword[b]
add rax,qword[a]

mov qword[c],rax

WRITE msg1,len1

mov rbx,[c]

call display

jmp print_menu

substraction: WRITE msg,len

READ char_buff,17

call accept

mov qword[a],rbx

READ char_buff,17

call accept

mov qword[b],rbx

mov rax,qword[a]

sub rax,qword[b]

mov qword[c],rax

WRITE msg2,len2

mov rbx,[c]

call display

jmp print_menu

multiplication: WRITE msg,len

READ char_buff,17

call accept

mov qword[a],rbx

READ char_buff,17
call accept

mov qword[b],rbx

mov rax ,qword[a]

mul qword[b]

mov qword[c],rdx

mov qword[d],rax

WRITE msg3,len3

mov rbx,qword[c]

call display

mov rbx,qword[d]

call display

jmp print_menu

division: WRITE msg,len

READ char_buff,17

call accept

mov qword[a],rbx

READ char_buff,17

call accept

mov qword[b],rbx

mov rdx,00

mov rax,qword[a]

div qword[b]

mov qword[c],rax

mov qword[d],rdx

WRITE msg4,len4

mov rbx,[c]
call display

WRITE msg5,len5

mov rbx,[d]

call display

jmp print_menu

accept: dec rax

mov rcx,rax

mov rsi,char_buff

mov rbx,00

up: shl rbx,04

mov rdx,00

mov dl,byte[rsi]

cmp dl,39H

jbe sub30

sub dl,07H

sub30: sub dl,30H

add rbx,rdx

inc rsi

dec rcx

jnz up

ret

display:mov rsi, char_buff

mov rcx, 16

up1: rol rbx, 04H

mov dl, bl
and dl, 0FH

cmp dl, 09H

jbe add30

add dl,07H

add30: add dl,30H

mov byte[rsi], dl

inc rsi

dec rcx

jnz up1

WRITE char_buff, 16

ret

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy