Solutions

advertisement
EE3803: Microprocessor System Design
Practice Exam 1 with Solutions
1. [15 points] What physical memory addresses are accessed by the following
instructions? The relevant register values are given in the table below.
CS
DS
SS
ES
= 0ED10H BX = 03CFH
= 05B0H BP = 1FF0H
= 1200H SI = 0031H
= 8424H DI = 1100H
MOV
DL,[DI+5AH]
MOV
ES:[SI-4],BH
MOV
AH,[SI+BP]
MOV DL,[DI+5AH]
 DS*10H + DI + 5AH =
05B00H + 1100H + 5AH = 06C5AH
MOV ES:[SI-4],BH
 ES*10H + SI - 4 =
84240H + 0031H - 4 = 8426DH
MOV AH,[SI+BP]
 SS*10H + SI + BP =
012000H + 0031H + 1FF0H = 14021H
2. [20 points] Generate the 8086 machine code for the following assembly instructions.
Explain the functionality of all the bits in the machine code.
MOV
BX,BP
MOV
CL,[BP+SI+754h]
MOV BX,BP
1 0 0 0 1 0 0
opcode
1
d w
1 1 1 0 1 0 1 1
mo
reg
r/m
d
opcode = ‘100010’  move register/memory to/from register
d = ‘0’  direction is from register
w = ‘1’  data width is a word
mod = ‘11’  r/m field specifies a register
reg = ‘101’  BP (source)
r/m = ‘011’  BX (destination)
Hexadecimal:
89 EB
Alternative encoding:
registers
8B DD
by setting d = ‘1’ and swapping
MOV CL,[BP+SI+754h]
1 0 0 0 1 0 1
opcode
0
d w
1 0 0 0 1 0 1 0
mo
reg
r/m
d
54h
disp
lo
opcode = ‘100010’  move register/memory to/from register
d = ‘1’  direction is to register
w = ‘0’  data width is a byte
mod = ‘10’  indirect addressing with 16-bit displacement
reg = ‘001’  CL (destination)
r/m = ‘010’  SS:[BP+SI+disp] (source)
disp = displacement or offset
Hexadecimal:
8A 8A 54 07
07h
disp hi
3. [20 points] Suppose the following code is executed on an 8086 system:
MOV
MOV
BX, offset table
AX, [BX+1]
.data
table
dw
519Ah,529Bh,539Ch
Assume DS = 0FE17h. Describe how the data is transferred from memory to AX over the
8086's 16-bit data bus. Determine the number of bus cycles and the values of A0, BHE
and data (D0-D7 and D8-D15) in each cycle.
The physical address accessed by MOV AX,[bx+1] is FE171h, which is odd,
requiring two bus cycles to read 16 bits of data. The data in the relevant memory
range is stored as follows (“little endian” byte order):
Address
FE173h
FE172h
FE171h
FE170h
Data byte
52h
9Bh
51h
9Ah
Thus AX = 9B51h after the MOV instruction finishes.
The two bus cycles will contain:
Address
A0
BHE
D0-D7
D8-D15
Bus cycle 1
FE171h
1 (low bank inactive)
0 (high bank active)
--51h ( AL)
Bus cycle 2
FE172h
0 (low bank active)
1 (high bank inactive)
9Bh ( AH)
---
In a full implementation, A0 is used to enable the low memory bank (D0-D7) and
BHE enables the high memory bank (D8-D15).
4. [20 points] A listing of an assembly program (including machine code) is attached.
Assume the stack pointer is 0100H at the start of execution of this program.
a) Fill in the contents of the stack at the checkpoints marked in the program comments. If
you do not know the memory contents, leave the cell blank. Identify the top of stack at
each checkpoint by circling the corresponding memory cell. Assume no interrupts are
occurring.
Top of Stack = Green.
(Note that values stay in memory even though they are no longer pointed to)
Stack
Point
Point
Point
Point 4
offset
1
2
3
0102
0101
??
0100
22h
22h
22h
22h
00FF
44h
44h
44h
44h
00FE
03h
03h
03h
03h
00FD
05h
05h
05h
05h
00FC
00h
00h
00h
00FB
21h
21h
21h
00FA
39h
39h
39h
00F9
0c8h
0c8h
0c8h
00F8
03h
03h
03h
00F7
05h
05h
05h
00F6
00F5
b) Fill in the known register values at the checkpoints.
Register
AX
DX
SP
BP
IP
Point 1
??
0305h
00FCh
39C8h
001Eh
Point 2
??
0305h
00F6h
00F8h
0004h
Point 3
036Eh
0305h
00FAh
39C8h
0012h
Point 4
036Eh
2244h
0100h
39C8h
0025h
1
System Design
2
3
4
0000
5
0000
6
0000
7
0000
8
0000
9
0001
10
0003
11
point 2
12
0004
13
0007
14
000A
15
000C
16
000E
17
0010
18
0011
19
point 3
20
0012
21
0013
22
23
0013
24
0016
25
0019
26
001A
27
001D
28
point 1
29
001E
30
0021
31
0024
32
point 4; stop
33
0025
34
; EE3803 D2005 Microprocessor
; Gene Bogdanov, March 2005
; Exam1 problem 5
.model small
.stack 100h
.code
55
8B EC
52
function1
push
mov
push
proc
bp
bp,sp
dx
;
8B
8B
02
02
02
5A
5D
46 04
56 06
C4
C2
C6
mov
mov
add
add
add
pop
pop
ax,[bp+4]
dx,[bp+6]
al,ah
al,dl
al,dh
dx
bp
;
C3
BD 39C8
BA 2244
52
BA 0305
52
ret
function1
start:
mov
mov
push
mov
push
endp
bp,39C8h
dx,2244h
dx
dx,0305h
dx
;
E8 FFDF
83 C4 02
5A
call
add
pop
function1
sp,2
dx
;
here
90
end
nop
start
Download