Write the LEGv8 assembly for the following code snippet assu
Write the LEGv8 assembly for the following code snippet (assuming the base address of A is in X9, the base address of B is in X10, i is in X11 and j is in X12 and that A and B store 64-bit integer values): A[i]=B[i]
Solution
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
