Skip to content

My high-level programming language with the syntax of assembly

Notifications You must be signed in to change notification settings

antosmichael07/MispASM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MispASM

Getting started

Your first program

  • Start by making a main function like this :
global _start

_start
global _start

_start
    mov s0 "Hello World!"
  • Now print "Hello World!"
global _start

_start
    mov s0 "Hello World!"
    
    push s0
    call "std.print"
    pop s0
  • Great you wrote your first program, if it didn't work, you might not have the std library, you can get the code from the lib folder here on github and compile it manually

What MispASM offers

Types

  • int, float, string, register, variable, constant
  • To differentiate between numbers you can type :
i8-123
i16-123
i32-123
i64-123
u8-123
u16-123
u32-123
u64-123
f32-123.45
f64-123.45
  • If you just type a number it is automatically i32 and if you type a . in the number it is automatically f32
  • Strings are typed : "Hello World!"

Functions

  • Functions start with _
  • Declare main function at the start of the program : global _start
  • Call a function : fcal <function>
  • Functions are typed as strings in arguments
  • Call a function from a library : call "std.print"
  • When calling a library from a program, the .misplib file has to be located in ../lib/<name>.misplib
  • You can pass registers to the library with stack

Variables and constants

  • Variables have to be set at the start of the program and can be changed with : set <variable> <arg2>
  • Constants cannot be changed
  • You need to declare them before global function
const:
    hello "Hello World!"

var:
    bye "Goodbye!"

global _start
  • They have to be declared in this order, firstly constants and then variables, but you don't need to use both

Instructions

  • They have a maximum of 2 arguments
  • Syntax : <instruction> <arg1> <arg2>

Registers

  • Registers are typed : li0, the zero indicates that it is the first long integer
  • There is 256 of every register
  • Are used as variables, but they can perform operations, variables can only be set
  • Can be used as arguments to instructions
  • Store data with : mov <register> <arg2>
  • Return registers are used for storing data after an instruction that performs a calulation, for example add sets the register : rli return long integer or other if you use different type than i32

Stack

  • Stores data and passes them to libraries
  • Only registers can be stored
  • Store data with : push <register>
  • Delete data with : pop <register>

Writing a library

What you need

How to

  • When calling a library from a program, the .misplib file has to be located in ../lib/<name>.misplib
  • Use the Misp Library builder, it will generate a structure of files
    • ./build.bat for building your library
    • ./lib/lib.go is for decoding and encoding data between a program and your library, you don't need to worry about it
    • ./lib/<name>.go is for your functions in the library, there is a map of functions where you write your functions
    • ./test/test.mispasm the .mispasm program that is used to test your library
  • The command misplib needs these arguments : misplib <destination> <name>

Cheatsheet

Instruction Description
add Addition
sub Subtraction
fcal Function call
mul Mulitplication
div Division
call Call from library
push Push to the stack
pop Pop from the stack
mov Move to register
label Label
jmp Jump to label
mod Modulo
cmp Compare
je Jump equal
jne Jump not equal
jg Jump greater
jge Jump greater or equal
jl Jump less
jle Jump less or equal
inc Increase
dec Decrease
ret Return
def Defenestrate the program
set Set a variable
and Logical AND
or Logical OR
xor Logical XOR
shr Shift bits right
shl Shift bits left
not Logical NOT
hlt Halt
Register Description
bi Byte integer i8
si Short integer i16
li Long integer i32
lli Long long integer i64
bui Byte unsigned integer u8
sui Short unsigned integer u16
lui Long unsigned integer u32
llui Long long unsigned integer u64
lf Long float f32
llf Long long float f64
s String
rbi Return byte integer i8
rsi Return short integer i16
rli Return long integer i32
rlli Return long long integer i64
rbui Return byte unsigned integer u8
rsui Return short unsigned integer u16
rlui Return long unsigned integer u32
rllui Return long long unsigned integer u64
rlf Return long float f32
rllf Return long long float f64
rs Return string
Type Description
i8 8-bit integer
i16 16-bit integer
i32 32-bit integer
i64 64-bit integer
u8 8-bit unsigned integer
u16 16-bit unsigned integer
u32 32-bit unsigned integer
u64 64-bit unsigned integer
f32 32-bit float
f64 64-bit float

About

My high-level programming language with the syntax of assembly

Topics

Resources

Stars

Watchers

Forks