Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 20bb553
Showing
5 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
*.o | |||
*.bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
NASM=/usr/local/bin/nasm | |||
LD=ld | |||
|
|||
all: hello_world.bin hello_world64.bin | |||
|
|||
hello_world.o: | |||
$(NASM) -f macho hello_world.asm | |||
hello_world.bin: hello_world.o | |||
$(LD) -e main -macosx_version_min 10.7.0 -lSystem -o hello_world.bin hello_world.o | |||
|
|||
hello_world64.o: | |||
$(NASM) -f macho64 hello_world64.asm | |||
hello_world64.bin: hello_world64.o | |||
$(LD) -e main -macosx_version_min 10.7.0 -lSystem -o hello_world64.bin hello_world64.o | |||
|
|||
clean: | |||
rm -f *.o | |||
rm -f *.bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
# Hello World in NASM assembly for OS X (32 & 64 bit) | |||
|
|||
I won't promise this is done "the right way" (tm), I've never really | |||
used assembly but wanted to play around with it some. | |||
Everything seems to work under OS X Lion. | |||
|
|||
To assemble the 64 bit version you'll need to build your own nasm (use | |||
homebrew). | |||
|
|||
## Thanks | |||
These, among other sources, where helpful: | |||
* http://thexploit.com/secdev/mac-os-x-64-bit-assembly-system-calls/ | |||
* http://www.x86-64.org/documentation/abi.pdf | |||
* http://michaux.ca/articles/assembly-hello-world-for-os-x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
SECTION .data | |||
msg: db "Hello World!", 0x0a | |||
len: equ $-msg | |||
|
|||
SECTION .text | |||
global main | |||
|
|||
kernel: | |||
int 0x80 | |||
ret | |||
|
|||
main: | |||
mov eax, 4 ; SYS_write | |||
push dword len | |||
push dword msg | |||
push dword 1 ; stdout | |||
call kernel | |||
add esp, 12 | |||
push dword 0 | |||
mov eax, 1 | |||
call kernel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
SECTION .data | |||
msg: db "Hello World!", 0x0a | |||
len: equ $-msg | |||
|
|||
SECTION .text | |||
global main | |||
|
|||
kernel: | |||
syscall | |||
ret | |||
|
|||
main: | |||
mov rax, 0x2000004 ; SYS_write | |||
mov rdi, 1 | |||
mov rsi, msg | |||
mov rdx, len | |||
call kernel | |||
mov rax, 0x2000001 | |||
mov rdi, 0 | |||
call kernel |