Giter Club home page Giter Club logo

another-little-asm's Introduction

Build Status

Yet another Little ASM

yla is an custom Assembly-like language, implemented from scratch in C++. Name inspired on my-little-asm deverloped by @alexdantas witch was also deverloped as System Software class assigment at UnB. So far, it has an assembler (to create machine code), a linker, a loader and a simulator.

This is an example on how Assembly languages work - a set of human-readable instructions that are translated into machine code. Normally the language would be designed for some hardware to execute, but in our case we simulate it step by step.

With our basic instruction set we can potentially write any existing program out there - also called Turing-completeness.

We have a parser that reads each instruction on the text file and converts them into integers - indexing all 14 possible instructions.

First, make sure to compile everything by doing:

$ make

Sample code

SECTION TEXT
ROT: INPUT N1
    COPY N1, N4 ; Comentary
    COPY N2, N3
    COPY N3, N3 + 1
    OUTPUT N3 + 1
    STOP

SECTION DATA
N1: SPACE
N3: SPACE  4        ; Array of size 4
N2: CONST  -0x10    ; Look ma, hex constant!

Language definition

yla follows a MIPS Assembly-like syntax.

Highlights:

  • 14 instructions.
  • ; starts comment until the end of line.
  • Labels references memory addresses.
  • Accumulator register (ACC) implied on arithmetic instructions.
  • Files with .asm extension.

Code is divided in two sections:

  • Text section (for actual code)
  • Data section (for variables and constants)

Instructions

Name Instruction Description
Add ADD ACC <- ACC + MEM[OP]
Subtract SUB ACC <- ACC - MEM[OP]
Multiply MULT ACC <- ACC * MEM[OP]
Divide DIV ACC <- ACC / MEM[OP]
Jump Unconditional JMP PC <- OP
Jump if Negative JMPN If ACC < 0 then PC <- OP
Jump if Positive JMPP If ACC > 0 then PC <- OP
Jump if Zero JMPZ If ACC = 0 then PC <- OP
Copy COPY MEM[OP2] <- MEM[OP1]
Load from Memory LOAD ACC <- MEM[OP]
Store into Memory STORE MEM[OP] <- ACC
Store Input INPUT MEM[OP] <- STDIN
Output Memory OUTPUT STDOUT <- MEM[OP]
Stop Execution STOP stops program

Note:

  • MEM[OP] means memory address specified by operand and PC is the program counter (current instruction address).

Directives

Name Effect
SECTION TEXT Signals begin of instructions.
SECTION DATA Start of data definitions.
SPACE Saves an empty space on memory for data storage.
SPACE N Saves an empty array in memory of size N.
CONST X Saves a constant of value X in memory.
CONST X Saves a constant of value X in memory.

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.