Professional Documents
Culture Documents
Faculty of Engineering
Faculty of Engineering
Date:
Faculty of Engineering
Department of Electrical and Electronics Engineering
BEE 3013
Microprocessor and Microcontroller Lab
LAB MANUAL
Session
Year 3
Semester 1
Page 2 of 25
EXPERIMENT 4: STRING MANIPULATIONS USING 8086 MICROPROCESSOR
Objective:To understand how to move block of data from one memory location to another in
assembly language using 8086simulator
Procedure:
LABEL MNEMONICS
LEA DI, a2
REP
MOVSB
HLT
a1 DB 1,2,3,4,5,6,7,8
a2 DB 8 DUP(0)
Page 3 of 25
Fig 1
Fig 2
Page 4 of 25
Fig 3
Fig 4
Page 5 of 25
Fig 5
Fig 6
Page 6 of 25
Fig 7
Fig 8
Page 7 of 25
Fig 9
Fig 10
Page 8 of 25
Fig 11
Fig 12
Page 9 of 25
Fig 13
Fig 14
Page 10 of 25
Fig 15
Fig 16
Page 11 of 25
Fig 17
Fig 18
Page 12 of 25
Fig 19
Fig 20
Page 13 of 25
Fig 21
Fig 22
Page 14 of 25
Discussion:
In this Lab is an assembly code to understand how to move block of data from one
memory location to another. As shown in the figures above the emulation steps.
the assembly code and the emulation window indicating the start for the program,
the command (LEA) moves the contents of the designated memory location (a1)
into the target register (SI), the command (LEA) moves the contents of the
designated memory location (a2) into the target register (DI), moving the value of
(0008H) to CX, the H will be (00) & the L will be (08), the command (REP) will
cause repetition of the instructions until CX becomes zero, by using command
(MOVSB) instruction will copy a byte from the location pointed to by the Direct
Index Register. - It will then automatically increment SI to point to the next source
location, the process will be repeated until CX is zero, the value of CX has been
zero and the value now stored in SI is (0014), the H will be (00) & the L will be
(14), and DI (001C), the H will be (00) & the L will be (1C), the command (HLT)
halts the central processing unit (CPU) until the next external interrupt is fired.
Procedure:
Page 15 of 25
The code:
org 100h
;*****************
; code.cheraus.com
;******************
print macro m
Page 16 of 25
mov ah,09h
mov dx,offset m
int 21h
endm
.model small
.data
.code
start:
mov ax,@data
mov ds,ax
print mstring
call accept_string
mov [di],al ;since these contain the size and length of the string
Page 17 of 25
inc si ;which are same in reverse string also
inc di
mov al,[si]
mov [di],al
inc si
inc di
mov ch,00
move_more: mov al,[si] ;copying character one by one from string1 pointed by si
inc di
dec cl
jnz move_more
print mreverse
print empty
exit:
int 21h
;accept procedure
Page 18 of 25
mov ah,01
int 21h
ret
accept endp
mov al,bl
mov bl,al
and al,0f0h
mov cl,04
rol al,cl
cmp al,09
jbe number
add al,07
mov dl,al
mov ah,02
int 21h
mov al,bl
and al,00fh
cmp al,09
jbe number2
add al,07
Page 19 of 25
mov dl,al
mov ah,02
int 21h
ret
display1 endp
int 21h
ret
accept_string endp
end start
end
ret
Page 20 of 25
2
Page 21 of 25
4
Page 22 of 25
5
Page 23 of 25
Discussion:
- Figure 1 is showing the assembly code and the emulation window indicating
the start for the program.
First variables will be the one which will hold the Strings entered by user in the
variables P1 LABEL BYTE M1 DB 0FFH L1 DB? P11 DB 0FFH DUP (‘$’)
to concate characters of two strings given by user and Other variables will be
Page 24 of 25
holding the Messages ‘ENTER ANY STRING: - $’, ‘ENTERED STRING IS: - $’
and ‘CONVERTED STRING IS: $’ to be printed for the User, So in all Four
variables. The identified variables are P11, P22, MSG1, MSG2 and MSG3.
To reverse the decimal numbers in a byte or word, we change the code that prints
the decimal numbers. The reason is that converting from an integer (like the value
1234) to a string (like the characters "1234") usually generates letters in reverse
order and has to do extra work to reverse the characters; So
"print_reversed_decimal ()" will do less work (and inverting the number in another
way and then inverting it again when printed is twice the effort versus nothing!).
Alternatively, you can use BCD instead (as each segment contains a decimal
number). In this case, you can invert the decimal numbers using the "reverse
nibbling" method, and then printing the number becomes much cheaper
(transitions and masks rather than division and pattern).
Page 25 of 25