Docsity

Problem Set 2 with Solution - Computer Organization | COMP 411, Assignments of Computer Architecture and Organization

Toggle sidebar
bg1
Comp 411 Computer Orginization
Fall 2007
Problem Set #2 Solutions
Problem 1
Instruction Hexadecimal Binary
sll $0, $0, 0 0x00000000 0000 0000 0000 0000 0000 0000 0000 0000
addi $4, $0, 2 0x20040002 0010 0000 0000 0100 0000 0000 0000 0010
add $2, $0, $4 0x00041020 0000 0000 0000 0100 0001 0000 0010 0000
and $3, $2, $4 0x00441824 0000 0000 0100 0100 0001 1000 0010 0100
ori $3, $2, 1 0x34430001 0011 0100 0100 0011 0000 0000 0000 0001
sra $3, $2, 8 0x00021a03 0000 0000 0000 0010 0001 1010 0000 0011
lui $2, 0xfeed 0x3c02feed 0011 1100 0000 0010 1111 1110 1110 1101
ori $2, $2, 0xface 0x3442face 0011 0100 0100 0010 1111 1010 1100 1110
loop: bne $t0,$0,loop 0x15000000 0001 0101 0000 0000 0000 0000 0000 0000
Problem 2
Hexadecimal Instruction
0x2002fff0 addi $2 $0 0xfff0
0x00021822 sub $3 $0 $2
0x8c440010 lw $4 0x10($2)
0x00021100 sll $2 $2 0x0004
0x28850010 slti $5 $4 0x0010
0x3042000f andi $2 $2 0x000f
0x3c03c0de lui $3 0xc0de
Problem 3
a) move rA, rB could be translated to addi rA, rB, 0
Many instructions could do this: or, sub, add, etc.
b) neg rA, rB could be translated to sub rA, r0, rB
This could be done in two cycles with nor and addi 1.
c) not rA, rB could be translated to nor rA, rB
This is could also be done with sub and addi.
d) pow2 rA, rB could be translated to:
addi rA, $0, 1
sllv rA, rA, rB
Raising 2 to an arbitrary power cannot be done in one operation!
1
pf3

Partial preview of the text

Download Problem Set 2 with Solution - Computer Organization | COMP 411 and more Assignments Computer Architecture and Organization in PDF only on Docsity!

Comp 411 Computer Orginization

Fall 2007

Problem Set #2 Solutions

Problem 1

Instruction Hexadecimal Binary sll $0, $0, 0 0x00000000 0000 0000 0000 0000 0000 0000 0000 0000 addi $4, $0, 2 0x20040002 0010 0000 0000 0100 0000 0000 0000 0010 add $2, $0, $4 0x00041020 0000 0000 0000 0100 0001 0000 0010 0000 and $3, $2, $4 0x00441824 0000 0000 0100 0100 0001 1000 0010 0100 ori $3, $2, 1 0x34430001 0011 0100 0100 0011 0000 0000 0000 0001 sra $3, $2, 8 0x00021a03 0000 0000 0000 0010 0001 1010 0000 0011 lui $2, 0xfeed 0x3c02feed 0011 1100 0000 0010 1111 1110 1110 1101 ori $2, $2, 0xface 0x3442face 0011 0100 0100 0010 1111 1010 1100 1110 loop: bne $t0,$0,loop 0x15000000 0001 0101 0000 0000 0000 0000 0000 0000

Problem 2

Hexadecimal Instruction 0x2002fff0 addi $2 $0 0xfff 0x00021822 sub $3 $0 $ 0x8c440010 lw $4 0x10($2) 0x00021100 sll $2 $2 0x 0x28850010 slti $5 $4 0x 0x3042000f andi $2 $2 0x000f 0x3c03c0de lui $3 0xc0de

Problem 3

a) move rA, rB could be translated to addi rA, rB, 0 Many instructions could do this: or, sub, add, etc.

b) neg rA, rB could be translated to sub rA, r0, rB This could be done in two cycles with nor and addi 1.

c) not rA, rB could be translated to nor rA, rB This is could also be done with sub and addi.

d) pow2 rA, rB could be translated to: addi rA, $0, 1 sllv rA, rA, rB Raising 2 to an arbitrary power cannot be done in one operation!

e) dec rA could be translated to addi rA, rA - There are no other easy ways to do this.

f ) sign rA,rB could be translated to sra rA, rB 0x1f Could also be done with slti and sub.

Problem 4

a) Using lw with $0, one can address 2^16 or 2^13 ”locations” in memory depending on weather you restrict accesses to be word aligned or not. In either case, the locations are not contiguous since the immediate value is signed. The unsigned values are at the ’top’ of memory, while the signed values are at the ’bottom’ of memory.

b) The effective address of all references must be aligned properly. For lw and sw this is word alignment.

c) The la $t0, 200($t1) pseudo-instruction can be implemented using addi $t0, $t1, 200.

d) The instruction sequence needed to access an array offset give the array index in $t0 and the offset in $t1 is: sll $t2, $t1, 2 add $t2, $t1, $t lw $t2, 0($t2) Note that before using the offset, it must be multiplied by 4 to access the correct word byte aligned. Only then can it be added to the base and used to access memory.

e) The store instructions are unique in that they use the rt as a source.

Problem 5

a) All register reference locations in instructions would need to be increased in length from 5 to 6 (in order to address 2^6 locations). The available space for other values such as the immedi- ate constants, shamt, or opcode must be reduced, or the instruction size must be increased. Positive benefits would include using the added registers to reduce memory accesses.

b) Similarly to part a), adding a larger range in one section means a loss of range in other sections in the instruction, or an increase in the size of each instruction. Benefits of a larger immediate include access to a wider range of memory for certain instructions.

c) The sw instruction already requires 2 source registers. Adding the capability to use another register as a variable offset would use 3 registers as sources- one for the address, one for the offset, and one for the value. Thus, this instruction would require the hardware modification of adding an extra output line on the register file.

d) Removing the need to specify a destination register frees up 5 bits in the instruction. This would greatly help the modifications in a) and b). It would give the extra bits needed for the a) modification and still have 2 bits left over for the b) modification.