C335 Homework #2 solution

$20.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (1 vote)

PART I (4 POINTS)
Do the addition and subtraction manually for the following two binary numbers:
1 0 0 0 1 0 0 1 1 0 0 0 1 0 0 0 1 0 0 1 1 0 0 0
+ 0 0 1 1 0 1 1 0 1 0 1 1 – 0 0 1 1 0 1 1 0 1 0 1 1
——————————— ——————————–
PART II (4 POINTS) (SHOW YOUR STEPS!)
(1) What binary number does this hexadecimal number represent: 0x7ffffffa? What decimal
number does it represent? (assume 32-bit 2’s complement)
(2) What hexadecimal number does the binary number present:
0b11001010111111101111101011001110?
PART III (4 POINTS)
(1) Convert -10310 to binary (8 bits), and then to hexadecimal (assume 2’s complement is
used).
(2) Convert 0xAA to binary then to Decimal (assume 2’s complement is used).
PART IV (TOTAL 12 POINTS, 3 POINTS EACH) (SHOW YOUR STEPS!)
(1) Convert 4096 into a 32-bit two’s complement binary number.
(2) Convert -2047 into a 32-bit two’s complement number.
(3) What decimal number does this two’s complement binary number represent: 0b1111
1111 1111 1111 1111 1111 0000 0110?
(4) What decimal number does this two’s complement binary number represent: 0b1111
1111 1111 1111 1111 1111 1110 1111?
PART V (5 POINTS) (DON’T FORGET TO ADD COMMENTS TO THE CODE!)
Add comments to this following MIPS code and describe in one sentence what it computes.
Assume that $a0 and $a1 are used for the input and both initially contain the integers a and b,
respectively. Assume that $v0 is used for the output:
add $t0, $zero, $zero
loop: beq $a1, $zero, finish
add $t0, $t0, $a0
addi $a1, $a1, -1
j loop
finish: addi $t0, $t0, 100
add $v0, $t0, $zero
PART VI (5 POINTS) (DON’T FORGET TO ADD COMMENTS TO THE CODE!)
The following code segment processes two arrays and products an important value in register
$v0. Assume that each array consists of 2500 words indexed 0 through 2499, that the base
addresses of the arrays are stored in $a0 and $a1, respectively, and their sizes (2500) are stored
in $a2 and $a3, respectively. Add comments to the code and describe in one sentence what this
code does. Specifically, what will be returned in $v0?
sll $a2, $a2, 2
sll $a3, $a3, 2
add $v0, $zero, $zero
add $t0, $zero, $zero
outer: add $t4, $a0, $t0
lw $t4, 0($t4)
add $t1, $zero, $zero
inner: add $t3, $a1, $t1
lw $t3, 0($t3)
bne $t3, $t4, skip
addi $v0, $v0, 1
skip: addi $t1, $t1, 4
bne $t1, $a3, inner
addi $t0, $t0, 4
bne $t0, $a2, outer
PART VII (6 POINTS)
The following program tries to copy words from the address in register $a0 to the address in
register $a1, counting the number of words copied in register $v0. The program stops copying
when it finds a word equal to 0. You do not have to preserve the contents of register $v1, $a0,
and $a1. This terminating word should be copied but not counted.
addi $v0, $zero, 0 # Initialize count
loop:lw $v1, 0($a0) # Read next word from source
sw $v1, 0($a1) # Write to destination
addi $a0, $a0, 4 # Advance pointer to next source
addi $a1, $a1, 4 # Advanced pointer to next destination
beq $v1, $zero, loop # Loop if word copied != zero
There are multiple bugs in this MIPS programs; fix them and turn in a bug-free version.
BONUS QUESTION (1 EXTRA POINT):
Find out how to represent fractions using binary number systems.
(1) Convert binary number 1.1011 to decimal number
(2) Convert decimal number 0.1 to binary number