Skip to content

Instantly share code, notes, and snippets.

@antonijn
antonijn / dtoa.java
Last active August 29, 2015 13:57
dtoa
private static String ltoa(long l, int bas) {
bool sign = l < 0;
if (sign) {
l = -l;
}
int digits;
int neg = 1;
for (digits = 0; l >= neg; ++digits) {
neg *= bas;
[bits 16]
org 0x100
main:
mov ah, 0x0f
int 0x10 ; get video mode
push ax ; store vid mode
mov ah, 0x00
mov al, 0x13
@antonijn
antonijn / strlen.asm
Last active August 29, 2015 13:57
strlen function using cdecl in x86-16
strlen:
push bp
mov bp, sp
mov si, 0
.rep:
mov ax, [bp + si + 4]
test ax, ax
jz .break
inc si
jmp .rep
;
; runtime.ll
;
; The libaquastd interface for the aqua runtime services.
;
%rt._Unwind_Exception = type { [4 x i8], void (sysint, %rt._Unwind_Exception*) *, i64, i64 }
declare sysint @_Unwind_RaiseException(%rt._Unwind_Exception* %ex) noreturn
@antonijn
antonijn / main.asm
Last active August 29, 2015 13:58
What code compiled by FACC might look like (FAC-syntax)
global main
main:
push bp
mov bp, sp
sub sp, 2
mov word [ss:bp - 2], 0
.for0.start:
cmp word [ss:bp - 2], 10
jnl .for0.break
@antonijn
antonijn / gist:10529342
Created April 12, 2014 10:40
Compiler Structure?
Expression
ConstantExpression
Literal
IntLiteral
LongLiteral
FloatLiteral
DoubleLiteral
BooleanLiteral
CharLiteral
StringLiteral
IDEA
2D Top-down simcity-stronghold crusader-like sandbox game
You have to build and maintain a town beneath the surface.
Materials:
- Wood (building, fuel)
- Stone (building)
- Gold (currency)
/*
* Multiplies two 32-bit numbers on 8086.
*/
long _stdcall _mul32(int highr, int lowr, int highl, int lowl)
{
asm {
; a = lowl * lowr
mov ax, [bp + 6] ; lowl
mul word [bp + 10] ; lowr
@antonijn
antonijn / euler15.hs
Created May 23, 2014 21:03
Euler problem 15
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe (Maybe)
import qualified Data.Maybe as Maybe
lattice :: Int -> Int -> Int
lattice x y = fst (latticeI Map.empty x y)
where
latticeI m a 1 = (a, m)
@antonijn
antonijn / readType.hs
Last active August 29, 2015 14:02
Read any C type from a [Token] token stream
-- File parsing hub, providing an interface to the parsers and other
-- helper functions to be used by other parsers.
-- Copyright (C) 2014 Antonie Blom
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
module Compiler.Parser where