CS 271 Computer Architecture and Assembly Language Final Exam
CS 271 Computer Architecture and Assembly Language Final Exam
Final Exam
1. (5 pts) What is the correct order of steps in the instruction execution cycle?
_____ Update the instruction pointer to point to the next instruction
_____ Fetch the instruction operand(s) if necessary
_____ Execute the instruction
_____ Fetch the instruction at the instruction pointer into the instruction register
_____ Decode the instruction in the instruction register
_____ Go back to the beginning of the instruction execution cycle
;code fragment R
mov eax,1
2. (3 pts) In code fragment R, suppose that variables y and z are mov ebx,3
declared as DWORD, and z contains a non-negative value. Assuming that mov ecx,z
the value of z is small enough so that no overflow occurs, what is cmp ecx,0
calculated and stored in memory location y? (Your answer should be an je store
top:
algebraic expression, not a literal value.) mul ebx
loop top
store:
___________________ mov y,eax
Use the following declarations and address information for problems # 3 - 4
MAXSIZE = 100
.data
list DWORD MAXSIZE DUP (?)
Recall that DWORD specifies 4 bytes (32 bits). After the "program" is loaded and relocated, the label list is
equivalent to absolute address 1000h. I.E., during program execution, the list array starts at memory address
1000h. All addresses are given in hexadecimal; other values are in decimal.
3. (2 pts) How many bytes of memory are reserved by the declaration of list? ____________
4. _____ After the statement mov edi,OFFSET list is executed, which of the following
correctly assigns the value 42 to the 10th element of the list array?
A. mov list[edi+36],42
B. mov list[9],42
C. mov [edi+36],42
D. all of the above
E. none of the above
;code fragment S
mov edi,OFFSET list
5. (3 pts) After code fragment S is executed, what are the mov eax,MAXSIZE
contents of the first 6 elements of the list array. top:
cmp eax,0
jle quit
mov [edi],eax
dec eax
add edi,TYPE list
jmp top
quit:
;code fragment T
6. (3 pts) After code fragment T is executed, what are the mov edi,0
contents of the first 6 elements of the list array. mov eax,1
mov ecx,MAXSIZE
top:
mov list[edi],eax
add eax,2
add edi,4
loop top
7. (3 pts) After code fragment U is executed, what are the ;code fragment U
mov edi,OFFSET list
contents of the first 6 elements of the list array.
mov ebx,0
mov eax,1
mov ecx,MAXSIZE
top:
mov [edi+ebx],eax
inc eax
add ebx,TYPE list
loop top
8. _____ Pipelining is a form of instruction-level parallelism that is implemented by running multiple
instruction execution cycles so that
A. sequential instructions can be in different stages of the cycle at the same time
B. sequential instructions can be executed simultaneously
C. each instruction can be processed by multiple CPUs to verify accuracy
T
D. an n-stage pipeline can guarantee that a program will run in n time (where T is the time to run the
program without pipelining).
E. none of the above
11. _____ The speed of processor-level parallelism as implemented in software depends on the
I. parallelizability of algorithms
II. features of parallel application programming languages
III. parallel operating system software
IV. efficiency of parallel system libraries
A. I, II, III B. II, III, IV C. I, III, IV D. I, II, III, IV
E. none of A - D is correct
In problems # 12 - 16, A, B, and C are Boolean expressions. Select True if the statement is a Boolean identity,
False otherwise.
12. _____ 1 A A
A. True B. False
13. _____ A B A B
A. True B. False
14. _____ A B A B
A. True B. False
15. _____ A B A B
A. True B. False
A ( B C ) ( A B )( A C )
16. _____
A. True B. False
Use this information to answer questions # 17 - 18.
An algorithm takes 20 seconds to execute on a single 2.4G processor. 40% of the algorithm is sequential.
Assuming zero latency and perfect parallelism in the remaining code …
17. (3 pts) Approximately how long should the algorithm take on a parallel machine made of 8 2.4G
processors?
____________
18. (3 pts) Suppose that we can add (with perfect scalability) any number of 2.4 G processors to the system.
What is the fastest time that can be achieved?
____________
B. D. B and C
Space MACRO x
LOCAL again E. none of these
push ECX
push EAX
mov AL, ’ ’
mov ECX,x
again:
call WriteChar
loop again
pop EAX
pop ECX
ENDM
24. (3 pts) How many bytes of memory will the entire program require if the new code is added as a macro?
____________
25. (3 pts) How many bytes of memory will the entire program require if the new code is added as a
procedure?
____________
Use this information to answer questions # 26 - 31.
Given the following MASM data segment declarations:
.data
list DWORD 50 DUP(?)
matrix DWORD 20 DUP(5 DUP(?))
value DWORD 10597059 ; decimal
string BYTE ”Computer Architecture”,0
The base address of list is 1000H
___________________
28. (2 pts) In a high-level language, the 27th element of list is referenced as list[26]. What is the hexadecimal
address of list[26] ?
___________________
29. (2 pts) In a high-level language, the 4th column of the 6th row of matrix is referenced as matrix[5][3].
What is the hexadecimal address of matrix[5][3] ?
___________________
32. (3 pts) Show the postfix (RPN) form of the infix expression a - (b + c) / (d * e)
_____________________________________________
33. (3 pts) Find the integer value of the postfix (RPN) expression
2 7 + 3 2 - + 5 / 2 *
_____________________________________________
34. (3 pts) Show the infix form of the postfix (RPN) expression a b c d + - e / *
_____________________________________________
Assume that a, b, c, d, e, and z have all been declared as REAL10. Use the IA-32 FPU instructions in this table:
Instruction Meaning
finit Initialize the FPU
fld var Push value of var onto the register stack
fstp var Pop value from register stack into var
fadd Pop two values from register stack, add, and push result onto register stack
fsub Pop two values from register stack, subtract first popped from second popped,
and push result onto register stack
fmul Pop two values from register stack, multiply, and push result onto register stack
35. _____ (3 pts) Which of the following correctly implements the assignment statement:
z = a * (b + c) + (d - e)
A. C.
finit finit
fld a fld a
fmul fld b
fld b fld c
fadd fadd
fld c fmul
fadd fld d
fld d fld e
fsub fsub
fld e fadd
fstp z fstp z
D.
B. finit
finit fld a
fld b fld b
fld c fld c
fadd fadd
fld a fld d
fmul fld e
fld d fsub
fld e fadd
fsub fmul
fadd fstp z
fstp z
E. none of these
36. (5 pts) The code below uses the Space macro defined previously. What output is generated by the MASM
"program"?
main PROC
push 1
push 1
push 5
call rfinal
exit
main ENDP
rfinal PROC
push ebp
mov ebp,esp
mov eax,[ebp+16]
mov ebx,[ebp+12]
mov ecx,[ebp+8]
mul ebx
mov [ebp+16],eax
cmp ebx,ecx
jge unwind
inc ebx
push eax
push ebx
push ecx
call rfinal
unwind:
mov eax,[ebp+16]
call WriteDec
Space 2
pop ebp
ret 12
rfinal ENDP
_____________________________________________