Skip to content

Instantly share code, notes, and snippets.

@cbarrett
Created November 30, 2009 23:05
Show Gist options
  • Save cbarrett/245856 to your computer and use it in GitHub Desktop.
Save cbarrett/245856 to your computer and use it in GitHub Desktop.
I'm going through the Crenshaw tutorial http://compilers.iecc.com/crenshaw/ but translating from TurboPascal/68K to Python/x86. I've only just begun: I just finished the second section of the tutorial, but I have found this helpful. Works on Snow Leopard
#!/bin/sh
# (c) 2009 Colin Barrett <colin@springsandstruts.com>
# MIT Licensed.
echo ' .cstring
format_string:
.asciz "Result: %d\\n"
.text
.globl _main
_main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
' > temp.s
cat /dev/stdin | python cradle2.py > tempOutput
cat tempOutput >> temp.s
echo '
movl %eax, 4(%esp)
call _nextInstructionAddress
myAnchorPoint:
leal format_string-myAnchorPoint(%ebx), %eax
movl %eax, (%esp)
call _printf
leave
ret
_nextInstructionAddress:
movl (%esp), %ebx
ret' >> temp.s
if [[ $1 == "--full" ]]
then
cat temp.s
else
cat tempOutput
fi
gcc temp.s
if [[ $1 != "--no-run" ]]
rm -rf temp.s
rm -rf tempOutput
then
./a.out
rm -rf a.out
rm -rf temp.s
rm -rf tempOutput
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment