Q1)
A)
from the green card:
| code | Width (bits) | Binary |
|---|---|---|
i) opcode (lw) | 7 | 0000011 |
ii) rd (x14) | 5 | 01110 |
iii) rs1 (x10) | 5 | 01010 |
iv) imm[11:0] (16) | 12 | 000000010000 |
| v) we know its in the format `imm[11:0] | rs1 | funct3 |
00000001000001010010011100000011
B)
converting from binary to hexadecimal and grouping we get 0x01052703
C)
from part b we get the hex then we get each digit and multiply it by to get the unsigned decimal
-
- Unsigned decimal = 17 114 883
Q2)
A)
im going to use the method of dividing by 2 then taking the remainder as the bit and since we are dividing by 2 we read from bottom as msb and top as lsb
| Step | Quotient | Remainder (bit) |
|---|---|---|
| 28 215 603 ÷ 2 | 14 107 801 | 1 |
| 14 107 801 ÷ 2 | 7 053 900 | 1 |
| 7 053 900 ÷ 2 | 3 526 950 | 0 |
| 3 526 950 ÷ 2 | 1 763 475 | 0 |
| 1 763 475 ÷ 2 | 881 737 | 1 |
| 881 737 ÷ 2 | 440 868 | 1 |
| 440 868 ÷ 2 | 220 434 | 0 |
| 220 434 ÷ 2 | 110 217 | 0 |
| 110 217 ÷ 2 | 55 108 | 1 |
| 55 108 ÷ 2 | 27 554 | 0 |
| 27 554 ÷ 2 | 13 777 | 0 |
| 13 777 ÷ 2 | 6 888 | 1 |
| 6 888 ÷ 2 | 3 444 | 0 |
| 3 444 ÷ 2 | 1 722 | 0 |
| 1 722 ÷ 2 | 861 | 0 |
| 861 ÷ 2 | 430 | 1 |
| 430 ÷ 2 | 215 | 0 |
| 215 ÷ 2 | 107 | 1 |
| 107 ÷ 2 | 53 | 1 |
| 53 ÷ 2 | 26 | 1 |
| 26 ÷ 2 | 13 | 0 |
| 13 ÷ 2 | 6 | 1 |
| 6 ÷ 2 | 3 | 0 |
| 3 ÷ 2 | 1 | 1 |
| 1 ÷ 2 | 0 | 1 |
| then reading from msb to lsb we get `00000001 10101110 10001001 00110011 | ||
| ` |
B)
for this we can group them into 4 nibbles :) then get their corresponding hex value by knowing each 4 bits giving 16 in length
| Binary | Hex |
|---|---|
| 0000 | 0 |
| 0001 | 1 |
| 1010 | A |
| 1110 | E |
| 1000 | 8 |
| 1001 | 9 |
| 0011 | 3 |
| 0011 | 3 |
then adding the 0x telling it the numbers are hex we get 0x01AE8933 |
C)
i)
- to find the operation we can look at the last 7 bits first to determine the opcode as its the same for all types of instructions, and then first 7 to determine if its a funct7 or an immediate
00000001 10101110 10001001 00110011and looking at this we can see the last 7 being indicative of an r type so we check the first 7 bits for operation, which matches add
ii)
- to find the destination its the rd, and that is the 11th bit to the 7th bit which is
10010which gives us x18 register
iii)
- to find the 2 sources we can find using the bits for rs1 19-15 and rs2 24-20 and converting that to decimal gives us x29, x26
iv)
- thus the full operation is
add x18, x29, x26
3-4)
- i would love to do a full write up for 3-4 but i just dont have time, and since they are not marked im not going to post them sorry </3 if they are supposed to be marked but as a mistake or smth
- here is my proof if you would like it ill do it :) because practice is good