编程辅导 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

Copyright By PowCoder代写 加微信 powcoder

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
A 0011 + 1100, unsigned form: 1111 = 15, no overflow. 2’s complement: 1111 = -1, no overflow B 0111 + 1111, unsigned form: 10110, overflow. 2’s complement: 0110 = 6, no overflow
C 1110 + 1000, unsigned: 1 0110, overflow. 2’s complement: 0110 = 6, overflow
D 0110 + 0010, unsigned: 1000, no overflow. 2’s complement: 1000 = -8, overflow
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]

reference: http://sandbox.mc.edu/ bennet/cs110/flt/dtof.html biasforthecomponent=22 −1=3
students have to show how to get the binary form in the first step.
(1) 3.625: first, to binary 3.625 = 11.101 second, normalize: 11.101 = 1.1101 × 21 third, biased exponent: 1 + 3 = 4 = 100 forth, representation: 0 100 1101
(2) 0.375: first, to binary 0.375 = 0.011 second, normalize: 0.011 = 1.1 × 2−2 third, biased exponent: −2 + 3 = 1 = 001 forth, representation: 0 001 1000
(3) 1.9: first, to binary 1.9 = 1.11100110…
second, normalize: 1.11100110… = 1.11100110 × 20 third, biased exponent: 0 + 3 = 3 = 011
forth, representation: 0 011 1110
(4) −2.75: first, to binary −2.75 = −10.11 second, normalize: −10.11… = −1.011 × 21 third, biased exponent: 1 + 3 = 4 = 100 forth, representation: 1 100 0110
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 _, _, _
lab1: sub _, _, _ lab2: …
1) convert 0x04003414 to binary 0000 0100 0000 0000 0011 0100 0001 0100. delete last two “00”, delete the first four “0000”, get 0100 0000 0000 0011 0100 0001 01
PC = 0x04003458 + 4 = 0x0400345X
2) beq $t4, $t5, lab1
add $t3, $t4, $t5
lab1: sub $t3, $t4, $t5 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
# $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 # multiply i by 4, store to $t1
add $t1, $t1, $s6 # get the address of A[i] in $t1
lw $t0, 0($t1) # get the value A[i] in $t0
bne $t0, $s5, Exit # branch if A[i]!=k
sll $0, $0, 0 # branch delay slot
add $s3, $s3, $s4 # i = i+j
while (A[i] == k)
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) [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.
Hint: you may want to consult the code in Problem 4.
1) a = b + c + V[3]
addu$t0,$t_1,$t_2 #a=b+c
lw $t_7, 12 ($t6) # note $t7 is any temporary register; $t7 = V[3] addu$t0,$t0,$t7 #a=a+V[3]=b+c+V[3]
2) a = b +U[V[3]]
lw $t_7, 12($t6) # note $t7$ could be any temporary register; $t7 = V[3]
sll$t7,$t_7,2 #$t7=$t7*4
addu $t8, $t7, $t_5 #note $t8 could be any temporary register; $t7 now stores the address for U[V[3]]) lw $t9, 0($t8) # note $t9 could be any temporary register; load the value of U[V[3]] to $t9
addu $t0, $t1, $t9 # a = b+ U[V[3]]

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com