Sunday, October 13, 2013

Assign 2 - Exercise 2.13

Jumping ahead a little into something that was meant to be programmed.



In the following problems, the data table contains the values for registers $t0 and
$t1. You w be asked to perform several MIPS logical operations on these registers.
a. $t0 = 0xAAAAAAAA, $t1 = 0x12345678
b. $t0 = 0xF00DD00D, $t1 = 0x11111111

2.13.1 For the lines above, what is the value of $t2 for the following sequence of instructions?
sll $t2, $t0, 44 #left shift by t0 44 store in t2
or $t2, $t2, $t1 #t2 = t2 | t1

pseudo
t2 = (t0 << 44) || t1
a)
= (0xAAAAAAAA << 44) || 0x12345678
b)
= (0xF00DD00D << 44) || 0x11111111

This shift left operation is actually illegal, as we use 32 bit registers, so we can only shift left by 31 as a max.  However, if we adjust this to shift 30, then shift 14, we get:
a)
= (0xAAAAAAAA << 44) || 0x12345678
-0x45412988
b)
= (0xF00DD00D << 44) || 0x11111111
0x75135111
we are shifting left the entire register and then doing an or, which copies t1



2.13.2 For the values in the table above, what is the value of $t2 for the following sequence of instructions?
sll $t2, $t0, 4 #shift left t0 by 4 store in t2
andi $t2, $t2, -1 #t2 += -1

pseudo
t2 = (t0 << 4) -1
a)
= (0xAAAAAAAA << 4) -1
=0xAAAAAAA0
b)
= (0xF00DD00D << 4) -1
=0x00DD00D0
This exercise is playing with bits. Visually we are dropping the left most hex digit and sweeping in a zero, in binary, its a bit different, no pun intended.
a)
0b10101010101010101010101010101010 to
0b10101010101010101010101010100000
b)
0b11110000000011011101000000001101 to
0b00000000110111010000000011010000

2.13.3 For the lines above, what is the value of $t2 for the following sequence of instructions?
srl $t2, $t0, 3 #shift right t0 by 3 store in t2
andi $t2, $t2, 0xFFEF #t2 += 0xFFEF

pseudo
t2 = (t0 >> 3) + 0xFFEF
a)
= (0xAAAAAAAA >> 3) + 0xFFEF
=0x5545
b)
= (0xF00DD00D >> 3) + 0xFFEF
=0xBA01


In the following exercise, the data table contains various MIPS logical operations.
You will be asked to find the result of these operations given values or registers
$t0 and $t1.
a.
sll  $t2, $t0, 1 #t2 = t0*2
andi $t2, $t2, –1 #t2 = t2 & -1
b.
andi $t2, $t1, 0x00F0 #t2 = t1 & 0x00F0
srl  $t2, 2 #illegal

srl $t2, 2 is an illegal instruction as srl takes in 2 registers and an arg. I am assuming this is a typo and am changing it.

b.
andi $t2, $t1, 0x00F0 #t2 = t1 & 0x00F0
srl  $t2, $t2, 2 #t2 = t2 >> 2 # t2/4

pseudo
a. $t2 = $t0 << 1
$t2 = $t2 & -1
$t2 = ($t0 << 1) & -1

b. $t2 = $t1 & 0x00F0
$t2 = $t2 >> 2
$t2 = ($t1 & 0x00F0) >> 2

Any why we need t0 and t1 is beyond me, since they are the same value and we don’t modify it, however, I copied what was in the book anyway.

2.13.4 Assume that $t0 = 0x0000A5A5 and $t1 = 0x00005A5A. What is
the value of $t2 after the two instructions in the table?
a) = (0x0000A5A5 << 1) & -1
=0x00014b4a
b) = (0x0000A5A5 & 0x00F0) >> 2
=(0x00000050) >> 2
=0x00000014

2.13.5 Assume that $t0 = 0xA5A50000 and $t1 = 0xA5A50000.What is
the value of $t2 after the two instructions in the table?
a) = (0xA5A50000 << 1) & -1
=0x4b4a0000
b) = (0xA5A50000 & 0x00F0) >> 2
=(0x0) >> 2
=0

2.13.6 Assume that $t0 = 0xA5A5FFFF and $t1 = 0xA5A5FFFF. What is
the value of $t2 after the two instructions in the table?
a) = (0xA5A5FFFF << 1) & -1
= (0x4b4bfffe)
b) = (0xA5A5FFFF & 0x00F0) >> 2
= (0x000000f0) >> 2
=0x0000003c

In the statements above; for a) -1 is FFFFFFFF so, it will just mime the results of the first operation, where-as b actually required calculation, in most cases.



As stated in the mini intro, these problems were all about logical operations.  I am not sure if they used hex to play visual games with the results, or force students to look at what is happening at the binary level, they are called bitwise operators after all.

As stated at the very beginning, I did up a MIPS program for this exercise.  The only operands I have performed thus far was a shift left and some adds, so it was nice to touch each one of these.

No comments:

Post a Comment