In: Computer Science
Encode the following instruction
(1) identify the instruction format that will be used
(2) indicate the values of each of the fields for that format in decimal
(3) convert each of these decimal val- ues to binary
(4) represent the entire instruction as one hexadecimal value
j L2. # where L2 is at the decimal byte address 1,048,608
Greetings!!
1) J instruction format is used.
Opcode(6 bits) | Memory address(26 bits) |
j L2 or equivalently can be written as j 0x00100020 because the label L2 has an address 1048608(00100020 in hex).
4) Opcode = 000010
Memory address = 00 0000 0100 0000 0000 0000 1000
Machine code = 0000 1000 0000 0100 0000 0000 0000 1000 = 0x08040008
From the given address 00100020(equivalent binary is 0000 00 0000 0100 0000 0000 0000 1000 00) 26 bit jump address(0040008) will be taken and append to make the machine code. The least 2 bits are not used because this is obtained after shifting the address left by 2 bits to align it to the memory word address.
Address calculation during program execution: 26 bits(00 0000 0100 0000 0000 0000 1000) from the machine code is shifted left by 2 bits(or multiplied by 4 to align it to word sized memory) and append to the 4 MSB bits of the current PC. ie 0000 + 0000000100000000000000100000 = 00000000000100000000000000100000 = 00100020 which is the actual jump address.
2) Decimal:
Opcode: 2 | Memory address: 262152 |
3) Binary:
Opcode(6 bits):000010 | Memory address(26 bits):00000001000000000000001000 |
Hope this helps