Difference between revisions of "Calico LC3"
Doug Blank (Talk | contribs) |
Doug Blank (Talk | contribs) (→Instructions) |
||
Line 77: | Line 77: | ||
</pre> | </pre> | ||
− | + | == Extensions == | |
+ | |||
+ | There is an unused instruction in the original LC3 instruction set. You can use add one of two possible extensions: | ||
+ | |||
+ | * A set of graphical instructions for drawing simple pictures | ||
+ | * A shift instruction | ||
+ | |||
+ | You may select these two modes by issue one of the following inside your assembly program: | ||
+ | |||
+ | * .SET MODE GRAPHICAL | ||
+ | * .SET MODE SHIFT | ||
+ | |||
+ | |||
+ | The SHIFT instruction takes this form: | ||
<pre> | <pre> | ||
Line 84: | Line 97: | ||
; store in destination register (DestR) | ; store in destination register (DestR) | ||
</pre> | </pre> | ||
+ | |||
+ | Example: | ||
+ | |||
+ | <pre> | ||
+ | SHIFT R0, R1, #1 ; shift the contents of R1 to the left by one bit | ||
+ | ; and store the result in R0 | ||
+ | </pre> | ||
+ | |||
+ | The GRAPHICS instructions: | ||
+ | |||
+ | <pre> | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | [[Image:graphical-codes.png]] | ||
= Examples = | = Examples = |
Revision as of 02:06, 13 December 2013
Calico LC3 is an assembly language based on the Little Computer by Patt and Patel. Calico LC3 is a language in the Calico Project.
Contents
Overview
Calico LC3 is an implementation of Patt and Patel's LC3 assembly language. The language is written in Calico Python, but appears as a full language in Calico.
In Calico, you need to first enable the LC3 language before using it:
- start Calico
- under menu -> Calico -> Languages
- make sure that "LC3" is checked
- Create a new LC3 script, or examine one of the Examples
- (Enable "Spreadsheet", too if you want to use it to display memory)
Special features:
- Tracing, breakpoints, integrated IDE
- syntax color highlighting
- Right-click on errors takes you to line of code
- Assembler and interpreter
- Counts instructions executed
- Counts machine cycles executed, estimates milliseconds to run
- Error checking and useful error messages
- menu -> View -> Tabs -> Locals - shows registers
- Shows memory as Calico Spreadsheet
Source Materials:
- http://highered.mcgraw-hill.com/sites/0072467509/
- http://www.cs.georgetown.edu/~squier/Teaching/HardwareFundamentals/LC3-trunk/docs/LC3-AssemblyManualAndExamples.pdf
Special Interactive Directives
Enter these commands in the Calico Shell entry area:
Interactive Directives: .help - shows this info .show memory - display memory as a Spreadsheet .assemble - assemble the first .asm file in Calico .step - execute the next instruction, increment PC .reset - reset LC3 to start state") .raw [start [stop]] - list meory in hex .list - list program from memory .dump [start [stop]] - dump memory as program .regs - show registers .set pc HEXVALUE - set PC .set memory HEXLOCATION HEXVALUE- set memory .set reg VALUE HEXVALUE - set register .get pc - get PC .get memory HEXLOCATION - get memory .get reg VALUE - get register
Instructions
ADD DR, SR1, SR2 ; Addition ADD DR, SR1, imm5 ; Addition with Immediate AND DR, SR1, SR2 ; Bit-wise AND AND DR, SR1, imm5 ; Bit-wise AND with Immediate BRx, label (where x = {n,z,p,zp,np,nz,nzp}) ; Branch JMP BaseR ; Jump JSR label ; Jump to Subroutine JSRR BaseR ; Jump to Subroutine in Register LD DR, label ; Load PC-Relative LDI DR, label ; Load Indirect LDR DR, BaseR, offset6 ; Load Base+Offset LEA, DR, label ; Load Effective Address NOT DR, SR ; Bit-wise Complement RET ; Return from Subroutine RTI ; Return from Interrupt ST SR, label ; Store PC-Relative STI, SR, label ; Store Indirect STR SR, BaseR, offset6 ; Store Base+Offset TRAP immediate-vector ; System Call
Extensions
There is an unused instruction in the original LC3 instruction set. You can use add one of two possible extensions:
- A set of graphical instructions for drawing simple pictures
- A shift instruction
You may select these two modes by issue one of the following inside your assembly program:
- .SET MODE GRAPHICAL
- .SET MODE SHIFT
The SHIFT instruction takes this form:
SHIFT DestR, SR, immed6 ; shift source register (SR) by immed6 ; (positive, left; negative right) and ; store in destination register (DestR)
Example:
SHIFT R0, R1, #1 ; shift the contents of R1 to the left by one bit ; and store the result in R0
The GRAPHICS instructions:
Examples
Here is a basic Hello World assembly program.
;; helloworld.asm .ORIG x3000 LEA R0, HELLO PUTS HALT HELLO .STRINGZ "Hello, World!\n" .END
There are more examples in menu -> File -> Examples -> LC3.
Future Possibilities
- integrate with other languages
- create real code that could be executed on computer (maybe .NET/Mono VM code?)
- load/run binary-text files and obj files
- show dissassembled code