Some of the exercises include material of general interest that goes beyond the requirements of this subject. These are indicated by an asterisk.
rol x, y, 5ror x, y, 27(1)000001 for 54 + 11 = 65, overflow in 6 bits;
(0)101000 for 13 + 27 = 40, no overflow in 6 bits;
(0)100000 for 1 + 127 = 128, no overflow in 8 bits;
1111101 for (-14) + 11 = (-3), no overflow in 6 bits;
101010 for 13 + 27 = 40, overflow in 6 bits (incorrect
sign);
00000000 for 1 + (-1) = 0, no overflow in 8 bits;
0x47f0d for 241672 + 52997 = 294669, no overflow in 20
bits;
0xf4f533 for (-7028207) + 6304546 = (-723661), no overflow
in 24 bits;
0xfd058 for 52446 + (-64646) = (-12200), no overflow in 20
bits;
100001
x 100
------
0
0
100001
--------
10000100
which equals 132. Check: 33*4 = 132.
11 1111 1111
x 1100
------------
0
0
11 1111 11
11 1111 1
------------
11 1111 0100
which equals -12. Check: (-1)*12 = -12.
0000 0001 0110
x 1111 1111 1011
--------------
1 0110
10 110
0
1011 0
1 0110
10 110
101 10
1011 0
0110
110
10
0
--------------
1111 1001 0010
which equals -110. Check: 22*(-5) = -110.
1111 1110 1110
x 1111 1111 0000
--------------
| val1 | val2 | NOT val1 | val1 AND val2 | val1 OR val2 |
|---|---|---|---|---|
| 0000 0000 | 1111 1111 | 1111 1111 | 0000 0000 | 1111 1111 |
| 0000 0000 | 0000 0000 | 1111 1111 | 0000 0000 | 1111 1111 |
| 1111 0000 | 0101 0101 | 0000 1111 | 0101 0000 | 1111 0101 |
1010 1101 for 115 + 58 = 173, overflow in 8 bits;
0011 1000 for (-36) + 92 = 56, no overflow in 8 bits;
1101 1110 for (-47) + 13 = (-34), no overflow in 8 bits;
0100 0001 for (-73) - 118 = (-191), overflow in 8 bits;
1100 0111 for 30 - 87 = (-57), no overflow in 8 bits;
111 1101 for 81 - 20 = 61, no overflow in 8 bits;
111
x 110
--------------
0
111
1 11
--------------
010 1010
which equals 42. Check: 7*6 = 42.
0000 0001 1110
x 1111 1111 0111
--------------
1 1110
11 110
111 10
0
1 1110
11 110
111 10
1111 0
1110
110
10
--------------
1110 1111 0010
which equals -270. Check: 30*(-9) = (-270).
01 1011
x 01 0100
--------------
110 11
1 1011
--------------
0010 0001 1100
which equals 540. Check: 27*20 = 540.
1111 1111 1111
x 1111 1110 1111
--------------
1111 1111 1111
1111 1111 111
1111 1111 11
1111 1111 1
0
1111 111
1111 11
1111 1
1111
111
11
1
--------------
0000 0001 0001
which equals 17. Check: (-1)*(-17) = 17.
5 101
-- -----
4|23 100|10111
20 100
-- ---
3 111
100
---
11
30 11110
--- --------
8|240 1000|11110000
24 1000
-- ----
00 1110
1000
----
1100
1000
----
1000
1000
----
00
sll were not available, we could use rol and clear
those bits that are rotated from the left end of the data item and reinserted
on the right. Thus, the instruction
sll x, y, 5
could be replaced by the instructions
rol x, y, 5
and x, x, 0xffffffe0
sra is to be replaced by rol, the amount moved has to
subtracted from 32 and the correct sign bits have to be inserted. Thus, the
instruction
sra x, y, 5
could be replaced by the instructions
rol x, y, 27
bltz y, a10
and x, x, 0x07ffffff
b a20
a10:
or x, x, 0xf8000000
a20: