You are on page 1of 1

1.

a) The hex code for given code is


02114020
8de80020
2010fff6

b) Second and third instructions are I-type instructions.

c) When immediate of second instruction is sign extended it becomes


0000 0020, while the third instructions immediate becomes
ffff fff6.

2.) It is assumed that the variables temp, i, n, and result are


declared in advance.

temp = 0;
i = 1;
while(1)
{
int t2 = (n<i) ? 1 : 0;
if (t2 != 0) break;
temp += i;
i += 2;
}
result = temp;

3.) It is assumed that the variables num and count are declared in
advance.

count = 0;
while (num !=0)
{
uint32_t t0 = num & 0x0001;
if (t0 != 0)
count += 1;
num = num>>1;
}

You might also like