Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

CSCI-263 Assignment 2

Sebastian Rodriguez ID:201805802

Due date: March 07, 2019 or earlier


You may hand in your assignment early. Please note
all below refer to 4th revised edition:
 
1. Exercise 2.10 (2.10.1-2.10.6) on page 188.
2. Exercise 2.16 (2.16.1-2.16.6) on page 193.
3. Exercise 2.25 (2.25.6-2.25.7) on page 204.
4. Exercise 2.27 (2.27.4-2.27.6) on page 206.
5. Exercise 2.30 (2.30.1-2.30.2) on page 209.
6. Exercise 2.31.1 on page 210

a. OPCODE = 000000 RS = 10000 RT = 10000 RD = 10000 SHMT = 00000 FUNCT = 100000 

 add $s0, $s0, $s0

 b: OPCODE = 000000 RS = 01010 RT = 01011 RD = 01001 SHMT = 00000 FUNCT = 100010 

 sub $t1, $t2, $t3

2.10.2 [5] <2.5> What type (I-type, R-type, J-type) instruction do the binary
entries above represent?

a: This is an R-Type Instruction.


 b: This is an R-Type Instruction. 
CSCI-263 Assignment 2
Sebastian Rodriguez ID:201805802
2.10.3 [5] <2.5> If the binary entries above were data bits, what number would
they represent in hexadecimal? 

 a: 0x02108020

 b: 0x014B4822

a: 0010 0001 0000 1000 0000 0000 0000 0000 0x21080000

 b: 10101101010010010000000000100000 0xAD490020 

2.10.5 [5] <2.5> What type (I-type, R-type, J-type) instruction do the instructions
above represent?

a: This is an I-Type Instruction 

 b: This is an I-Type Instruction 

2.10.6 [5] <2.5> What is the binary then hexadecimal representation of the
opcode, Rs, and Rt fields in this instruction? For R-type instructions, what is the
hexadecimal representation of the Rd and funct fields? For I-type instructions,
what is the hexadecimal representation of the immediate field?

a: OPCODE = 001000 = 0x8


 RS = 01000 = 0x8
 RT = 01000 = 0x8
 Immediate = 0000000000000000 = 0x0000

 b: OPCODE = 101011 =


 RS = 01010 = 0xA
 RT = 01010 = 0x9
 Immediate = 0000000000100000 = 0x0020
CSCI-263 Assignment 2
Sebastian Rodriguez ID:201805802

a. $t2 = 1
b. $t2 = 1

a. none b. none
CSCI-263 Assignment 2
Sebastian Rodriguez ID:201805802

a. Jump – No, Beq - No


b. Jump – No, Beq - No

a. $t2 = 2 b. $t2 = 1

a. $t2 = 0 b. $t2 = 0
CSCI-263 Assignment 2
Sebastian Rodriguez ID:201805802

a. jump – Yes, beq – no b. jump – no, beq – no

lui $t1, 0x2001 # $t1 = 0010 0000 0000 0001 0000 0000 0000 0000
ori $t1, 0x4924 # $t1 = 0010 0000 0000 0001 0100 1001 0010 0100

add $t1, $0, $0 #clear $t1


addi $t2, $0, top_8_bits #set top 8b
sll $t2, $t2, 24 #shift left 24 spots
or $t1, $t1, $t2 #place top 8b into $t1
addi $t2, $0, nxt1_8_bits #set next 8b
sll $t2, $t2, 16 #shift left 16 spots
CSCI-263 Assignment 2
Sebastian Rodriguez ID:201805802
or $t1, $t1, $t2 #place next 8b into $t1
addi $t2, $0, nxt2_8_bits #set next 8b
sll $t2, $t2, 24 #shift left 8 spots
or $t1, $t1, $t2 #place next 8b into $t1
ori $t1, $t1, bot_8_bits #or in bottom 8b

a. 0x12345678
b. 0x00000000

a. t0 = (0x1234 << 16) + 0x5678;


b. t0 = (0x1234 << 16) && 0x5678;

a.0x00400000 beq $s0, $0, FAR 0x12000c3c


...
0x00403100 FAR: addi $s0, $s0, 1 0x22100001

b. 0x00000100 j AWAY 0x09000004


...
0x04000010 AWAY: addi $s0, $s0, 1 0x22100001
CSCI-263 Assignment 2
Sebastian Rodriguez ID:201805802

a. addi $t0, $0, 0x31


sll $t0, $t0, 8
beq $s0, $0, TEMP
...
TEMP: jr $t0

b. addi $s0, $0, 0x4


sll $s0, $s0, 24
ori $s0, $s0, 0x10
jr $s0
...
addi $s0, $s0, 1

a. 2 more Instructions

b. 3 more Instructions
CSCI-263 Assignment 2
Sebastian Rodriguez ID:201805802

a. add $t0, $0, $0

b. add $t0, $0, large


beq $t1, $t0, LOOP

a. No. The branch displacement does not depend on the placement


of the instruction in the text segment.

b. Yes. The address of v is not known until the data segment is


built at link time.
CSCI-263 Assignment 2
Sebastian Rodriguez ID:201805802

a.
Text Size 0x440
Data Size 0x90

Text Address Instruction:

0x00400000 lbu $a0, 8000($gp)


0x00400004 jal 0x0400140
0x00400140 sw $a1, 0x8040($gp)
0x00400144 jal 0x0400000
CSCI-263 Assignment 2
Sebastian Rodriguez ID:201805802

Data 0x10000000 (X)


0x10000040 (Y)

b.
Text Size 0x440
Data Size 0x90

Text Address Instruction:


0x00400000 lui $at, 0x1000
0x00400004 ori $a0, $at, 0
0x00400140 sw $a0, 8040($gp)
0x00400144 jmp 0x04002C0
0x004002C0 jal 0x0400000

Data 0x10000000 (X)


0x10000040 (Y)

You might also like