MPMC Ex 3
MPMC Ex 3
PROGRAMS:
EXP 03 [a]. Write an assembly language program to enter two numbers and display their
sum on screen.
CODE:
OUTPUT:
31|page
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
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 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
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
mov ecx , n3
mov edx , n1len mov edx , n3len
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
OUTPUT:
CONCLUSION:
39|page