Assignment 1-Solution
Assignment 1-Solution
Usman Rafique
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:
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
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.
Page 4 of 4