Skip to content

Emulator and assembler for my "LEG" Architecture CPU in the game "Turing Complete"

License

Notifications You must be signed in to change notification settings

bczhc/leg-cpu-emulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LEG-CPU-emulator

Emulator and assembler for my "LEG" Architecture CPU in the game "Turing Complete".

Build

cargo build -r

Run All Tests

cargo test

CLI Usage:

Usage: leg [OPTIONS] <SOURCE>

Arguments:
  <SOURCE>
          Path to the source file.
          
          The source file is of the two filename extensions: .asm/.bin

Options:
  -o, --output <OUTPUT>
          Path to the output file.
          
          If no output file is specified, derive from the input file.

  -t, --out-type <OUT_TYPE>
          [possible values: commented-hex, binary]

  -r, --run
          Assemble and run

      --stdout
          Output to stdout

  -i, --input <INPUT>
          Path to the program input

      --stdin
          Read program input from stdin

  -h, --help
          Print help (see a summary with '-h')

Example

hello_world.asm:

.data 0
text 'hello, world' text_len

.entry start

.code
start:
    cp 0 r0 ; r0 <- 0
    for1:
    add r0 text r1
    ld r1 r1 ; r1 <- text[i]
    cp r1 out ; print character out
    add r0 1 r0 ; increase r0
    jamv for1 ; move address of label 'for1' to the jump-address register
    jplt r0 text_len ; do the jump if r0 < text_len
    cp 0x0a out ; print the new-line
    halt
leg hello_world.asm -r
hello, world

Or

leg hello_world.asmleg hello_world.bin
hello, world

For the code that can be used in Turing Complete, use:

leg hello_world.asm --stdout -t hex
0x01 0x0c 0x00 0x10 # copystatic
0x68 0x65 0x6c 0x6c 0x6f 0x2c 0x20 0x77 0x6f 0x72 0x6c 0x64 # data
# start:
0x83 0x00 0x00 0x00 # cp 0 r0
# for1:
0x48 0x00 0x00 0x01 # add r0 text r1
0x28 0x01 0x01 0x00 # ld r1 r1
0x03 0x01 0x00 0x0c # cp r1 out
0x48 0x00 0x01 0x00 # add r0 1 r0
0x44 0x00 0x14 0x00 # jamv for1
0x62 0x00 0x0c 0x00 # jplt r0 text_len
0x83 0x0a 0x00 0x0c # cp 0x0a out
0x02 0x00 0x00 0x00 # halt

water_world.asm:

echo '4,6,1,4,6,5,1,4,1,2,6,5,6,1,4,2' | target/debug/leg tests/asm/water_world.asm -r --stdin
28echo '5,6,2,5,1,3,2,1,1,1,1,1,1,1,1,1' | target/debug/leg tests/asm/water_world.asm -r --stdin
5

More examples are under tests.

WebUI

Dev-Run

cd web-ui
wasm-pack build
cd web && npm run dev

Build

cd web-ui
wasm-pack build
cd web && npm run build
# now files to serve are under dist/

About

Emulator and assembler for my "LEG" Architecture CPU in the game "Turing Complete"

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published