2) (4 points)
a) 210 -
103
/ 103 = 2.4%
b) 240 -
1012
/ 1012 = 9.95%
3) 20,000 seconds (6 points)
1 side = 10-1 meters
Resolution = 1 dot every 10-4 meters
So total # of points in the box = ( 10-1 /
10-4
)3 = 109 points
109 points * 102 instructions/point =
1011
instructions
(1011 instructions) / (5*106 instructions/sec)
= 20,000 seconds
4) A = (B + C) * (D + E) (10 points)
ld r1,B (1)
ld r2,C (1)
add r1,r1,r2 (0)
ld r2,D (1)
ld r3,E (1)
add r2,r2,r3 (0)
mpy r1,r1,r2 (0)
st r1,A (1)
5 total memory references
5) (6 points)
| DEC R2 | SHL AX, 4 | |
| Operation to be performed | Explicit: DEC | Explicit: SHL |
| Location of first operand | Explicit: R2 | Explicit: AX |
| Location of second operand | Implicit: minus 1 | Explicit: 4 |
| Place to store result | Explicit: R2 | Explicit: AX |
| Location of next instruction | Implicit: program counter | Implicit: program counter |
.org
2000
;next word loaded at address 200010
a: .dw
1
;reserve 1 word for var a
.org
3000
;program loaded at address 300010
ld
r0,a
;R[r0] = M[a]
lar
r1,zero
;load address of jump loc
brzr
r1,r0
;branch to jump loc in r1 if R[r0] = 0
addi r0, r0,
-1
;decr R[r0]
lar
r1,next
;load addr of next loc
br
r1
;jump to next
zero: addi r0,r0,1 ;incr R[r0]
next:st
r0,a
;store R[r0] in mem loc a
6 b) for ( i=0; i < 10 ; i++) ndigit[i]=0; (10 points)
.org
1000
;next word at address 100010
i: .dw
1
;reserve 1 word for variable i
ndigit: .dw
10
;reserve 10 words for array ndigit
.org
5000
;program loaded at address 500010
la r0,
0
;R[r0] = 0
st r0,
i
;M[i] = 0
la r1,
10
;R[r1] = 10
lar r5,
loop
;load addr of jump loc
lar r6,
over
;load addr of jump loc
ld r2,
i
;R[r2] = M[i] to hold displacement for array
loop: ld r3,
i
;R[r3] = M[i]
sub r4, r3,
r1
;R[r4] = i - 10
brzr r6,
r4
;jump to loc in r6 if R[r4] = 0
st r0, ndigit(r2)
;ndigit[i]=
0
addi r2, r2,
4
;Next word
addi r0, r0,
1
;Incr i
st r0,
i
;M[i] = R[r0]
br
r5
; Next iteration
over:
7)Call procedure (20 points)
For this problem, you should go about it in 3 steps. First, think about a procedure call in C or some generic programming language...
main {
arbitrary code
Output = proc_call(A,B)
}
proc_call(int A, int B){
body of proc
return Output
}
Second, construct a list of everything that must be done involving the architecture so that the procedure call will work.
- location of where to branch to for procedure (proc. should be
"labelled")
- get initial PC
- know where in memory initial PC and other necessary data for
program
are located
- save PC of instruction following procedure call in main and
restore
it
- save any registers used in procedure that were used in main and
then
restore those values once you leave procedure call
At the beginning of main, you should get the initial PC and initialize your memory (location of where data is loaded from/stored to) with pseudo-ops. The procedure parameters should be loaded here, too, since they are going to be passed from main to th e procedure. The code from problem 6 and the appendix give examples of this. You should also decide before the call which register will eventually hold the output of the procedure.
In the procedure call, you must save the PC of the instruction following the procedure and load into the PC the location of the procedure call. Then in the prolog (or the call, but it seems more efficient in the prolog), you must save any registers th at are going to be used in the procedure. This way, if they are used in main, the data will not be overwritten. This includes the two parameters. In C, the parameters may change in a procedure, but the changed values are not returned to main, only the output would be.
Finally, in the epilog of the procedure you must do two things. One, is restore all the registers to their original values except for the register designated for the output (since it is returned to main). The other thing is restore the PC to the loca tion of the instruction after the procedure call.
Third and finally, construct this in SRC. Here is one possibility...
.org
1000
// Next word loaded from address 1000
X: .dw
3
// Reserve 2 words for variable X (two parameters)
.org
5000
// Initial PC - 5000
// input params in r3, r4, output param will
be r5, Procedure call PC
// will be in r1; location of PC after proc.
call will be put in r31
la r7, 4
ld r3,
X
// get 2 params.
ld r4, X(r7)
lar r1, Proc_call // load Proc_call
address
relative to PC into r1
....arbitrary code ...
brl r31,
r1
// PC of next instruction to r31, PC <- r1
instruction after proc call....
proc_call: sto r3, X
sto r4, X(r7)
...store any other registers that will be
used
in the procedure
(I could store r7, but I will not need it
here)
...arbitrary code, output param, r5, gets a value ....
ld r3, X
ld r4,
X(r7)
// restore params and any other registers
// used in proc. to the values they had in main
br
r31
// branch to next instruction in main after proc.
// call