Microprocessor Systems and Interfacing (CPE342), Instructor Name: M.
Usman Rafique
COMSATS UNIVERSITY ISLAMABAD, Lahore Campus
Department of Electrical and Computer Engineering
Subject: Microprocessor Systems and Interfacing Course Code: CPE342
Assignment No. ONE Total Marks: 40
Submission Date: March 02, 2020
Handed over on: Feb. 24, 2020 (Monday)
(in classroom)
Student’s Name:
Registration Number:
Instructions:
Provide your solution in the space provided against each problem
Back side of each leaf is for rough work only
Submission after the deadline will not be graded
Do not use lead pencil in your solution
Problem 1 10 Marks
Create an 8086-88 assembly language subroutine that computes the total number of zero bits in a 16-bit register of
8088 CPU. Subroutine should put the count of bits in AL.
Solution:
Assume that the BX is the register in which the count of zero bits is to be computed.
XOR AL, AL
MOV DX, 1
MOV CL, 16
START:
TEST BX, DX
JZ COUNT
GO: SHL DX, 1
LOOP START
HLT
COUNT:
INC AL
JMP GO
Page 1 of 4
Microprocessor Systems and Interfacing (CPE342), Instructor Name: M. Usman Rafique
Problem 2 10 Marks
Create an 8086-88 assembly language program that toggles the even-numbered bits of data byte stored at
ABCDH:0055H.
Solution:
MOV AX, 0ABCDH
MOV DS, AX
XOR [0055H], 55H
Problem 3 10 Marks
Create an 8086-88 assembly language program the reverses the order of bits in AL without using ROR and ROL
instructions.
Solution:
MOV AL, 0BEH ;TEST VALUE IN AL
MOV AH, AL
MOV DH, 1
MOV BL, AH
MOV CL, 7
SHR BL, CL
AND BL, DH
MOV DL, BL
MOV CH, DL
MOV SI, 7
AGAIN:
SHL AH, 1
MOV BL, AH
DEC CL
SHR BL, CL
SHL DH, 1
AND BL, DH
MOV DL, BL
OR CH, DL
DEC SI
JNZ AGAIN
MOV AL, CH
HLT
Page 2 of 4
Microprocessor Systems and Interfacing (CPE342), Instructor Name: M. Usman Rafique
Problem 4 10 Marks
Create an 8086-88 assembly language program that copies the contents of a data segment ‘A’ starting from
45DDH to a data segment ‘B’ starting from AF90H, as shown in figure 1 below.
Byte 0H Byte 0H
Byte 1H
Byte FFFEH
Byte FFFFH Byte FFFFH
Segment A Segment B
Figure 1
Solution:
XOR CX, CX
XOR SI, SI
MOV DI, 0FFFFH
COPY:
MOV AX, 45DDH
MOV DS, AX
MOV DH, [SI]
MOV AX, AF90H
MOV DS, AX
MOV [DI], DH
INC SI
DEC DI
LOOP COPY
HLT
Page 3 of 4
Microprocessor Systems and Interfacing (CPE342), Instructor Name: M. Usman Rafique
Explanation:
At the beginning of
It#0: CX = 0, SI = 0, DI = 65535
It#1: CX = 65535, SI = 1, DI = 65534
It#2: CX = 65534, SI = 2, DI = 65533
It#3: CX = 65533, SI = 3, DI = 65532
So the sum of it# (or SI) and CX contents is always 65536 and
sum of the contents of SI and DI is always 65535.
Therefore, the contents of SI and DI at the start of the last
iteration (just before the HLT execution) will be:
Last iteration number = It# = 65536-1 = 65535
Hence the contents of SI are 65535. So the contents of DI must
be 0 as SI+DI = 65535.
Hence it verifies that all the 65536 bytes are copied
according to the given requirement.
Page 4 of 4