Giter Club home page Giter Club logo

lalu-assembler's Introduction

LALU Assembler

"A simple assembler for a simple processor."

Labels:

Writing the @ symbol lets you 'name' the next address in program memory. A label can be used in place of any 5-bit address.

@abc // stores the address of the next command
add
sub
jmp @abc // goes back to the 'add' statement
Pointers:

Writing the * symbol lets you 'name' an address in data memory. A pointer can be used in place of any 4-bit address.

*idx = 0101
st *idx // stores A to 0101
Bases:

You can enter any number as a binary, decimal, or hexidecimal. All of the following lines do the same thing (set the pointer *idx to 0100). The assembler deduces the number of bits that the number should take up.

*idx = 0b100 // 0b in front means binary
*idx = 0b0100 // any number of leading zeros
*idx = 100 // (no modifier means binary)
*idx = 0d4 // 0d for decimal
*idx = 0x4 // 0x for hexidecimal
Literal command:

If your implementation has extra non-standard commands, good for you! You can still use the assembler if you encode your special commands as literals. When the assmbler comes to a literal number , it translates that number into binary literally. For example:

This

add
sub
0b11110001
0xAD
51
add
sub

Compiles to

00 01 F1 AD 00 01

since 11110001 base 2 is F1 base 16.

Comments:

Java-style comments are ignored (both line-comments and block-comments).

add // This is a comment
sub /*
this is a comment
so is this
*/
ld 100 // /*
(notably) this is a comment
*/
Commands:
  • add (0000)
  • sub (0001)
  • ld (0010) takes one 4-bit address
  • xchg (0011)
  • st (0100) takes one 4-bit address
  • jmp (101) takes one 5-bit address
  • djmp ("delayed jump") is an alias for jmp
  • jmpn (110) takes one 5-bit address
  • djmpn ("delayed jump if negative") is an alias for jmpn
  • loada (0111)
  • sta (1000)
  • incr (1001)
  • nop (1000)
Whitespace ignorant:

This

add       sub
ld
1000
st1000

is equivalent to this

add
sub
ld 1000
st 1000
Errors:

Error messages look really nice with line number and the error line with the offending token underlined. Hopefully you won't have to see them. :)

CMD mode:

Execute the program normally (with no arguments) to enter GUI mode as usual.

To use CMD mode, add the argument cmd to the program. It reads source from stdin, outputs the assembled binary to stdout, and outputs errors to stderr. Run this from the prompt to compile test.asm to tset.out: java -jar LALU_Assembler_v*.jar cmd < test.asm > test.out.

lalu-assembler's People

Stargazers

Neil Patil avatar Arthur Pachachura avatar

Watchers

James Cloos avatar Sam Grayson avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.