Coder Social home page Coder Social logo

llvm's Introduction

LLVM

A Low Level Virtual Machine in python. (obviously not very performant)

Also has a compiler

LLVM Instructions

0000: inc - Increment a register
0001: dec - Decrement a register
0010: mov - Copy a register
0011: set - Set a register to a value
0100: psh - Push a register to a stack
0101: pop - Pop and get a value from a stack
0110: beq - Branch if equal
0111: bne - Branch if not equal
1000: bnz - Branch if not zero
1001: jmp - Jump
1010: and - And 2 memory
1011: or - Or 2 memory
1100: xor - Xor 2 memory
1101: shl - Shift left
1110: shr - Shift right
1111: hlt - Halt (exit)

Memory

8 bit memory

Addresses

0b0     - does syscall
0b1     - syscall arg 1
0b11    - syscall arg 2
0b100   - syscall return
0b101   - flags
0b110   - jump address
0b111   - return address
0b1111  - Assembler temp register

Syscalls

0b0:   no call
0b1:   print    - Print a byte
0b10   input    - Get a byte from stdin
0b11   getstack - Get stack pointer
0b100  setstack - Set stack pointer

more soon

Flags

0b0   - No flag
0b1   - Stack err
0b10  - Print err
0b11  - Input err

Example program

#define arg1 0b1

print:                ;; print a byte stored in the syscall arg1 register
    syscall 0b0001    ;; print syscall

start:                ;; The program prints every 8-bit ascii character.
    inc arg1          ;; increment arg1 (syscall does not wipe args)
    bnz print arg1    ;; if arg1 is not zero, branch to print
    hlt               ;; Halt

Using the llvm

Syntax: py llvm.py <filename>

Using the compiler

Syntax: py compiler.py <filename> <outfilename>

llvm's People

Contributors

omena0 avatar

Watchers

 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.