# CPSC 330 Fall 1999 HW #1 Assigned September 1, 1999 Due September 8, 1999 Submit in class Use a word processor (although you may hand-draw answers to Problems.

## Presentation on theme: "CPSC 330 Fall 1999 HW #1 Assigned September 1, 1999 Due September 8, 1999 Submit in class Use a word processor (although you may hand-draw answers to Problems."— Presentation transcript:

CPSC 330 Fall 1999 HW #1 Assigned September 1, 1999 Due September 8, 1999 Submit in class Use a word processor (although you may hand-draw answers to Problems 24 and 25) Chapter 2, Heuring and Jordan, Prob: 2, 3, 4, 5, 6, 9, 14, 23, 24, 25

2.4 Assume that operands and results are stored in memory addresses can be accessed with direct addressing. Also assume that SRC has a multiply instruction, mpy, that uses format 6. ld r0, B ld r1, C add r0, r0, r1 ld r1, D ld r2, E add r1, r1, r2 mpy r0, r0, r1 st r0, A

2.5 Assume each instruction fetch requires one memory access Machine Instructions Opnds/Results Total 3-address 3 9 12 2-address 5 13* 18 1-address 7 7 14 0-address 8 5 13 SRC (gen reg) 8 5 13 *ADD A, C takes 3 data accesses: 2 to fetch A and C and one to store A

2.9 In a stack machine, an arithmetic instruction only needs an opcode field, while a PUSH/POP instruction needs both opcode and a much longer address field. If all instructions were forced to be the same length, a considerable amount of memory space would be wasted in arithmetic instructions.

2.14 a) ld r0, a ; Get value of a la r1, 1 ; Gt constant +1 lar r2, plus ; Set branch target brzr r2, r0 ; Skip next if a=0 neg r1, r1 ; Convert constant to -1 plus: add r0, r0, r1 ; Form a+1 or a-1 st r0, a ; Update a b) la r4, 0 ; Constant 0 la r3, ndigit ; R[3] points to ndigit[i] lar r2, loop ; Branch target addi r1, r4, 0 ; Make R[1], =i, 0 loop: st r4, 0(r3) ; ndigit[i] = 0 addi r3, r3, 4 ; Advance array pointer addi r1, r1, 1 ; i++ addi r0, r1,-10 ; R[0]<0 iff i<10 brmi r2, r0 ; Repeat if i<10

2.23 Register Transfer Control signals ------------------ ------------------- a) W <- R[6]+1 R[6]out, Win Y <- W Wout, Yin Z <- R[4] + Y R[4]out, Zin R[3] <- Z Zout, R[3]in b) Y <- R[5] R[5]out, Yin Z <- R[4] + Y R[4], Zin Y <- Z Zout, Yin Z <- R[3] + Y R[3]out, Zin R[2] <- Z Zout, R[2]in

2.24 On whiteboard 2.25 On whiteboard

Download ppt "CPSC 330 Fall 1999 HW #1 Assigned September 1, 1999 Due September 8, 1999 Submit in class Use a word processor (although you may hand-draw answers to Problems."

Similar presentations