Name: Anonymous 2010-07-20 8:24
7kb of code for hello world?
.00401016: 55 push ebp
.00401017: 8BEC mov ebp,esp
.00401019: 6808104000 push 000401008 ;'Hello world!' --↑1
.0040101E: FF1500104000 call printf
.00401024: 59 pop ecx
.00401025: 33C0 xor eax,eax
.00401027: 5D pop ebp
.00401028: C3 retn
.00401029: CC int 3
.0040102A: CC int 3
.0040102B: CC int 3
[code]
So you have the function prologue/epilogue (can be eliminated by increasing optimization settings, /Ox should do the trick:
[code]
00401016: 6808104000 push 00401008 ;'Hello world!' --↑1
0040101B: FF1500104000 call printf
00401021: 59 pop ecx
00401022: 33C0 xor eax,eax
00401024: C3 retn)
Application starts with top of stack looking like:
0012FFC4 7C816FD7 RETURN to kernel32.7C816FD7
7C816FD7 50 PUSH EAX
7C816FD8 E8 7B50FFFF CALL kernel32.ExitThread), so you'd get the expected results (it also places a SEH handler and some other useful things), but it doesn't have to do any of that(it's undocumented behaviour), so a compliant Win32 application should call ExitProcess or ExitThread when they need to exit (or do it portably through libc).
#include <stdio.h>
int main(void){ return puts("Hello, World!"); }
"GRUNNUR"
% ghc -O --make -dynamic Hello.hs -o Hello
[1 of 1] Compiling Main ( Hello.hs, Hello.o )
Linking Hello ...
% du -h Hello
24K Hello
section .data
output db "Hello",10
olen equ $ - output
section .text
global _start
_start:
xor rax,rax
inc rax
mov rdi,rax
mov rsi,output
mov rdx,olen
syscall
mov rax,60
mov rdi,0
syscalldu -hAB1
.comm environ, 0
.comm __progname, 0
hello: .string "Hello, World!"
.globl _start
_start:
pushl $hello
call puts
call exit
section .text
global _start
_start:
mov eax, 0x4
mov ebx, 0x1
mov ecx, msg
mov edx, 0xF
int 0x80
mov eax, 0x1
mov ebx, 0x0
int 0x80
section .data
msg: dw "Hello, world!", 0xa
_________________________________________
/ Assembles and links to 364 bytes. Maybe \
\ you guys are doing something wrong! /
-----------------------------------------
\
\
,;;;;;;;,
;;;;;;;;;;;,
;;;;;'_____;'
;;;(/))))|((\
_;;((((((|))))
/ |_\\\\\\\\\\\\
.--~( \ ~))))))))))))
/ \ `\-(((((((((((\\
| | `\ ) |\ /|)
| | `. _/ \_____/ |
| , `\~ /
| \ \ /
| `. `\| /
| ~- `\ /
\____~._/~ -_, (\
|-----|\ \ ';;
| | :;;;' \
| / | |
| | |
xchg bp, ax
mov dx, .msg
int 21h
ret
msg:
db "Hello world!$" ______________________________________
(>>69 still uses DOS 16-bit registers )
( and int 21h![code] )