I am having trouble figuring out how a LEGv8 machine instruction is decoded. Assume the following binary:
1000 1011 0000 1111 0000 0000 0001 0011
I have the following chart that is supposed to help me decode:
The first 11 bits 10001011000 correspond to decimal 1112 and according to the chart this is the ADD instruction. So I know how to determine this part of the instruction (unless there is a better approach, maybe this won't work for opcodes that aren't 11 bits?). At this point I am confused on how to proceed.
I know that ADD is of instruction format R-format so the bits are layed out as below:
opcode: 11 bits
Rm: 5 bits
shamt: 6 bits
Rn: 5 bits
Rd: 5 bits
I attempt to lay out the initial binary machine instruction knowing these field sizes...
opcode = 1000 1011 0000 1111 0000 0000 0001 0011 = 10001011000
This is the first 11 bits of the initial binary machine instruction.
Rm = 1000 1011 0000 1111 0000 0000 0001 0011 = 01111
This is the next 5 bits after the initial 11 bits for opcode.
shamt = 1000 1011 0000 1111 0000 0000 0001 0011 = 000000
This is the next 6 bits after the 5 bits for Rm.
Rn = 1000 1011 0000 1111 0000 0000 0001 0011 = 00000
This is the next 5 bits after the 6 bits for shamt.
Rd = 1000 1011 0000 1111 0000 0000 0001 0011 = 10011
This is the last 5 bits in the binary machine instruction (the 5 bits after the 5 bits for Rn).
Converting binary to decimal for the Rm, Rn and Rd I get:
Rm = 15 = X15
Rn = 0 = X0
Rd = 19 = X19
Therefore my final answer to decoding the initial binary machine instruction to an assembly statement would be ADD X19, X0, X15
However the textbook answer where this example is from is ADD X16, X15, X5. Where did I go wrong?
Your solution seems to be correct, and also matches output produced by gnu binutils:
$ echo .int 0b10001011000011110000000000010011 > test.s
$ as test.s && objdump -d a.out
a.out: file format elf64-littleaarch64
Disassembly of section .text:
0000000000000000 <.text>:
0: 8b0f0013 add x19, x0, x15
Books are known to contain errors ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With