Micro LR 2
Micro LR 2
Computer Engineering
Oct 12, 2022
1
Air University Islamabad Submitted to: Miss Mariam Sabir
AIR UNIVERSITY
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING
EXPERIMENT NO 2
Lab Title: STRING DEFINITION AND REVERSAL AND BASIC ARITHMATIC OPERATIONS
Student Name: Umar Mustafa Reg. No: 200365
Objective:
LAB ASSESSMENT:
Data presentation
Experimental results
Conclusion
Date: Signature:
2
Home Tasks
1. Write an assembly code that takes string from user and display the
string and the reversed string on screen.
8086 Code
.model small
.stack 100h
.data
msga db 'Enter string: $'
msgb db 'String Entered: $'
msgc db 'Reversed String: $'
arr db 10 dup('$')
rev db 10 dup(?)
.code
.startup
lea dx,msga
mov ah,9h
int 21h
mov ah,10
lea dx,arr
mov arr,6
int 21h
mov dl,0ah
mov ah,2h
int 21h
3
lea dx,msgb
mov ah,9h
int 21h
lea dx,arr+2
mov ah,9h
int 21h
mov dl,0ah
mov ah,2h
int 21h
lea dx,msgc
mov ah,9h
int 21h
lea si,arr+2
mov cl,0
again:
mov dl,ds:[si]
inc si
inc cl
cmp dl,'$'
jne again
dec cl
dec si
4
dec si
lea di,rev
again1:
mov dl,ds:[si]
mov ds:[di],dl
dec si
inc di
dec cl
jnz again1
mov dl,'$'
mov ds:[di],dl
mov arr,6
lea dx,rev+1
mov ah,9
int 21h
.exit
end
Output
5
2. Add four numbers and display the result on screen, your program
should be capable of separating the two digits of sum if sum is greater
than 9, and should display both digits. (HINT: Use division). It is
necessary to add 30h to result before you display it in order to get the
ASCII equivalent of the result.
8086 Code
.model small
.stack 100h
.data
msga db 'Enter four numbers:$'
msgb db 'Result of addition: $'
a db ?
b db ?
.code
.startup
lea dx,msga
mov ah,9h
int 21h
mov ah,2
mov dl,0ah
int 21h
mov cl,0
mov bl,0
loop1:
mov ah,1h
int 21h
sub al,30h
mov dl,al
6
add bl,dl
mov ah,2
mov dl,0ah
int 21h
inc cl
cmp cl,4
jne loop1
lea dx,msgb
mov ah,9h
int 21h
cmp bl,9
jg greater
mov dl,bl
add dl,30h
mov ah,2h
int 21h
.exit
greater:
mov dl,bl
mov ax,dx
mov bl,10
div bl
mov a,al
mov b,ah
mov dl,a
7
add dl,48
mov ah,2h
int 21h
mov dl,b
add dl,48
mov ah,2h
int 21h
.exit
end
Output
8
Conclusion
Reversing a string is the technique that reverses or changes the order of a given
string so that the last character of the string becomes the first character of the
string and so on.
For 16-bit segments, however, the SI and the DI registers are used to point to the
source and destination, respectively.
Arithmetic instructions are those instructions that perform the arithmetic operations
of addition, subtraction, multiplication, and division.
Arithmetic operators expect numeric operands and produce a numeric result. They
are most frequently used in sub-expressions.