Arithmetic and Logic Instructions
The LC-3 provides three (3) Arithmetic and Logic Unit (ALU) Instructions
All ALU instructions are preformed on data in Registers and the results are stored in Registers
NOT
Performs a logical NOT on data in a register
.ORIG x3000
AND R0, R0, #0; Clear out whatever is currently in R0
ADD R0, R0, #5; Set R0 to 5
NOT R1, R0; Invert the value in R0 and store in R1
Done HALT
;End of Program
;Data Declarations-------------
.END
AND
Performs a logical AND on data in two Register, storing the result in a Register
.ORIG x3000
AND R0, R0, #0; Clear out whatever is currently in R0
ADD R0, R0, #5; Set R0 to 5
NOT R1, R0; Invert the value in R0 and store in R1
Done HALT
;End of Program
;Data Declarations-------------
.END
ADD
Performs a logical ADD on data in two Register, storing the result in a Register
.ORIG x3000
AND R0, R0, #0; Clear out whatever is currently in R0
ADD R0, R0, #5; Set R0 to 5
NOT R1, R0; Invert the value in R0 and store in R1
Done HALT
;End of Program
;Data Declarations-------------
.END
Condition Code Register
All ALU instructions set the Condition Code (CC) register at the end of executing the instruction
This register can be used by future instructions that might decide to change the program's flow (like an If/Else -or- Loop behavior)
The CC will be in one of three possible states:
N - The last operation resulted in a Negative Value
Z - The last operation resulted in a Zero Value
P - The last operation resulted in a Positive Value
Other instructions do not change the CC, so it will holding last value until another of the above 4 instructions is executed