I am writing a program in C to convert a hex file compiled for the LC3 processor back into assembly language.
Currently, I am trying to decode the ADD
instruction.
There are two types of ADD
s in LC3 assembly language:
- add by reference: adding two registers
- add immediate: adding a register to a hard-coded value
For example, the hex code 164F
would be converted to: ADD R3, R1, R7
. this is an add by reference. Conversely, the hex code for 153F
would be converted to: ADD R2, R4, #-1
. This is an add immediate.
The function should decode both as appropriate.