0% found this document useful (0 votes)
142 views3 pages

CS151B/EE116C - Solutions To Homework #1

This document contains solutions to problems from Homework #1 on MIPS assembly language. Problem 1 provides the logic diagram for a 2-bit register. Problem 2 shows the MIPS instructions to load the base address 0x003ABFEC into a register. Problem 3 demonstrates bit shifting instructions. Problem 4 contrasts loading a number from memory in big endian vs little endian format. Problem 5 decodes the instruction fields for a MIPS instruction. Problem 6 provides the binary encoding for a series of MIPS instructions. Problem 7 gives an efficient solution for an XOR comparison. Problem 8 shows code to load a value from memory conditionally. Problem 9 contrasts loading a byte from memory in big endian vs little endian format.

Uploaded by

tinhtrilac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
142 views3 pages

CS151B/EE116C - Solutions To Homework #1

This document contains solutions to problems from Homework #1 on MIPS assembly language. Problem 1 provides the logic diagram for a 2-bit register. Problem 2 shows the MIPS instructions to load the base address 0x003ABFEC into a register. Problem 3 demonstrates bit shifting instructions. Problem 4 contrasts loading a number from memory in big endian vs little endian format. Problem 5 decodes the instruction fields for a MIPS instruction. Problem 6 provides the binary encoding for a series of MIPS instructions. Problem 7 gives an efficient solution for an XOR comparison. Problem 8 shows code to load a value from memory conditionally. Problem 9 contrasts loading a byte from memory in big endian vs little endian format.

Uploaded by

tinhtrilac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS151B/EE116C Solutions to Homework #1

Problem (1) C.36


Register0

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)

Problem (3) 2.14.1


srl

$9, $8, 5

# shift $8 right by 5, store in $9

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

0000 0001 1110 1100


0000 0001 1111 0000
0000 0001 1111 0100
0000 0001 1111 1000
0000 0001 1111 1100
0000 0010 0000 0000
0000 0010 0000 0100
0000 0010 0000 1000
0000 0010 0000 1100
0000 0010 0001 0000
0000 0010 0001 0100
0000 0010 0001 1000

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

Big Endian: Memory[11] = 1

8
00

9
00

10
00

11
01

Little Endian: Memory[11] = 0

11
00

10
00

09
00

08
01

opcode

addi
sll
add
lw
beq
addi
slt
beq
add
j
sub
j

You might also like