LC3 Huongdancode
LC3 Huongdancode
Instruction Set
Op Format Description Example
ADD ADD DR, SR1, SR2 Adds the values in SR1 and ADD R1, R2, #5
ADD DR, SR1, imm5 SR2/imm5 and sets DR to that The value 5 is added to the value in
value. R2 and stored in R1.
AND AND DR, SR1, SR2 Performs a bitwise and on the AND R0, R1, R2
AND DR, SR1, imm5 values in SR1 and SR2/imm5 A bitwise and is preformed on the
and sets DR to the result. values in R1 and R2 and the result
stored in R0.
BR BR(n/z/p) LABEL Branch to the code section BRz LPBODY
Note: (n/z/p) means indicated by LABEL, if the bit Branch to LPBODY if the last
any combination of indicated by (n/z/p) has been set instruction that modified the
those letters can appear by a previous instruction. n: condition codes resulted in zero.
there, but must be in negative bit, z: zero bit, p: BRnp ALT1
that order. positive bit. Note that some Branch to ALT1 if last instruction
instructions do not set condition that modified the condition codes
codes bits. resulted in a positive or negative
(non-zero) number.
x
LC-3 Quick Reference Guide
Symbol Legend
Symbol Description Symbol Description
SR1, SR2 Source registers used by instruction. LABEL Label used by instruction.
DR Destination register that will hold trapvector8 8 bit value that specifies trap service
the instruction’s result. routine.
imm5 Immediate value with the size of 5 offset6 Offset value with the size of 6 bits.
bits.
TRAP Routines
Trap Vector Equivalent Assembly Description
Instruction
x20 GETC Read one input character from the keyboard and store it into R0
without echoing the character to the console.
x21 OUT Output character in R0 to the console.
x22 PUTS Output null terminating string to the console starting at address
contained in R0.
x23 IN Read one input character from the keyboard and store it into R0 and
echo the character to the console.
x24 PUTSP Same as PUTS except that it outputs null terminated strings with
two ASCII characters packed into a single memory location, with
the low 8 bits outputted first then the high 8 bits.
x25 HALT Ends a user’s program.
Pseudo-ops
Pseudo-op Format Description
.ORIG .ORIG # Tells the LC-3 simulator where it should place the segment of
code starting at address #.
.FILL .FILL # Place value # at that code line.
.BLKW .BLKW # Reserve # memory locations for data at that line of code.
.STRINGZ .STRINGZ “<String>” Place a null terminating string <String> starting at that location.
.END .END Tells the LC-3 assembler to stop assembling your code.
xi