Docsity

Assembly Language Program and Floating Point Representation, Exams of Structural Analysis

Toggle sidebar
bg1
61C Spring 2002, MT2, Clancy
Problem 1 (6 points, 15 minutes)
Consider the following assembly language program segment, which loads $t0 with the larger of $a1 and an integer
labeled by value.
lui $at, upper half of value
lw $t1, lower half of value ($at)
slt $at, $t1, $a1
beq $at, $0, t1greater
add $t0, $0, $a1
j gotmax
t1greater:
add $t0, $0, $t1
gotmax:
...
Part a
The table below lists some of the statements in the program segment. Indicate which of the statements listed below
will be represented by an entry in the relocation table.
Statement
lui $at, upper half of value
lw $t1, lower half of value($at)
beq $at,$0,t1greater
j gotmax
will it contribute an entry to the
relocation table?
(yes or no)
__________________
__________________
__________________
__________________
pf3
pf4
pf5

Partial preview of the text

Download Assembly Language Program and Floating Point Representation and more Exams Structural Analysis in PDF only on Docsity!

61C Spring 2002, MT2, Clancy

Problem 1 (6 points, 15 minutes) Consider the following assembly language program segment, which loads $t0 with the larger of $a1 and an integer labeled by value.

lui $at, upper half of value lw $t1, lower half of value ($at) slt $at, $t1, $a beq $at, $0, t1greater add $t0, $0, $a j gotmax t1greater: add $t0, $0, $t gotmax: ...

Part a The table below lists some of the statements in the program segment. Indicate which of the statements listed below will be represented by an entry in the relocation table.

Statement

lui $at, upper half of value lw $t1, lower half of value($at) beq $at,$0,t1greater j gotmax

will it contribute an entry to the relocation table? (yes or no)





Part b Given below is the part of the text segment of max.o that's the assembled version of the assembly language segment above. Assume that when the code is included in a program that is assembled into a file named max.o, the instruction labeled by t1greater is the 33th instruction in max.o;s text segment and the word labeled by value is the 7th word in max.o's data segment. Fill in the missing hexadecimal digits. Show your work. instruction

lui $at, upper half of value lw $t1, lower half of value($at) slt $at,$t1,$a beq $at,$0,t1greater add $t0,$0,$a j gotmax t1greater: add $t0,$0,$t gotmax: ...

corresponding hexadecimal value 3C01 __________ 8C29 __________ 0125 082A 1020 __________ 0005 4020


0009 4020

Powers of 2 n

  • 0 1 2 3 4 5 6 7 8 9

2 n

1 2 4 8 16 32 64 128 256 512 1024 2048

Problem 3 (5 points, 14 minutes) Complete the framework on the next page to produce an assembly language function named reverse that implements the following (equivalent) Scheme and C functions:

Scheme (define (reverse L soFar) (if (null? L) soFar (reverse (cdr L) (cons (car L) soFar) ) ) )

Equivalent C version struct Thing { ... (as in project 1) } typedef struct thing *ThingPtr; ThingPtr reverse (ThingPtr L, ThingPtr soFar) { if (L == NIL) { return soFar; } else { return reverse (L->th_cddr, cons (L->th_car, soFar)); } }

The code you supply should match he associated comments. Don't worry about memory allocation; the cons function will deal with that.

Problem 4 (2 points, 5 minutes)

Under what conditions will execution of the instruction sw $t0, 3($t0) produce an error? Circle your answer, and briefly explain.

never sometimes always Explanation: