GithubHelp home page GithubHelp logo

xtrm-en / construct Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thomas-de-bock/construct

0.0 0.0 0.0 86 KB

Compiler for an x86 Assembly language abstracting over NASM

License: MIT License

C++ 98.69% Makefile 0.52% C 0.79%

construct's Introduction

About

Construct is an abstraction over x86 NASM Assembly. It adds features such as while loops, if statements, scoped macros, simpler function-call syntax and more. It currently supports 64, 32, 16 and 8 bit modes.

Syntax

Construct is indent sentitive and requires all indentations to use the tab character. Below is a code example:

extern printf

section .text
function strlwr(str):
	while byte[str] ne 0:
		if byte[str] ge 65:
			if byte[str] le 90:
				!crntchr sil
				mov crntchr, byte[str]
				add crntchr, 32
				mov byte[str], crntchr
		inc str


function main():
	call strlwr(teststring)

	mov rax, 0
	call printf(fmt, teststring)

	mov rax, 60
	syscall

section .data
teststring db "HeLlO WoRlD", 0
fmt: db "%s", 10, 0
  • Sections: Sections do not add any indentation, construct currently supports text, data and bss sections.
  • While loops: While loops take a single conditional statement
  • If statements: If statements, like while loops, take a single conditional statement
  • Functions: Functions are declared with the "function" keyword, a "ret" instruction is added to functions in post-processing, so functions will not flow into eachother.
  • Function calls: Functions can be called with any number of arguments, independent of the function decleration. If the amount of arguments used to call a function is more than its decleration states, they can be accessed like normal with their respective registers / stack address. Construct function calls, like NASM, use the "call" keyword. Functions can still be called without parentheses or arguments, NASM-style.
  • Macros: Construct macros can only be used in their respective scopes. Construct macros are declared with the '!' character and cannot contain whitespaces.

Any NASM code can still be used in your construct programs.

Conditionals

Using the naming of the conditional jump instructions, construct supports the following comparisons:

  • e: equals
  • ne: not equals
  • l: less
  • g: greater
  • le: less or equal
  • ge: greater or equal

Neither side of the comparison can contains whitespaces.

Use

Required flags

  • -f (format): Can be either "elf64", "elf32", "elf16", "elf8" and decides the registers used for funcion calls.
  • -i (input file): Specifies the input file to be compiled (-i is not neccesary)

construct's People

Contributors

thomas-de-bock 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.