|
|
|
|
Posted on 06-14-2006, by Tim
There are 15 instructions in LC-3 assembly language. They are separated into three different categories: operation, data movement, and finally, control.
Please note: more advanced instructions such as TRAP, will be covered in a later tutorial.
Operation Instructions
ADD - Destination , Source , Source
ADD takes in two numbers and stores their sum in the Destination register. The first source must be a register, while the second source may be either a register or an immediate value.
Examples:
AND - Destination , Source , Source
AND performs a bitwise AND operation on the two sources (both registers) and stores the value in the Destination register. The second source may also be an immediate value.
Examples:
NOT - Destination , Source
The NOT instruction takes a value (source register) and inverts it in the destination register. For example, if it held the value of "011001," then NOTing the value would give you "100110."
Example:
Data Movement Instructions
LD - Destination , Source
The LD instruction takes a source label and stores its address into the destination register. The source label must be within 255 lines of the LD instruction.
Example:
LDR - Destination , Source , Offset
LDR stores the source register's value plus an immediate value offset and stores it in the destination register.
Example:
LDI - Destination , Source
LDI treats the source register as an address and stores the contents of memory at that address in the destination register.
Examples:
ST - Destination , Source
This function stores a value (source label) into a destination register.
Example:
STR - Destination , Source , Offset
STR stores the value in a source register into a destination register. An immediate offset may also be used. If you do not want to use an offset, simply pass a #0 as the offset.
Example:
STI - Destination , Source
STI treats its immediate value source, or a label as a memory address and stores the value of that address into the destination register.
Example:
Control Instructions
BR - n z p Label
Think of the BR instruction as an if statement in higher-level languages. However, the BR command is more picky about how you use it. BR will only jump to a new memory location depending on whether or not the previous instruction's result was negative, zero, or positive. You may tell BR to jump on either zero or positive, or even all three. To tell BR to jump on a specific condition, append it to the command. For example, jumping on only negative numbers would be "BPn" whereas jumping on negative, zero or positive would be "BPnzp." It is interesting to note that these condition flags MUST be placed in this order.
Example:
| Code: | LOOP:
ADD R1, R1, #-1
BRp LOOP |
If R1 contains a positive value when it continues onto the BRp line, then BR will jump back to the beginning of the LOOP label. If not, it will go to the next line.
JMP - Source
JMP will jump to a source register's location.
Example:
JSR - Label
JSR is used to simulate subroutines and functions where the label is an immediate value that is the beginning of the function.
Example:
JSRR - Destination
JSRR is nearly identical to JSR except that uses a register instead of a label.
Example:
Difficulty: Beginner - Views: 27905
| chaoscreater wrote: | I think some of these are wrong? E.g.
| : | ST - Destination , Source
This function stores a value (source label) into a destination register.
Example:
|
isn't ST suppose to store the contents in the register R1, into the memory address/label ADDR?? I checked all my LC3 notes and it's the opposite to what it says on this page.........some of these are opposites to my notes, could you please check them? |
|
|