# CS代考程序代写 mips COMP 2421 Computer Organization Homework 1

COMP 2421 Computer Organization Homework 1

Release date: Feb. 22, 2021

Firm Deadline: 11:59 pm, Mar. 1, 2021. Zero mark for late submission

Note: Please remember that you are not permitted to directly exchange ideas about how to solve the problems in this homework. Limited discussions are allowed mainly about the clarity of the questions – you are encouraged to discuss if you feel that some parts of the questions are confusing, and make sure that you understand the questions before proceeding. If you used any conclusions or results not

presented in the lecture, please properly provide references to them.

1. Suppose we use 4 bits to represent a number. For the same bit pattern, e.g. 1001, if we use different number systems, it could have different meanings. For each of the following four cases, finish these two tasks:

1) Suppose the binary numbers are represented in unsigned form, compute the addition (write the result in 4 bits) and determine if there is overflow.

2) Suppose the binary numbers are represented in 2’s complement form, compute the addition (write the result in 4 bits) and determine if there is overflow.

Four cases [2.5 pts for each case]:

A 0011 + 1100 B 0111 + 1111 C 1110 + 1000 D 0110 + 0010

2. Converting the following decimal numbers to 8-bit floating-point number format. Specially, among the 8 bits, the first bit store the sign bit, the next 3 bits store the biased exponent, and the remaining 4 bits store the significand.

Requirements: show your transformation step by step. Specifically, you need to show how you transformed the number to binary form and then the normalized form: ±1.bbbb × 2E . Then, write the biased exponent, and finally the 8-bit representation.

Note: the bias used for the exponent is 2k −1 − 1, where k is the number of bits to represent the biased exponent. Positive number is represented by bit 0

Decimal numbers: (1) 3.625; (2) 0.375 (3) 1.9 (4) −2.75 [2.5 pts for each case]

3. Answering the following two questions. You need to explain your answer

1) [4 pts] Suppose the instruction j addr is located at address 0x04003458, and that addr is located at address 0x04003414. In the address field of the machine code of this instruction, what will the binary bit pattern be? What will the value of PC be after j addr is executed?

2) [6 pts] Fill in the blanks in the MIPS code segment to implement the following “if-else” structure:

if (i != j) h=i+j

else h=i-j

MIPS code (assume i and j are already stored in $t4 and $t5, respectively. Store the result h in $t3. Ignore any overflow.):

beq _, _, lab1 add _, _, _

j_

lab1: sub _, _, _ lab2: …

4. [10pts] Let A be an array, where each element in A is a 32-bit unsigned integer. The array is stored in the memory sequentially (that is, A[0],A[1], A[2], …, are stored in a sequence). The address of A[0] is called the base address of the array. And the address of A[i] is base address added by 4 × i.

Now, read the following MIPS code segment, explain each instruction in the code. Then explain the functionality of this code segment (it is best that you can write a simple “while” structure in C language to explain the functionality).

# $s3 stores value i

# $s4 stores value j

# $s5 stores the value k

# $s6 stores the base address of array A

Loop: sll $t1, $s3,2

add $t1, $t1, $s6

lw $t0, 0($t1)

bne $t0, $s5, Exit

sll $0, $0, 0

add $s3, $s3, $s4

j Loop

Exit:

5. The following problem will investigate how to use MIPS to implement some simple C program statements. Suppose we have three variable a,b,c that are already stored at the register $t0, $t1, $t2. We also have two arrays U and V, where each element in the array is a 32-bit unsigned integer. Assume the base address of the array U and V are stored in registers $t5 and $t6, respectively. (Refer to Problem 4 about the addressing of arrays).

1) [4pts] For this C statement a = b + c + V[3], write MIPS instructions to implement it.

Requirement: use three instructions in this required order “addu, lw, addu” to implement it. Store the result in $t0. Write comment for each instruction of your code. Ignore any overflow.

2

2) [6pts] For this C statement a = b +U[V[3]], write MIPS instructions to implement it.

Requirement: use five instructions in this required order “lw, sll, addu, lw, addu” to implement it. Store the result in $t0. Write comment for each instruction of your code. Ignore any overflow.

3