Helwan University
Faculty of Engineering at Helwan
Microprocessors - 8086
Sheet – 2 (Assembly Language)
1. Write an 8086 assembly program to save the HEX numbers 01H, 02H, 03H, 04H,
and 05H to memory locations 7101H, 7102H, 7103H, 7104H, and 7105H
respectively.
Solution:
MOV AL, 01H
MOV [7101H], AL
MOV AL, 02H
MOV [7102H], AL
MOV AL, 03H
MOV [7103H], AL
MOV AL, 04H
MOV [7104H], AL
MOV AL, 05H
MOV [7105H], AL
HLT
Solution Using Jump: Solution Using Loop:
MOV AL, 05H MOV CX, 0005H
MOV BX, 7105H MOV BX, 7105H
L: MOV [BX], AL L: MOV [BX], CL
DEC BX DEC BX
DEC AL LOOP L
JNZ L HLT
HLT
This study source was downloaded by 100000885594941 from CourseHero.com on 05-09-2024 22:34:29 GMT -05:00
https://www.coursehero.com/file/99536014/Solution-of-Microprocessor-Sheet-2-2pdf/
2. Write an 8086 assembly program to add the value 05H to the contents of each of
the registers BL, CL, DL. Assuming BL=11H, CL=22H, DL=33H.
Solution:
MOV BL, 11H
MOV CL, 22H
MOV DL, 33H
ADD BL, 05H
ADD CL, 05H
ADD DL, 05H
HLT
3. Repeat question 1 for memory locations 0100H, 0101H, and 0102H
a. Using direct addressing.
b. Using indirect addressing.
c. Using relative addressing.
Solution - a:
Using Direct Addressing
MOV AL, 01H
MOV [0100H], AL
INC AL
MOV [0101H], AL
INC AL
MOV [0102H], AL
HLT
Solution - b:
Using Indirect Addressing
MOV BX, 0100H
MOV AL, 01H
MOV [BX], AL
INC BX
INC AL
MOV [BX], AL
INC BX
INC AL
MOV [BX], AL
HLT
This study source was downloaded by 100000885594941 from CourseHero.com on 05-09-2024 22:34:29 GMT -05:00
https://www.coursehero.com/file/99536014/Solution-of-Microprocessor-Sheet-2-2pdf/
Solution - c:
Using Relative Addressing
MOV BX, 0100H
MOV AL, 01H
MOV [BX + 0000H], AL
INC AL
MOV [BX + 0001H], AL
INC AL
MOV [BX + 0002H], AL
HLT
4. Write an 8086 assembly program to add the two numbers 23F9H and 9A35H,
and save the result at memory locations 7100H, 7101H, and 7102H.
Solution:
MOV AX, 23F9H
ADD AX, 9A35H
MOV [7100H], AX
MOV AL, 00H
ADC AL, 00H
MOV [7102H], AL
HLT
5. Write an 8086 assembly program to add the two numbers F3A56BH and
78B6A9H, and save the result at memory locations 7100H, 7101H, 7102H, and
7103H.
Solution:
MOV AX, A56BH F3 A5 6B H +
MOV BX, 00F3H 78 B6 A9 H
ADD AX, B6A9H -------------------
ADC BX, 0078H 1 6C 5C 14 H
MOV [7100H], AX
MOV [7102H], BX [7100H] 14H
HLT [7101H] 5CH
[7102H] 6CH
[7103H] 01H
This study source was downloaded by 100000885594941 from CourseHero.com on 05-09-2024 22:34:29 GMT -05:00
https://www.coursehero.com/file/99536014/Solution-of-Microprocessor-Sheet-2-2pdf/
6. Write an 8086 assembly program to calculate the summation of the contents of
each memory location from 7101H to 7105H, with its corresponding contents in
memory locations 710AH to 710EH, then save the results in memory locations
7110H to 7114H, respectively.
Solution:
Using Jump: Using Loop:
MOV AH, 05H MOV CX, 0005H
MOV BX, 7100H MOV BX, 7100H
L: MOV AL, [BX + 0001H] L: MOV AL, [BX + 0001H]
ADD AL, [BX + 000AH] ADD AL, [BX + 000AH]
MOV [BX + 0010H], AL MOV [BX + 0010H], AL
INC BX INC BX
DEC AH LOOP L
JNZ L HLT
HLT
7. Write an 8086 assembly program to contentiously read content of memory
location 7100H, and check its content:
- if it is zero, put 1 in register BL.
- if it is negative, put 2 in register BL.
- if it is positive, put 4 in register BL.
Solution:
L: MOV AL, [7100H]
CMP AL, 00H
JL NEG
JG POS
MOV BL, 01H
JMP L
NEG: MOV BL, 02H
JMP L
POS: MOV BL, 04H
JMP L
This study source was downloaded by 100000885594941 from CourseHero.com on 05-09-2024 22:34:29 GMT -05:00
https://www.coursehero.com/file/99536014/Solution-of-Microprocessor-Sheet-2-2pdf/
8. Write an 8086 assembly program to perform a cyclic displacement on the
contents of registers AL, BL, and CL.
Solution:
MOV DL, CL
MOV CL, BL
MOV BL, AL
MOV AL, DL
HLT
9. Repeat question 8 with the contents of memory locations FE50H to FE52H
a. Using direct addressing.
b. Using indirect addressing.
c. Using relative addressing.
d. Which addressing mode fits best? Why?
Solution - a:
Using Direct Addressing
MOV AL, [FE52H]
MOV AH, [FE51H] [FE52H] [FE51H]
MOV [FE52H], AH [FE51H] [FE50H]
MOV AH, [FE50H] [FE50H] [FE52H]
MOV [FE51H], AH
MOV [FE50H], AL
HLT
Solution - b, c and d: Left as an exercise
Hint: Use jump or loop instructions to simplify the code
This study source was downloaded by 100000885594941 from CourseHero.com on 05-09-2024 22:34:29 GMT -05:00
https://www.coursehero.com/file/99536014/Solution-of-Microprocessor-Sheet-2-2pdf/
10. Write an 8086 assembly program to multiply the contents of register BL by the
contents of register BH, and save the result in AL. Don’t use the “MUL”
instruction.
Solution:
MOV AL, 00H
L: ADD AL, BH
DEC BL
JNZ L
HLT
11. Write an 8086 assembly program to divide the contents of register BL by the
contents of register BH, save the result in AL, and the remainder in AH.
Don’t use the “DIV” instruction.
(Assume that BL > BH, BH0)
Solution:
MOV AL, 00H
MOV AH, BL
L: SUB AH, BH
INC AL
CMP AH, BH
JGE L
HLT
12. Write an 8086 assembly program to calculate the factorial of an integer in the
accumulator, assuming that the result can reside in one byte register. Send the
result to register BX.
Solution:
MOV CX, AX
MOV AX, 0001H
L: MUL CL
LOOP L
MOV BX, AX
HLT
This study source was downloaded by 100000885594941 from CourseHero.com on 05-09-2024 22:34:29 GMT -05:00
https://www.coursehero.com/file/99536014/Solution-of-Microprocessor-Sheet-2-2pdf/
13. Within the address range 1900H → 191FH. Determine the content of BL, BH,
and DL registers in which:
BL = Number of Positive values.
BH = Number of Negative values.
DL = Number of Zero values.
Solution:
MOV BL, 00H
MOV BH, 00H
MOV DL, 00H
MOV SI, 1900H
L: CMP [SI], 00H
JZ ZERO
JS NEG
INC BL
L1: INC SI
CMP SI, 191FH
JLE L
HLT
ZERO:INC DL
JMP L1
NEG: INC BH
JMP L1
14. Write an 8086 assembly program to always check the content of the input port
35H. If the content is positive, put it in memory location 7200H. While if negative,
put it on output port 03H.
Solution:
L: IN AL, [35H]
CMP AL, 00H
JG POS
JS NEG
JMP L
POS: MOV [7200H], AL
JMP L
NEG: OUT [03H], AL
JMP L
This study source was downloaded by 100000885594941 from CourseHero.com on 05-09-2024 22:34:29 GMT -05:00
https://www.coursehero.com/file/99536014/Solution-of-Microprocessor-Sheet-2-2pdf/
15. Write an 8086 assembly program to always check the content of the input port
03H. If the content is even, put it in memory location A200h, otherwise put the
content on output port 0Ah.
Solution:
L: IN AL, [03H]
MOV BL, AL
AND BL, 01H
JZ EVEN
OUT [0AH], AL
JMP L
EVEN: MOV [A200H], AL
JMP L
16. Write an 8086 assembly program to always check the 4th bit of the content of the
input port A3H. If the 4th bit of the content is one, put the data in memory location
E100h, otherwise put the content on output port 0Ah.
Solution:
L: IN AL, [A3H]
MOV BL, AL
AND BL, 08H
JZ ZERO
MOV [E100H], AL
JMP L
ZERO:OUT [0AH], AL
JMP L
This study source was downloaded by 100000885594941 from CourseHero.com on 05-09-2024 22:34:29 GMT -05:00
https://www.coursehero.com/file/99536014/Solution-of-Microprocessor-Sheet-2-2pdf/
17. Write an 8086 assembly program to calculate the equation 2*AL + 4*BL using the
appropriate shift or rotate instructions then store the result in memory location
BA07h (Assume that the result will reside in one byte).
Solution:
SHL AL, 01h
SHL BL, 02h
ADD AL, BL
MOV [BA07h], AL
This study source was downloaded by 100000885594941 from CourseHero.com on 05-09-2024 22:34:29 GMT -05:00
https://www.coursehero.com/file/99536014/Solution-of-Microprocessor-Sheet-2-2pdf/
Powered by TCPDF (www.tcpdf.org)