A simple assembly- and brainfuck-inspired stack-based language

Overview

asm-stackfuck

A simple assembly- and brainfuck-inspired stack-based language.

The language has a few goals:

  • Be stack-based
  • Look like assembly
  • Have a similar token set to brainfuck

Tokens

push 
   
     ; pushes an integer to the stack
add        ; pushes the sum of the last two elements on the stack
sub        ; pushes the difference of the last two elements on the stack, also sets relevant flags
cmp        ; sets the zero flag as if it had subtracted, but doesn't actually perform subtraction
dup        ; duplicates the top of the stack
swap       ; swaps the top two elements on the stack
rotr       ; rotates top three elements right
rotl       ; same but to the left
in         ; pushes a single character of user input
out        ; outputs top element of stack as char
jnz @
   
  
; jumps to section if zero flag set with `cmp` or `sub` is not active jz @
; jumps to section if zero flag is active jmp @
; jumps to section

Sections

Pretty sure assembly calls them labels. They label a part of the program. The program requires a label called _start. Lets you do:

_start:
  push 64
  
loop:
  push 1
  add
  
  dup
  out
  
  dup
  push 90
  cmp
  jnz @loop
  
  push 10
  out

Which is a program that prints the ascii characters 'A' - 'Z'. Note how references to sections in jump statements are prepended with an @ character.

Compiling and running

The compiler is written in Python. Simply do

chmod +x ./stackfuck.py
./stackfuck.py 
   
    
nasm -f elf output.asm
ldd -m elf_i386 -s -o output output.o
./output

   

Try compiling and running the programs in examples/ to see how it works.

You might also like...
These are the scripts used for the project of ‘Assembly of a pan-genome for global cattle reveals missing sequence and novel structural variation, providing new insights into their diversity and evolution history’

script-SV-genotyping These are the scripts used for the project of ‘Assembly of a pan-genome for global cattle reveals missing sequence and novel stru

pythonOS: An operating system kernel made in python and assembly
pythonOS: An operating system kernel made in python and assembly

pythonOS An operating system kernel made in python and assembly Wait what? It uses a custom compiler called snek that implements a part of python3.9 (

Snek-test - An operating system kernel made in python and assembly
Snek-test - An operating system kernel made in python and assembly

pythonOS An operating system kernel made in python and assembly Wait what? It us

Assembly example for CadQuery
Assembly example for CadQuery

Spindle and vacuum attachment This is a model of the vacuum attachment for my Workbee CNC router. There is a mist spray coming from the left hand side

My Analysis of the VC4 Assembly Code from the RPI4

My Analysis of the VC4 Assembly Code from the RPI4

51AC8 is a stack based golfing / esolang that I am trying to make.

51AC8 is a stack based golfing / esolang that I am trying to make.

vFuzzer is a tool developed for fuzzing buffer overflows, For now, It can be used for fuzzing plain vanilla stack based buffer overflows
vFuzzer is a tool developed for fuzzing buffer overflows, For now, It can be used for fuzzing plain vanilla stack based buffer overflows

vFuzzer vFuzzer is a tool developed for fuzzing buffer overflows, For now, It can be used for fuzzing plain vanilla stack based buffer overflows, The

edgetest is a tox-inspired python library that will loop through your project's dependencies, and check if your project is compatible with the latest version of each dependency

Bleeding edge dependency testing Full Documentation edgetest is a tox-inspired python library that will loop through your project's dependencies, and

Paprika is a python library that reduces boilerplate. Heavily inspired by Project Lombok.
Paprika is a python library that reduces boilerplate. Heavily inspired by Project Lombok.

Image courtesy of Anna Quaglia (Photographer) Paprika Paprika is a python library that reduces boilerplate. It is heavily inspired by Project Lombok.

Owner
Nils Trinity
I make shitty programs
Nils Trinity
MindF**k it's a programming language as BrainFuck, but with some cool features.

MindF**k Description MindF**k it's a programming language as BrainFuck, but with some cool features. Symbol What does symbol mean > Next slot < Previo

tixcode 0 Jun 15, 2022
An implementation of an interpreter for the Brainfuck esoteric language in Python

Brainfuck Interpreter in Python An implementation of an interpreter for the Brainfuck esoteric language in Python. ?? The Brainfuck Language Created i

Carlos Santos 0 Feb 1, 2022
Simple python code for compile brainfuck program.

py-brainf*ck Just a basic compiled that compiles your brainf*ck codes and gives you informations about memory, used cells, dumped version, logs etc...

null 4 Jun 13, 2021
Encode and decode cancro lang files to and from brainfuck

cancrolang Encode and decode cancro lang files to and from brainfuck. examples python3 main.py -f hello.cancro --run Hello World! the interpreter is n

witer33 1 Dec 20, 2021
One line Brainfuck interpreter in Python

One line Brainfuck interpreter in Python

null 16 Dec 21, 2022
A Brainfuck interpreter written in Python.

A Brainfuck interpreter written in Python.

Ethan Evans 1 Dec 5, 2021
Would upload anything I do with/related to brainfuck

My Brainfu*k Repo Basically wanted to create something with Brainfu*k but realized that with the smol brain I have, I need to see the cell values real

Rafeed 1 Mar 22, 2022
Plock : A stack based programming language

Plock : A stack based programming language

null 1 Oct 25, 2021
jonny is a stack based programming language

jonny-lang jonny is a stack based programming language also compiling jonny files currently doesnt work on windows you can probably compile jonny file

null 1 Nov 24, 2021
Morth - Stack Based Programming Language

Morth WARNING! THIS LANGUAGE IS A WORKING PROGRESS. THIS IS JUST A HOBBY PROJECT

Dominik Danner 2 Mar 5, 2022