CS151B/EE116C - Solutions To Homework #1
CS151B/EE116C - Solutions To Homework #1
Bit1
Bit0
Reg#
CLK
0 M
U
1 X
Bit0
Register1
Bit1
Bit0
Reg#
0 M
U
1 X
CLK
Bit1
Problem (2)
The base address of y 3850220, in hexadecimal, is 0x003ABFEC.
lui
ori
lw
add
sub
sw
$9,
$9,
$10,
$10,
$10,
$10,
0x003A
$9, 0xBFEC
52($9)
$10, $19
$10, $13
32($9)
$9, $8, 5
sll
$9, $9, 15
# shift $9 left by 15
Problem (4)
415 decimal = 0x019F
In a Big Endian machine, memory contains:
24 25 26 27
01 9F 00 00
We then obtain $1 = 0xFFFFFF9F and $2 = 0x00.
In a Little Endian machine, memory contains:
27 26 25 24
01 9F 00 00
We then obtain $1 = 0x00 and $2 = 0xFFFFFF9F
Problem (5)
op
rs
rt
offset
1 0 0 1 0 1 1 0 1 1 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 1
op = 0x25 = 100101
rs = $22 = 10110
rt = $11 = 01011
offset = 47 = 101111
Problem (6)
address
op
rs
rt
rd
shamt
func
001000
000000
000000
100011
000100
001000
000000
000100
000000
000010
000000
000010
00000 01111
0000 0000 0010 0001
00000 00101 00100 00010 000000
01011 00100 00100 00000 100000
00100 00100
0000 0000 0000 0000
00100 01111
0000 0000 0000 0111
00101 00101
0000 0000 0000 0001
00111 00100 00011 00000 101010
00011 00000
0000 0000 0000 0010
01100 00100 01100 00000 100000
00 0000 0000 0000 0000 0111 1100
01100 00111 01100 00000 100010
00 0000 0000 0000 0000 0111 1100
Problem (7)
Many solutions are possible. The most efficient implementation is as follows:
xor
$15,$16,$12
sltiu $15,$15,1
Problem (8)
Assume that the register $1 can be used by the assembler for temporary values.
lui
lw
beq
lui
ori
jr
$1,
$1,
$1,
$1,
$1,
$1
0x34
0x5D2C($1)
$5, 3
0xDABA
$1, 0x9878
$4,
$4,
$4,
$4,
$0, 1
8($0)
11($0)
125($0)
Problem (9)
addi
sw
lb
sb
8
00
9
00
10
00
11
01
11
00
10
00
09
00
08
01
opcode
addi
sll
add
lw
beq
addi
slt
beq
add
j
sub
j