A solution manual to
Assembly language
Programming
and the organization of
the IBM PC
Chapter 8
The Stack and introduction to Procedures
Chapter 9
Multiplication and Division instructions
BY:- Ytha Yu & Charles Marut
prepared by :
Warda Aziz
Wardaaziz555@gmail.com
Chapter 8
The stack and
introduction to
procedures
Question 5:
Suppose SP= 0200h, TOP of stack= 012Ah. What are the contents
of IP , SP
A) after RET is executed, when RET appears in a NEAR
procedure?
B) After RET 4 is executed, where RET appears in a NEAR
procedure?
Answer:
Question 6:
Write some code to
A) place the TOP of the stack into AX, without changing the
stack contents
B) Place the word that is below the stack TOP into CX, without
changing the stack contents.
C) Exchange the TOP two words on the stack. You may use AX,
BX
Question 7:
Procedures are supposed to return the stack to the calling
program in the same condition that they received it. However it
may be useful to have procedures that alter the stack. For
example suppose we would like to write a NEAR procedure
SAVE_REGS that saves BX, CX, DX, SI, DI, BP, DS and ES on
the stack. Now unfortunately , SAVE_REGS can’t return to the
calling program because the return address is not at the TOP of
the stack.
A) devise a way to implement a procedure SAVE_REGS that
gets around this problem(you may use AX to do this)
B) Write a procedure RESTORE_REGS that restores the
registers that SAVE_REGS has saved.
Answer:
Chapter 9
Multiplication and division
instructions
Question 1:
If it is a legal instruction, give the value of DX , AX, and CF/OF
after each of the following instruction is executed.
A) MUL BX, if AX contains 0008h and BX contains 0003h.
B) MUL BX, if AX contains 00FFh and BX contains 1000h.
C) IMUL CX, if AX contains 0005h and CX contains FFFF h.
D) IMUL WORD1, if AX contains 8000h and WORD1 contains
FFFF h.
E) MUL 10h, if AX contains FFE0h.
Solution:
DX AX CF/OF
A 0000 0018 0
B 000F F000 1
C FFFF FFFB 0
D 0000 8000 1
E Illegal statement!!!
Question 2:
Give the new values of AX and CF/OF for each of the following
instructions.
A) MUL BL, if AL contains ABh, and BL contains 10h
B) IMUL BL, if AL contains ABh and BL contains 10h
C) MUL AH, if AX contains 01ABh
D) IMUL BYTE1, if AL contains 02h and byte 1 contains FBh
AX CF/OF
A 0AB0 1
B FAB0 1
C 00AB 0
D FFF6 0
Question 3:
Give the new values of AX and DX for each of the following
instructions. Or tell if overflow occurs.
A)DIV BX, if DX contains 0000h, AX contains 0007h and Bx contains
0002h
B)DIV BX, if DX contains 0000h AX contains FFFEh and BX
contains 0010h
C)IDIV BX , if DX contains FFFFh AX contains FFFCh and BX
contains 0003h
D)DIV BX, if DX contains FFFFh AX contains FFFCh and BX
contains 0003h
AX DX OVERFLOW
A 0003 0001 0
B 0FFF 000E 0
C FFFF FFFF 0
D Divide overflow occur!!!
Question 4:
Give the new values of AL and AH for each of the following
instructions. Or tell if overflow occurs.
A) DIV BL, if AX contains 000Dh, BL contains 03h
B) IDIV BL, if AX contains FFFBh, BL contains FEh
C) DIV BL, if AX contains 00FEh, BL contains 10h
D) DIV BL, if AX contains FFE0h, BL contains 02h
AH AL OF
A 01 04 0
B FF 02 0
C 0B FE 0
D Divide overflow occour!!!
Question 5:
Give the values of DX after executing CWD if AX contains
A) 7E02h
B) 8ABCh
C) 1ABCh
Input Output
7E02 0000
8ABC FFFF
1ABC 0000
Question 6:
Give the values of AX after executing CBW if AL contains
a) F0h
b) 5Fh
c) 80h
Input Output
F0h FFF0
5Fh 005F
80h FF80
Question 7:
Write assembly code for each of the following high level language
assignment statements. Suppose that A,B and C are word variables
and all products will fit in 16 bits. Use IMUL for multiplication. Its
not necessary to preserve the contents of variables A,B and C.
A. A=5*A-7
B. B=(A-B)*(B+10)
C. A=6-9*A
D. IF A2
+ B2
=C2
THEN
Set CF
ELSE
Clear CF
END_IF
Solution:
d

Chap 8 The stack and introduction to procedures & Chapter 9 multiplication and division intrsuctions

  • 1.
    A solution manualto Assembly language Programming and the organization of the IBM PC Chapter 8 The Stack and introduction to Procedures Chapter 9 Multiplication and Division instructions BY:- Ytha Yu & Charles Marut prepared by : Warda Aziz Wardaaziz555@gmail.com
  • 2.
    Chapter 8 The stackand introduction to procedures
  • 7.
    Question 5: Suppose SP=0200h, TOP of stack= 012Ah. What are the contents of IP , SP A) after RET is executed, when RET appears in a NEAR procedure? B) After RET 4 is executed, where RET appears in a NEAR procedure? Answer: Question 6: Write some code to A) place the TOP of the stack into AX, without changing the stack contents B) Place the word that is below the stack TOP into CX, without changing the stack contents. C) Exchange the TOP two words on the stack. You may use AX, BX
  • 8.
    Question 7: Procedures aresupposed to return the stack to the calling program in the same condition that they received it. However it may be useful to have procedures that alter the stack. For example suppose we would like to write a NEAR procedure SAVE_REGS that saves BX, CX, DX, SI, DI, BP, DS and ES on the stack. Now unfortunately , SAVE_REGS can’t return to the calling program because the return address is not at the TOP of the stack. A) devise a way to implement a procedure SAVE_REGS that gets around this problem(you may use AX to do this) B) Write a procedure RESTORE_REGS that restores the registers that SAVE_REGS has saved. Answer:
  • 9.
    Chapter 9 Multiplication anddivision instructions
  • 10.
    Question 1: If itis a legal instruction, give the value of DX , AX, and CF/OF after each of the following instruction is executed. A) MUL BX, if AX contains 0008h and BX contains 0003h. B) MUL BX, if AX contains 00FFh and BX contains 1000h. C) IMUL CX, if AX contains 0005h and CX contains FFFF h. D) IMUL WORD1, if AX contains 8000h and WORD1 contains FFFF h. E) MUL 10h, if AX contains FFE0h. Solution: DX AX CF/OF A 0000 0018 0 B 000F F000 1 C FFFF FFFB 0 D 0000 8000 1 E Illegal statement!!! Question 2: Give the new values of AX and CF/OF for each of the following instructions. A) MUL BL, if AL contains ABh, and BL contains 10h B) IMUL BL, if AL contains ABh and BL contains 10h C) MUL AH, if AX contains 01ABh D) IMUL BYTE1, if AL contains 02h and byte 1 contains FBh AX CF/OF A 0AB0 1 B FAB0 1 C 00AB 0 D FFF6 0 Question 3: Give the new values of AX and DX for each of the following instructions. Or tell if overflow occurs. A)DIV BX, if DX contains 0000h, AX contains 0007h and Bx contains 0002h B)DIV BX, if DX contains 0000h AX contains FFFEh and BX contains 0010h C)IDIV BX , if DX contains FFFFh AX contains FFFCh and BX contains 0003h
  • 11.
    D)DIV BX, ifDX contains FFFFh AX contains FFFCh and BX contains 0003h AX DX OVERFLOW A 0003 0001 0 B 0FFF 000E 0 C FFFF FFFF 0 D Divide overflow occur!!! Question 4: Give the new values of AL and AH for each of the following instructions. Or tell if overflow occurs. A) DIV BL, if AX contains 000Dh, BL contains 03h B) IDIV BL, if AX contains FFFBh, BL contains FEh C) DIV BL, if AX contains 00FEh, BL contains 10h D) DIV BL, if AX contains FFE0h, BL contains 02h AH AL OF A 01 04 0 B FF 02 0 C 0B FE 0 D Divide overflow occour!!! Question 5: Give the values of DX after executing CWD if AX contains A) 7E02h B) 8ABCh C) 1ABCh Input Output 7E02 0000 8ABC FFFF 1ABC 0000 Question 6: Give the values of AX after executing CBW if AL contains a) F0h b) 5Fh c) 80h Input Output F0h FFF0 5Fh 005F 80h FF80 Question 7:
  • 12.
    Write assembly codefor each of the following high level language assignment statements. Suppose that A,B and C are word variables and all products will fit in 16 bits. Use IMUL for multiplication. Its not necessary to preserve the contents of variables A,B and C. A. A=5*A-7 B. B=(A-B)*(B+10) C. A=6-9*A D. IF A2 + B2 =C2 THEN Set CF ELSE Clear CF END_IF Solution:
  • 13.