Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 25

Doc No: MAHSA/ENG/FM/09

ASSIGNMENT COVER SHEET Rev No: 0

Date:

Faculty of Engineering
Department of Electrical and Electronics Engineering

Module Code Module Name


MPCL Microprocessor and Microcontroller Lab

Name of the student Kanakri


Student ID
BEEE20046465.
(MAHSA/ARU)
Email mohammadkanakry@gmail.com
Mobile Phone +60 182737922
Batch/Intake 14
Academic Session
Year/Level 3 Semester
Faculty of Engineering
MAHSA University

BEE 3013
Microprocessor and Microcontroller Lab

LAB MANUAL
Session
Year 3
Semester 1

Page 2 of 25
EXPERIMENT 4: STRING MANIPULATIONS USING 8086 MICROPROCESSOR

Experiment 4.1 for 8086 Microprocessor

Objective:To understand how to move block of data from one memory location to another in
assembly language using 8086simulator

Equipment required:PC with 8086 Microprocessor Simulator

Procedure:

1. Run the following assembly code

LABEL MNEMONICS

START: LEA SI, a1

LEA DI, a2

MOV CX, 0008H

REP

MOVSB

HLT

a1 DB 1,2,3,4,5,6,7,8

a2 DB 8 DUP(0)

2. Capture and discuss the result in the lab report

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.

Experiment 4.2 for 8086 Microprocessor

Objective: To write an assembly language to reverse data in a given string in 8086


microprocessor

Equipment required:PC with 8086 Microprocessor Simulator

Procedure:

1. Write the assembly code to solve the arithmetic operations


2. Capture and discuss the result in the lab report

Page 15 of 25
The code:

org 100h

;*****************

; Reversing a string in 8086 ALP

; code.cheraus.com

;******************

;macro for printing a string

print macro m

Page 16 of 25
mov ah,09h

mov dx,offset m

int 21h

endm

.model small

;** Data Segment **

.data

empty db 10,13, " $"

str1 db 25,?,25 dup('$')

str2 db 25,?,25 dup('$')

mstring db 10,13, "plz enter keyword: $"

mstring2 db 10,13, "plz enter second ekyword: $"

mreverse db 10,13, "Reversed keyword: $"

;**** Code Segment ****

.code

start:

mov ax,@data

mov ds,ax

print mstring

call accept_string

mov si,offset str1 ;point si to start of string1

mov di,offset str2 ;point di to start of string2

mov al,[si] ;copy first two locations of string1 to string2

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 cl,str1+1 ; copy length in cl

mov ch,00

add si,cx ;add length of string1 to si to move it to last location

dec si ;si at last location of string1

move_more: mov al,[si] ;copying character one by one from string1 pointed by si

mov [di],al ; to string2 pointed by "di" in reverse order as si moves

dec si ; from last character to first character

inc di

dec cl

jnz move_more

print mreverse

print str2+2 ; printing the reversed string

print empty

exit:

mov ah,4ch ;exit the program

int 21h

;accept procedure

accept proc near

Page 18 of 25
mov ah,01

int 21h

ret

accept endp

display1 proc near

mov al,bl

mov bl,al

and al,0f0h

mov cl,04

rol al,cl

cmp al,09

jbe number

add al,07

number: add al,30h

mov dl,al

mov ah,02

int 21h

mov al,bl

and al,00fh

cmp al,09

jbe number2

add al,07

number2: add al,30h

Page 19 of 25
mov dl,al

mov ah,02

int 21h

ret

display1 endp

accept_string proc near

mov ah,0ah ;accept string from user function

mov dx,offset str1 ; store the string in memory pointed by "DX"

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:

In this Lab is an assembly code to write an assembly language to reverse data in a


given string in 8086 microprocessor. As shown in the figures above the emulation
steps.

- 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

You might also like