Name ________________
SSN_________________
CS271 Spring 2002
Midterm 2 (Practice)
a) Write IJVM ISA code
b) Write UltraSpace ISA code
ILOAD X
BIPUSH 4
IADD
ISTORE C
ADD X, 4, C (X and C in R16 and R17)
c) How many bytes long is your IJVM code? ___7______________
d) How many bytes long is your UltraSparc code? __4_____________
To infix:
a) J3*2+4/ ___(2+3*J)/4__________________________
b) 2222222 _____________________________________
To RPN:
c) (j+16+y)/z ___j16y++z/__________
d) 2222222 _____________________
a) N=OPC; if (N) goto 0x100; else goto 0x00
B=OPC, MEM = 0, C=0, ALU=00110100, JAM=010, ADDR=0
b) 22222222
_____________________________________________
c) 33333333
_____________________________________________
public int factorial (int n) {
if (n <=1) return 1;
return n*factorial(n-1);
}
a) How many calls to factorial occur in executing factorial(4), including the initial call to factorial(4) itself? ____________4_____________________
b) What is the maximum Òstack depthÓ Ð that is, the maximum number of stack frames on the stack at any one time during the execution above? ____4____
Main1: PC=PC+1; fetch; goto (MBR)
ILOAD1: H = LV
ILOAD2: MAR=MBRU+H; rd
ILOAD3: MAR=SP=SP+1
ILOAD4: PC=PC+1; fetch; wr
ILOAD5: TOS=MDR; goto Main1
|
Start |
After Main1 |
After ILoad1 |
After ILoad2 |
After ILoad3 |
After ILoad4 |
After ILoad5 |
MAR |
0x00001000 |
|
|
0x0100 |
0x0102 |
|
|
MDR |
0x00000000 |
|
|
|
10FF7143 |
|
|
PC |
0x00000200 |
0x0201 |
|
|
|
0x0202 |
|
MBR |
0x15 |
|
0x00 |
|
|
|
0x01 |
SP |
0x00000101 |
|
|
|
0x0102 |
|
|
LV |
0x00000100 |
|
|
|
|
|
|
CPP |
0x00000000 |
|
|
|
|
|
|
TOS |
0x05732430 |
|
|
|
|
|
10FF7143 |
OPC |
0x00000003 |
|
|
|
|
|
|
H |
0x00000002 |
|
0x0100 |
|
|
|
|
|
|
|
|
|
|
|
|
MEMORY |
|
|
|
|
|
|
|
0x040B |
0x0A |
|
|
|
|
|
0x43 |
0x040A |
0xBB |
|
|
|
|
|
0x71 |
0x0409 |
0x00 |
|
|
|
|
|
0xFF |
0x0408 |
0x00 |
|
|
|
|
|
0x10 |
0x0407 |
0x30 |
|
|
|
|
|
|
0x0406 |
0x24 |
|
|
|
|
|
|
0x0405 |
0x73 |
|
|
|
|
|
|
0x0404 |
0x05 |
|
|
|
|
|
|
0x0403 |
0x43 |
|
|
|
|
|
|
0x0402 |
0x71 |
|
|
|
|
|
|
0x0401 |
0xFF |
|
|
|
|
|
|
0x0400 |
0x10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0x0203 |
0x00 |
|
|
|
|
|
|
0x0202 |
0x01 |
|
|
|
|
|
|
0x0201 |
0x00 |
|
|
|
|
|
|
0x0200 |
0x15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|