Write an LC-3 assembler in LC-3 assembly (just handling mnemonic -> opcode, not operands)

853 Views Asked by At

The LC-3 assembler must be able to map an instruction's mnemonic into its binary opcode. For instance, given an ADD, it must generate the binary pattern 0001.

The user must type in an LC-3 assembly language mnemonic and the program then displays its binary opcode.

If the assembly language mnemonic is invalid, it displays an error message.

So I'm writing the beginning of an LC-3 assembler in LC-3 assembly language, just handling mnemonic -> opcode mapping, not operands.Is there a way to do this without bruce forcing it? That is to say without having to write every mnemonic into memory.

(related: Difference between: Opcode, byte code, mnemonics, machine code and assembly)

.ORIG x3000
AND R0, R0, #0 
    IN      
    LD  R1, A   
    ADD R1, R1, R0
    BRz ND

LD  R1, B   
    ADD R1, R1, R0
    BRz ZERO    

ND  AND R0, R0, #0
IN
LD  R1, N
    ADD R1, R1, R0
    BRz ZZZO
    BRnp
ZZZO    AND R0, R0, #0
    LD  R0, N1
ZERO    AND R0, R0, #0
    OUT 
    HALT
A   .FILL   x8041
B   .FILL   x8042
D   .FILL   x8044
E   .FILL   x8045
I   .FILL   x8049
J   .FILL   x804A
M   .FILL   x804D
N   .FILL   x804E
N1  .FILL   x
O   .FILL   x804F
P   .FILL   x8050
R   .FILL   x8052
S   .FILL   x8053
T   .FILL   x8054
0

There are 0 best solutions below