Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

1.

Write a program to calculate the numbers from 0 to 100

Solution:

MOV AX, 0000D


MOV CX, 100D
AGAIN: ADD AX, CX
DEC CX
JNZ AGAIN

2. Write a program to calculate the even numbers from 0 to 100

Solution:

MOV AX, 0000D


MOV CX, 100D
AGAIN: ADD AX, CX
SUB CX, 02D
JNZ AGAIN

3. Write an instruction sequence to save the current contents of the 8088’s flags in the memory
location at offset MEM1 of the current data segment and then reload the flags with the
contents of the storage location at offset MEM2.
Solution:

LAHF ; Load AH from flags


MOV [MEM1], AH ; Move content of AH to MEM1
MOV AH, [MEM2] ; Load AH from MEM2
SAHF ; Store content of AH into flags

4. Write a program to calculate the factorial of 05h.

Solution:

MOV BL, 05h


MOV AL, 01h
AGAIN: MUL BL
DEC BL
JNZ AGAIN
5. Describe what happens to the status flags as the sequence of instructions that follows is
executed.
MOV AX, 1234H

MOV BX, 0ABCDH

CMP AX, BX

Solution:
(AX) = 123416 = 00010010001101002 (BX) = ABCD16 = 10101011110011012
(AX) – (BX) = 00010010001101002 - 10101011110011012
= 01100110011001112
Therefore, ZF = 0, SF = 0, OF = 0, PF = 0, CF = 1, AF = 1

6. Implement an instruction sequence that calculates the absolute difference between the
contents of AX and BX and places it in DX.
Solution:
CMP AX, BX JC DIFF2
DIFF1: MOV DX, AX
SUB DX, BX ; (DX)=(AX)-(BX) JMP DONE
DIFF2: MOV DX, BX
SUB DX, AX ; (DX)=(BX)-(AX) DONE: NOP

7. Write an instruction sequence to save the current contents of the 8088’s flags in the memory
location at offset MEM1 of the current data segment and then reload the flags with the
contents of the storage location at offset MEM2.
Solution:
LAHF ; Load AH from flags
MOV [MEM1], AH ; Move content of AH to MEM1
MOV AH, [MEM2] ; Load AH from MEM2
SAHF ; Store content of AH into flags

8. What is the result of executing the following instruction sequence?


ADD AL, BL

AAA

Assuming that AL contains 3316 (ASCII code for 3) and BL contains 3516 (ASCII code 5), and that AH has
been cleared.
Solution:
(AL)(AL)+(BL)= 3216 + 3416=6616
The result after the AAA instruction is (AL) = 0616
(AH) = 0016
with both AF and CF remain cleared

9. The 2’s-complement signed data contents of AL are –1 and that of CL are –2. What result is
produced in AX by executing the following instruction?
MUL CL IMUL CL

Solution:

(AL) = -1 (as 2’s complement) = 111111112 = FF16


(CL) = -2 (as 2’s complement) = 111111102 = FE16 Executing the MUL instruction gives
(AX) = 111111112x111111102=11111101000000102=FD0216
Executing the IMUL instruction gives (AX) = -116 x -216 = 216 = 000216

10. Describe the results of executing the following instructions?


MOV AL, 01010101B
AND AL, 00011111B
OR AL, 11000000B
XOR AL, 00001111B
NOT AL
Solution:
(AL)=010101012 000111112= 000101012=1516
Executing the OR instruction, we get
(AL)= 000101012 +110000002= 110101012=D516
Executing the XOR instruction, we get
(AL)= 110101012 000011112= 110110102=DA16
Executing the NOT instruction, we get
(AL)= (NOT)110110102 = 001001012=2516

11. Assume that CL contains 0216 and AX contains 091A16. Determine the new contents of AX and
the carry flag after the instruction SAR AX, CL is executed.
Solution:
(AX)=00000010010001102=024616, and the carry flag is (CF) =12

You might also like