In: Computer Science
Show the encoding of the following machine instructions and convert into hexadecimal.
1. STUR X7, [X9, #32]
2. SUBI X16, X4, #52
3. AND X5, X20, X3
Answer is as follows :
As we know that these instructions are 32 bit long. So machine instructions for given set are :
1) STUR X7, [X9, #32] : D-type Instruction
First 11 bits ( 31 to 21) are set for Opcode . So opcode is 0x7C0 for this instruction i.e. 11111000000.
Next 9 bits ( 20 to 12) are set for address or constants. So constant is #32 (in decimal) i.e. 000100000
Next 2 bits ( 11 to 10) are set to 00 for D- Type. So it is 00
Next 5 bits (9 to 5) are set for Address register i.e. X9 here. So it is 01001 in binary
Next 5 bits (4 to 0) are set for destination register i.e. X7 here. So it is 00111 in binary.
So we get
11111000000 000100000 00 01001 00111
or we can write as
1111 1000 0000 0010 0000 0001 0010 0111 i.e. 0xF8020127 in hexadecimal
So this instruction has
Machine Code - 1111 1000 0000 0010 0000 0001 0010 0111
Hexadecimal Code - 0xF8020127
2. SUBI X16, X4, #52 : I-type Instruction
First 11 bits ( 31 to 21) are set for Opcode . So opcode is 0x344 for this instruction i.e. 01101000100.
Next 11 bits ( 20 to 10) are set for address or constants. So constant is #52 (in decimal) i.e. 00000110100
Next 5 bits (9 to 5) are set for Source register i.e. X4 here. So it is 00100 in binary
Next 5 bits (4 to 0) are set for destination register i.e. X16 here. So it is 10000 in binary.
So we get
01101000100 00000110100 00100 10000
or we can write as
0110 1000 1000 0000 1101 0000 1001 0000 i.e. 0x6880D090 in hexadecimal
So this instruction has
Machine Code - 0110 1000 1000 0000 1101 0000 1001 0000
Hexadecimal Code - 0x6880D090
3. AND X5, X20, X3 : R-Type Instruction
First 11 bits ( 31 to 21) are set for Opcode . So opcode is 0x458 for this instruction i.e. 10001011000.
Next 5 bits (20 to 16) are set for Source register 2 i.e. X3 here. So it is 00011 in binary
Next 6 bits (15 to 10) are set for Shift OPerations. So this is arithmetic instruction so this will be 000000
Next 5 bits (9 to 5) are set for Source register 1 i.e. X20 here. So it is 10100 in binary
Next 5 bits (4 to 0) are set for destination register i.e. X5 here. So it is 00101 in binary.
So we get
10001011000 00011 000000 10100 00101
or we can write as
1000 1011 0000 0011 0000 0010 1000 0101 i.e. 0x8B030285 in hexadecimal
So this instruction has
Machine Code - 1000 1011 0000 0011 0000 0010 1000 0101
Hexadecimal Code - 0x8B030285
if there is any query please ask in the comments..