Giter VIP home page Giter VIP logo

pycmpy's Introduction

pycmpy

Learning about compilers and the assembly language with the Raspberry Pi.

Most files are mainly just examples, some may not work.

pycmpy/ folder contains a semi functional compiler written in python. It can add numbers and stuff, just not print them. It can print words, just not do anything else with them. See the directories README for more info.

pycmpy compiler

We can compile super non-trivial programs like this that will totally blow your mind. Say we have source file hello.cmpy whose contents is as follows:

print "hello, world!";

We can use pycmpy to compile this to native machine code by runninging (from within this directory):

$ python pycm.py hello.cmpy -o hello

What this will do is take the file hello.cmpy and create the executable hello. You should see an output like this.

Created file: hello.s
making executable...
------------------------------------------------
as -o hello.o hello.s
as -o io.o lib/io.s
ld -o hello hello.o io.o
Created file: hello.s
------------------------------------------------
successfully created executable:'hello'
to run: $ ./hello

We can now run this crazy program.

$ ./hello
hello, world!

Behind the scenes pycmpy created the file hello.s which in this case looks like this.

.global _start
_start:
	LDR R0, =string_const_0x0000
	MOV R1, #14
	BL io_print

	MOV R0, #0
	MOV R7, #1
	SWI 0

string_const_0x0000: .asciz "hello, world!\n"

.extern io_print

The io_print routines and possibly others are defined in the lib directory. After creating this it hands the rest over to as and ld who finish the job creating the executable.

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.