0% found this document useful (0 votes)
26 views11 pages

MPMC Ex 3

The document describes assembly language programs to perform arithmetic operations on two entered numbers. Program 1 takes in two numbers, calculates their sum, and displays it. Program 2 performs addition, subtraction, multiplication and division of two entered numbers, displaying the results. It also finds the remainder after division. Program 3 is described to take in dimensions of a rectangle, calculate and display its area and perimeter. It will also take dimensions of a triangle and perform similar calculations.

Uploaded by

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

MPMC Ex 3

The document describes assembly language programs to perform arithmetic operations on two entered numbers. Program 1 takes in two numbers, calculates their sum, and displays it. Program 2 performs addition, subtraction, multiplication and division of two entered numbers, displaying the results. It also finds the remainder after division. Program 3 is described to take in dimensions of a rectangle, calculate and display its area and perimeter. It will also take dimensions of a triangle and perform similar calculations.

Uploaded by

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

Experiment No.

3: Arithmetic Instructions Date:24/04/23

PROGRAMS:
EXP 03 [a]. Write an assembly language program to enter two numbers and display their
sum on screen.
CODE:

section .data mov edx, string2len


string1 db 'Enter the number 1: ', 10 int 80h
string1len equ $-string1
string2 db 'Enter the number 2: ', 10 mov eax,3
string2len equ $-string2 mov ebx,2
string3 db 'The sum of number 1 & 2: ', 10 mov ecx,num2
string3len equ $-string3 mov edx,5
int 80h
section .bss
num1 resb 5 mov eax, 4
num2 resb 5 mov ebx, 1
sum resb 5 mov ecx, string3
mov edx, string3len
section .text int 80h
global _start
mov eax, [num1]
_start: sub eax, '0'
mov eax, 4 mov ebx, [num2]
mov ebx, 1 sub ebx, '0'
mov ecx, string1 add eax, ebx
mov edx, string1len add eax, '0'
int 80h mov [sum], eax

mov eax,3 mov eax,4


mov ebx,2 mov ebx,1
mov ecx,num1 mov ecx,sum
mov edx,5 mov edx,5
int 80h int 80h

mov eax, 4 mov eax,1


mov ebx, 1 mov ebx,0
mov ecx, string2 int 80h

OUTPUT:

31|page

Nidhi Shanbhag Roll No:211105036


Experiment No.3: Arithmetic Instructions Date:24/04/23

EXP 03 [b]. Write an assembly language program to perform addition, subtraction,


multiplication and division of two entered numbers.
CODE:
section .data mov ecx, string2
string1 db 'Enter the number 1: ', 10 mov edx, string2len
string1len equ $-string1 int 80h
string2 db 'Enter the number 2: ', 10
string2len equ $-string2 mov eax,3
string3 db 'The sum of number 1 & 2: ', 10 mov ebx,2
string3len equ $-string3 mov ecx,num2
string4 db 'The difference of number 1 and 2: mov edx,5
', 10 int 80h
string4len equ $-string4
string5 db 'The product of number 1 & 2: ', 10 mov eax, 4
string5len equ $-string5 mov ebx, 1
string6 db 'The division of number 1 & 2: ', 10 mov ecx, newline
string6len equ $-string6 mov edx, newlinelen
string7 db 'The remainder is: ', 10 int 80h
string7len equ $-string7
newline db '', 10 mov eax,
newlinelen equ $-newline 4 ;ADDITION
mov ebx, 1
section .bss mov ecx, string3
num1 resb 5 mov edx, string3len
num2 resb 5 int 80h
sum resb 5
diff resb 5 mov eax, [num1]
prod resb 5 sub eax, '0'
quo resb 5 mov ebx, [num2]
rem resb 5 sub ebx, '0'
add eax, ebx
section .text add eax, '0'
global _start mov [sum], eax

_start: mov eax,4


mov eax, 4 mov ebx,1
mov ebx, 1 mov ecx,sum
mov ecx, string1 mov edx,5
mov edx, string1len int 80h
int 80h
mov eax, 4
mov eax,3 mov ebx, 1
mov ebx,2 mov ecx, newline
mov ecx,num1 mov edx, newlinelen
mov edx,5 int 80h
int 80h
mov eax, 4
mov eax, 4 mov ebx, 1
mov ebx, 1 mov ecx, newline 32|page

Nidhi Shanbhag Roll No:211105036


Experiment No.3: Arithmetic Instructions Date:24/04/23

mov edx, newlinelen


int 80h mov eax,4
mov ebx,1
mov eax, mov ecx,prod
4 ;SUBTRACTION mov edx,5
mov ebx, 1 int 80h
mov ecx, string4
mov edx, string4len mov eax, 4
int 80h mov ebx, 1
mov ecx, newline
mov eax, [num1] mov edx, newlinelen
sub eax, '0' int 80h
mov ebx, [num2]
sub ebx, '0' mov eax, 4
sub eax, ebx mov ebx, 1
add eax, '0' mov ecx, newline
mov [diff], eax mov edx, newlinelen
int 80h
mov eax,4
mov ebx,1 mov eax,
mov ecx,diff 4 ;DIVISION
mov edx,5 mov ebx, 1
int 80h mov ecx, string6
mov edx, string6len
mov eax, 4 int 80h
mov ebx, 1
mov ecx, newline mov al, [num1]
mov edx, newlinelen sub al, '0'
int 80h mov bl, [num2]
sub bl, '0'
mov eax, 4 DIV bl
mov ebx, 1 add al, '0'
mov ecx, newline add ah, '0'
mov edx, newlinelen mov [quo], al
int 80h mov [rem], ah

mov eax, mov eax,4


4 ;MULTIPLICATION mov ebx,1
mov ebx, 1 mov ecx,quo
mov ecx, string5 mov edx,5
mov edx, string5len int 80h
int 80h
mov eax, 4
mov al, [num1] mov ebx, 1
sub al, '0' mov ecx, newline
mov bl, [num2] mov edx, newlinelen
sub bl, '0' int 80h
MUL bl
add al, '0'
mov [prod], al

Nidhi Shanbhag Roll No:211105036


Experiment No.3: Arithmetic Instructions Date:24/04/23

mov eax, 4 ;DIVISION int 80h


33|page
mov ebx, 1 mov eax, 4
mov ecx, string7 mov ebx, 1
mov edx, string7len mov ecx, newline
int 80h mov edx, newlinelen
int 80h
mov eax,4
mov ebx,1 mov eax,1
mov ecx,rem mov ebx,0
mov edx,5 int 80h

OUTPUT:

EXP 03 [c]. Write an assembly language program to find area and perimeter of rectangle
and triangle.
CODE:
section .data newlinelen equ $-newline
string1 db 'Enter the length and breadth
of a rectangle: ', 10 section .bss
string1len equ $-string1 len resb 5
string2 db 'The area of rectangle is: ', bread resb 5
string2len equ $-string2 areaR resb 5
string3 db 'The perimeter of rectangle is: ', sumR resb 5
string3len equ $-string3 periR resb 5
string4 db 'Enter the base and height of a base resb 5
triangle: ', 10 height resb 5
string4len equ $-string4 prodT resb 5
string5 db 'The area of triangle is: ', areaT resb 5
string5len equ $-string5 side1 resb 5
string6 db 'Enter the 3 sides of a triangle: ', 10 side2 resb 5
string6len equ $-string6 side3 resb 5
string7 db 'The perimeter of triangle is: ', periT resb 5
string7len equ $-string7
newline db '', 10 section .text 34|Page

Nidhi Shanbhag Roll No:211105036


Experiment No.3: Arithmetic Instructions Date:24/04/23

global _start
mov eax, [len]
_start: sub eax, '0'
mov eax, mov ebx, [bread]
4 ;RECTANGLE sub ebx, '0'
mov ebx, 1 add eax, ebx
mov ecx, string1 add eax, '0'
mov edx, string1len mov [sumR], eax
int 80h
mov eax,3 mov al, '2'
mov ebx,2 sub al, '0'
mov ecx,len mov bl, [sumR]
mov edx,5 sub bl, '0'
int 80h MUL bl
add al, '0'
mov eax,3 mov [periR], al
mov ebx,2
mov ecx,bread mov eax,4
mov edx,5 mov ebx,1
int 80h mov ecx,periR
mov edx,5
mov eax, 4 ;AREA OF int 80h
RECTANGLE
mov ebx, 1 mov eax, 4
mov ecx, string2 mov ebx, 1
mov edx, string2len mov ecx, newline
int 80h mov edx, newlinelen
int 80h
mov al, [len]
sub al, '0' mov eax, 4
mov bl, [bread] mov ebx, 1
sub bl, '0' mov ecx, newline
MUL bl mov edx, newlinelen
add al, '0' int 80h
mov [areaR], al
mov eax, 4
mov eax,4 ;TRIANGLE
mov ebx,1 mov ebx, 1
mov ecx,areaR mov ecx, string4
mov edx,5 mov edx, string4len
int 80h int 80h

mov eax, 4 mov eax,3


mov ebx, 1 mov ebx,2
mov ecx, newline mov ecx,base
mov edx, newlinelen mov edx,5
int 80h int 80h

mov eax, 4 ;PERI OF mov eax,3


RECTANGLE mov ebx,2
mov ebx, 1 mov ecx,height
mov ecx, string3 mov edx,5
mov edx, string3len int 80h
int 80h 35|page

Nidhi Shanbhag Roll No:211105036


Experiment No.3: Arithmetic Instructions Date:24/04/23

mov ecx,side1
mov eax, 4 ;AREA OF mov edx,5
TRIANGLE int 80h
mov ebx, 1
mov ecx, string5 mov eax,3
mov edx, string5len mov ebx,2
int 80h mov ecx,side2
mov edx,5
mov al, [base] int 80h
sub al, '0'
mov bl, [height] mov eax,3
sub bl, '0' mov ebx,2
MUL bl mov ecx,side3
add al, '0' mov edx,5
mov [prodT], al int 80h

mov al, [prodT] mov eax, 4


sub al, '0' ;PERI OF TRIANGLE
mov bl, '2' mov ebx, 1
sub bl, '0' mov ecx, string7
DIV bl mov edx, string7len
add al, '0' int 80h
add ah, '0'
mov [areaT], al mov al, [side1]
sub al, '0'
mov eax, 4 mov bl, [side2]
mov ebx, 1 sub bl, '0'
mov ecx, areaT add al, bl
mov edx, 5
int 80h mov bl, [side3]
sub bl, '0'
mov eax, 4 add al, bl
mov ebx, 1 add al, '0'
mov ecx, newline mov [periT], al
mov edx, newlinelen
int 80h mov eax, 4
mov ebx, 1
mov eax, 4 mov ecx, periT
mov ebx, 1 mov edx, 5
mov ecx, newline int 80h
mov edx, newlinelen
int 80h mov eax, 4
mov ebx, 1
mov eax, 4 mov ecx, newline
mov ebx, 1 mov edx, newlinelen
mov ecx, string6 int 80h
mov edx, string6len
int 80h mov eax,1
mov ebx,0
mov eax,3 int 80h
mov ebx,2

Nidhi Shanbhag Roll No:211105036


Experiment No.3: Arithmetic Instructions Date:24/04/23

36|page
OUTPUT:

EXP 03 [d]. Write an assembly language program that inputs a number and display the next
4 numbers using increment operation.

CODE:
section .bss global _start
number resb 9
sys_in equ 3 _start:
sys_read equ 2 ;input statement
mov eax , 4
section .data mov ebx , 1
nl db "" , 10 mov ecx , num_input
nllen equ $-nl mov edx , nlen
int 80h
num_input db 'Enter The number : '
nlen equ $-num_input ;scanf
mov eax , 3
n1 db 'After 1st increment : ' mov ebx , 2
n1len equ $-n1 mov ecx , number
mov edx , 9
n2 db 'After 2st increment : ' int 80h
n2len equ $-n2
;1st inc
n3 db 'After 3rd increment : ' mov eax , [number]
n3len equ $-n3 inc eax
mov [number] , eax
n4 db 'After 4th increment : '
n4len equ $-n4 mov eax , 4
mov ebx , 1
section .text mov ecx , n1 37|page

Nidhi Shanbhag Roll No:211105036


Experiment No.3: Arithmetic Instructions Date:24/04/23

mov ecx , n3
mov edx , n1len mov edx , n3len
int 80h int 80h

mov eax , 4 mov eax , 4


mov ebx , 1 mov ebx , 1
mov ecx , number mov ecx , number
mov edx , 9 mov edx , 9
int 80h int 80h

mov eax ,4 mov eax ,4


mov ebx , 1 mov ebx , 1
mov ecx , nl mov ecx , nl
mov edx , nllen mov edx , nllen
int 80h int 80h

;2st inc
mov eax , [number] ;4st inc
inc eax mov eax , [number]
mov [number] , eax inc eax
mov [number],eax
mov eax , 4
mov ebx , 1 mov eax , 4
mov ecx , n2 mov ebx , 1
mov edx , n2len mov ecx , n4
int 80h mov edx , n4len
int 80h
mov eax , 4
mov ebx , 1 mov eax , 4
mov ecx , number mov ebx , 1
mov edx , 9 mov ecx , number
int 80h mov edx , 9
int 80h
mov eax ,4
mov ebx , 1 mov eax ,4
mov ecx , nl mov ebx , 1
mov edx , nllen mov ecx , nl
int 80h mov edx , nllen
int 80h

mov eax , 1
;3st inc mov ebx , 0
mov eax , [number] int 80h
inc eax
mov [number],eax

mov eax , 4
mov ebx , 1

38|page

Nidhi Shanbhag Roll No:211105036


Experiment No.3: Arithmetic Instructions Date:24/04/23

OUTPUT:

CONCLUSION:

All the programs were executed successfully.

Nidhi Shanbhag Roll No:211105036


Experiment No.3: Arithmetic Instructions Date:24/04/23

39|page

Nidhi Shanbhag Roll No:211105036


Experiment No.3: Arithmetic Instructions Date:24/04/23

Nidhi Shanbhag Roll No:211105036

You might also like