Skip to content

Instantly share code, notes, and snippets.

/*
* 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
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)
@antonijn
antonijn / gist:10529342
Created April 12, 2014 10:40
Compiler Structure?
Expression
ConstantExpression
Literal
IntLiteral
LongLiteral
FloatLiteral
DoubleLiteral
BooleanLiteral
CharLiteral
StringLiteral
@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
;
; 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 / 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
[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 / 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;
@antonijn
antonijn / MainClass.java
Created March 16, 2014 10:41
Only two heap-allocations! Not bad!
private static void foo() {
byte b = 10;
short s = 10;
void() f = void () s = b;
void(int) g = void (int a) a = b;
}
private static void bar() {
final int x = 10;
void(int) f = void (int a) a = x;
@antonijn
antonijn / MainClass.java
Last active August 29, 2015 13:57
Subtle differences
private static void foo() {
int x = 10;
void(int) f = void (int a) a = x;
}
private static void bar() {
final int x = 10;
void(int) f = void (int a) a = x;
}