Download ECE 267 Final Exam Solutions - UIC Computer Organization & Programming - Prof. Vladimir Go and more Exams Computer Architecture and Organization in PDF only on Docsity!
2002 University of Illinois at Chicago ECE 267 V. Goncharoff.
ECE
UIUICC
De Deppaarrttmmeenntt ooff ElEleeccttrriiccaall aanndd CCoommppuutteerr EnEnggiinneeeerriinngg
ECE 267 − Computer Organization and Programming
Final Examination Solutions (43 pts. total)
20 problems, not all equally weighted.
Assume Intel IA-32 assembly language, MASM 6.15 assembler throughout.
IMPORTANT: Please be aware that academic dishonesty will result in grade “E” for the course, and possibly dismissal from the University. Looking at another exam paper, showing someone your exam paper, or otherwise communicating exam problem information to/from another student is considered to be academically dishonest. Should you have any questions about this policy or about any of the exam questions, please ask me for clarification. -Vladimir Goncharoff
1. Express (631) 10 in radix 2, radix 8 and radix 16:
a) (631) 10 = ( 1001110111 ) 2
b) (631) 10 = ( 1167 ) 8
c) (631) 10 = ( 277 ) 16
2. Write (32) 10 in the shortest-possible unsigned integer binary code:
(32) 10 = ( 100000 ) unsigned binary
3. Write (−32) 10 in the shortest-possible signed integer binary code:
(−32) 10 = ( 100000 ) signed binary
4. What is the highest integer value N that may be exactly represented in REAL
format such that all integers in the range [0, N −1] may also be exactly represented?
N = [(1.1^23 ) 2 × 223 ] + 1 = 2^24 = (16,777,216) 10
5. Given: EAX contains value X in REAL4 format. Write assembly language
instructions that overwrite EAX with the value 4 X in REAL4 format. (Assume
that overflow does not occur.) Do not use any FPU instructions.
and eax, 7FFFFFFFh
ror eax, add al,2 or: add eax, 01000000h rol eax,
(1 pt.)
(1 pt.)
(1 pt.)
(1 pt.)
(1 pt.)
(2 pts.)
(2 pts.)
9. Rewrite the following code without using the .IF directive. Assume unsigned
binary code in EAX. Keep the code as short as possible.
.IF (eax >= 500) add eax,ebx .ELSEIF (eax <= 25) sub eax,ebx .ELSE mov eax,ebx .ENDIF
10. Using the .IF directive, write code that calls procedure "WriteChar" if register AL
contents are in the range '0' to '9'; otherwise call procedure "Crlf."
(3 pts.)
cmp eax, jae AE_ cmp eax, jbe BE_ mov eax,ebx jmp Next
AE_500: add eax,ebx jmp Next
BE_25: sub eax,ebx
Next:
.IF (al >= '0') && (al <= '9') call Writechar .ELSE call Crlf .ENDIF
(2 pts.)
11. Rewrite the following code without using the LOCAL directive:
Compute PROC LOCAL X[200]:SDWORD mov X[0],- mov X[4], call Some_other_procedure ret Compute ENDP
12. Write one assembly language instruction that replaces EAX bits b 31 b 30 b 29 with
13. Write one assembly language instruction that replaces EAX bits b 31 b 30 b 29 with
(3 pts.)
Compute PROC
push ebp mov ebp,esp sub esp, mov SDWORD PTR [ebp-800],- mov SDWORD PTR [ebp-800+4], call Some_other_procedure mov esp,ebp pop ebp ret
Compute ENDP
or eax, 0E0000000h
and eax, 1FFFFFFFh
(2 pts.)
(2 pts.)
16. Write a macro named "mSquare_Root_EAX" that causes the floating point value
in register EAX to be replaced with its square root. Use the FPU instruction fsqrt.
This macro has no parameters.
17. Write a procedure named "Reverse_EAX" that reverses the order of bits in register
EAX. For example, EAX = FF1100AAh becomes EAX = 550088FFh. Restore
the contents of any other registers used inside the procedure. Keep the code as
short as possible.
(3 pts.)
(2 pts.)
mSquare_Root_EAX MACRO LOCAL ftemp .data ftemp REAL4? .code finit mov ftemp,eax fld ftemp fsqrt fstp ftemp mov eax,ftemp ENDM
Reverse_EAX PROC USES ebx ecx
mov ecx, A1: shr eax, rcl ebx, loop A
mov eax,ebx ret
Reverse_EAX ENDP
18. Write a procedure named "Cube_Root_EAX" that causes the floating point value
in register EAX to be replaced with its cube root. Use 20 iterations of the
Newton-Raphson recursion in the FPU. Restore the contents of any other registers
used inside the procedure.
(3 pts.)
Cube_Root_EAX PROC USES ecx
.data X REAL4? Y REAL4? ftwo REAL4 2. fthree REAL4 3. .code
finit mov X,eax mov Y,eax mov ecx,
A1: fld X fld Y fld Y fmul fdiv fld Y fld ftwo fmul fadd fld fthree fdiv fstp Y loop A
mov eax,X ret
Cube_Root_EAX ENDP
20. Write a macro named "mProduct" that is invoked as follows:
mProduct reg1, reg2, reg
Each of the parameters is a 32-bit register name; as a result the contents of reg
are replaced by reg2 × reg3. Assume that overflow does not occur. Only the
contents of reg1 should change as a result of invoking this macro.
mProduct MACRO reg1,reg2,reg
LOCAL temp .data temp DWORD? .code
push eax push edx mov temp,reg mov eax,reg mul temp mov temp,eax pop edx pop eax mov reg1,temp
ENDM
(2 pts.)