ECE291 Spring 2002 Exam 1

Section Your Score Max
1. Fundamentals   30 points
2. Addressing Memory   40 points
3. Arithmetic and Branches   40 points
4. Stack and Interrupts   40 points
5. Coding Problem   40 points
6. Fun Question   10 points
Total   200 points

Section 1. Fundamentals

1. Write out the contents of memory that result from the following variable declarations, beginning from offset 0 in the code segment.  You may use 'A' to represent the ASCII byte for the character A.  If the contents cannot be determined put an X in the box (15 points)

Var1	dd 'kalimera'
Var2    resw 5
Var3    db 'Cool','$'
Var4    resd 4
Var5    dw 1Ah, 0Ah
CS:00                
CS:08                
CS:10                
CS:18                
CS:20                
CS:28                
CS:30                
CS:38                

2. How many memory operations will it take to read a word from address 291 and a word from address 292 in the 80286? (6 points)

3. Fill the missing entries in the following table, which contains mappings between logical addresses and linear addresses in real mode.  All numbers given in hex (9 points)

1111:FFFF  
1100:8000  
  FFFFE

Section 2. Memory Addressing

1. Using the register values given below (in hex), determine the memory address (or addresses) of the byte (or bytes) read or written in each of the following instructions.  Note that the problems can be solved independently (20 points)

BX=1234 DI=2000 CS=2556
BP=11CA SI=0500 DS=2000
SS=5600 SP=1030  
Instruction Linear Address(es) Read or Written
MOV AX, [DI]  
SUB DX, [BX+SI]  
PUSH SI  
ADD CX, [BP+0A00h]  
POP [DI+1234h]  

2. Write legal or illegal next to each of the following instructions and give justification for the illegal ones (20 points)

  1. MOV WORD[BX+SI], [DI]
  2. MOV BYTE[BL], 5
  3. MOV WORD[CS:SI], 42
  4. ADD AX, BYTE[SI]
  5. ADD DL, [AX+BX]

Section 3. Arithmetic and Branches

1. The ECE291 TA's have a worldwide reputation for their ability to analyze and debug weird codes.  To appreciate their efforts, analyze the following code and try to determine the value of AX at the five question points in the code. (20 points)

LATER	EQU	8
NOW	EQU	4
ORANGES	EQU	9
THREE	EQU	3
...
; macro formerly known as BURGERS_AND_FRIES
%macro	EAT	2
%%SHIP
	MOV	AX, %{1}
	MOV	CX, %{2}
	ROR	AX, CL
	JC	%%SHIP
	INC	CX
%%SHIP
%endmacro
...
; some groceries
APPLES	DW	5
MANGOS	DB	7, 4, 5, 6, 3
PEACHES	DW	9, 3, 2, 1, 8
FRUITCAKE	DW 0BADh
...
; a procedure
HOME
	SUB	WORD[FRUITCAKE], THREE
	CMP	WORD[APPLES], ORANGES
	JAE	.PEAR
	ADD	WORD[APPLES], 2
	CALL	HOME
.PEAR
	MOV	AX, [FRUITCAKE]
	RET
...
EAT_HEALTHY
	EAT	0F00Dh, NOW
	; QUESTION 1: AX =
	EAT	CX, AX
	; QUESTION 2: AX =
	MOV	AX, [PEACHES+3]
	MOV AL, [MANGOS+3]
	; QUESTION 3: AX =
	CALL	HOME
	; QUESTION 4: AX =
	MOV	AX, [APPLES]
	MOV	CX, 8
.FOR_A_WHILE
	ADD	AX, CX
	LOOP	.FOR_A_WHILE
	; QUESTION 5: AX =
	RET

2. Write code to multiply a 8-bit unsigned integer stored in AL by 11.  Using the MUL instruction will cost you 50% of the points (10 points)

3. Suppose the register AX contains a pair of packed binary values.  The low order 4 bits contain a value in the range 0..15 and the high order 12 bits contain a value in the range 0..4095.  Write the code to set the high order 12 bits of AX to the decimal value 291 and the low order 4 bits of AX to the decimal value 10. (10 points)

Section 4. Interrupts and the Stack

1. We asked a lousy programmer to write a procedure that computes the area of a trapezoid.  We would like to call the procedre with a far call from our assembly program.  We pass three parameters to the procedure: b1, b2, and h.  These are unsigned 16-bit numbers and they are passed to the procedure using the convention of C compilers for parameter passing.  To make his life easier, we told him that the area of a trapezoid is computed as (b1+b2)h / 2 and that we don't mind so much about accuracy.  Here's what our programmer came up with.  The next day he was fired.

Find all errors in the following code. (15 points)

Trapezoid:
	PUSH	BP
	PUSH	CX
	MOV	SP, BP
	MOV	AX, [BP+4]
	ADD	AX, [BP+6]
	MUL	WORD[BP+8]
	MOV	CX, 2
	DIV	CX
	POP	BP
	POP	CX
	RET

2. What is the interrupt vector table and where is it stored in memory? (5 points)

3. Select True or False for each of the following statements. (10 points)

4. Explain in a few words the steps taken to install and uninstall a new ISR for a hardware interrupt. (10 points)

Section 5. Coding Problem

Write a procedure which takes in seeral single-digit numbers via kbdin and returns their average.  For full points, make sure to ignore any keypresses that are not digits.  Write this procedure as you would in a machine problem. (40 points)

extern kbdin ; returns ASCII value in al
...

AvgNDigits:
; Reads in CX single-digit numbers and averages them into AX
;
; Inputs: CX = number of digits to average
; Outputs: AX = average of the CX digits
; Calls: kbdin to read each digit

Section 6. Fun Question

Write what the following two sets of instructions do using no more than 10 words (5 in each question).  Each word in excess of 10 will cost you a point. (10 points)

XOR AX, BX
XOR BX, AX
XOR AX, BX
Answer:
CBW
XOR AL, AH
SUB AL, AH
Answer: