Skip to content

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

asm
.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

asm
.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

asm
.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)

Condition Code Register

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

The contents of this E-Text were developed under an Open Textbooks Pilot grant from the Fund for the Improvement of Postsecondary Education (FIPSE), U.S. Department of Education. However, those contents do not necessarily represent the policy of the Department of Education, and you should not assume endorsement by the Federal Government.
Released under Creative Commons BY NC 4.0 International License