Skip to content

Instantly share code, notes, and snippets.

@fuxx
Created July 25, 2012 18:57
Show Gist options
  • Save fuxx/3177893 to your computer and use it in GitHub Desktop.
Save fuxx/3177893 to your computer and use it in GitHub Desktop.
Template files for NASM programs
; Executable name : %EXEC_NAME%
; Version : 1.0
; Created date : %CREATION_DATE%
; Author : Ish - StefanPopp.de
; Description
;
;
;
; Build using these commands:
; nasm -f elf -g -F stabs %EXEC_NAME%.asm
; ld -o %EXEC_NAME% %EXEC_NAME%.o
;
section .data ; Section containing initialized data
StringHello: db "Hello World!", 10
StringHelloLen: equ $-StringHello
section .bss ; Section containing uninitialized data
Buff resb 1
section .text ; section containing code
global _start ; Linker needs this to find the entry point
_start:
nop
mov eax, 4
mov ebx, 1
mov ecx, StringHello
mov edx, StringHelloLen
int 0x80
Exit: mov eax, 1 ; exit
mov ebx, 0 ; ret value 0
int 0x80 ; call kernel
nop
#!/bin/sh
EXPECTED_ARGS=1
E_BADARGS=65
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` program-name"
exit $E_BADARGS
fi
CURRENT=$(date)
mkdir $1
sed -e "s;%EXEC_NAME%;$1;g" -e "s;%CREATION_DATE%;$CURRENT;g" asm-template.txt > "$1/$1.asm"
sed -e "s;%EXEC_NAME%;$1;g" makefile-template.txt > "$1/makefile"
# be careful! dont use spaces for indentation! makefile requires tabs instead of spaces
%EXEC_NAME%: %EXEC_NAME%.o
ld -o %EXEC_NAME% %EXEC_NAME%.o
%EXEC_NAME%.o: %EXEC_NAME%.asm
nasm -f elf -g -F stabs %EXEC_NAME%.asm -l %EXEC_NAME%.lst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment