Professional Documents
Culture Documents
Assembly Solutions
Assembly Solutions
Solution:
Solution:
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:
Solution:
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
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:
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