Skip to content

Instantly share code, notes, and snippets.

@tuttlem
tuttlem / gist:4138799
Created November 24, 2012 07:36
Smoke - Average
bloom:
mov cx, 63680 ; we average every pixel except the top row
mov di, 320 ; we start at the 2nd row
next_avg:
xor ax, ax ; clear out our accumulator
mov al, es:[di] ; get the current pixel
@tuttlem
tuttlem / gist:4142080
Created November 25, 2012 01:55
Add program - C
#include <stdio.h>
/** Forward declaration for our add function */
int add(int, int);
int main() {
/* add some numbers */
int x = add(5, 4);
@tuttlem
tuttlem / gist:4142091
Created November 25, 2012 01:57
Add program - Assembly
global add
section .text
add:
mov eax, [esp+4] ; get the 1st param
mov ecx, [esp+8] ; get the 2nd param
add eax, ecx ; add them together
; leaving the return value in eax
@tuttlem
tuttlem / gist:4142093
Created November 25, 2012 01:59
Add program - Compilation
gcc -m32 -c -g add.c -o add.o
nasm -felf32 maths.asm -o maths.o
gcc -m32 add.o maths.o -o add
@tuttlem
tuttlem / gist:4142177
Created November 25, 2012 02:38
Compile with debug info (GCC)
$ gcc -g test.c -o test
@tuttlem
tuttlem / gist:4142385
Created November 25, 2012 04:22
GDB: Load executable
$ gdb test
@tuttlem
tuttlem / gist:4147906
Created November 26, 2012 12:14
Simple Window - New Macros
; copies data from one memory location to another
m2m MACRO M1, M2
push M2
pop M1
ENDM
; syntactic sugar for returning a value
return MACRO arg
mov eax, arg
ret
@tuttlem
tuttlem / gist:4147911
Created November 26, 2012 12:15
Simple Window - Register Window Class
LOCAL wc :WNDCLASSEX
szText szClassName, "SimpleWindow32"
; fill out the WNDCLASSEX structure here
mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
mov wc.lpfnWndProc, offset WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
@tuttlem
tuttlem / gist:4147919
Created November 26, 2012 12:18
Simple Window - Create window
; create the window
invoke CreateWindowEx, WS_EX_OVERLAPPEDWINDOW,
ADDR szClassName,
ADDR szDisplayName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInst, NULL
; save off the window handle
@tuttlem
tuttlem / gist:4147927
Created November 26, 2012 12:20
Simple Window - Window Proc
WndProc PROC hWin :DWORD,
uMsg :DWORD,
wParam :DWORD,
lParam :DWORD
.if uMsg == WM_CLOSE
.elseif uMsg == WM_DESTROY
invoke PostQuitMessage, NULL
return 0