Reputation: 72975
I'd like to play with writing some assembly on my Mac, ideally native, but I'd understand if it's easier to learn in QEMU or something.
I see that there are different dialects of assembly depending on the processor - what dialect is the "best" to learn?
I don't really have any idea of where to start, any pointers as to how to even run a program in assembly?
Upvotes: 20
Views: 19479
Reputation: 21591
Get involved with communities that thrive in assembly code. The first that comes to mind is the demoscene. For one, check out the productions released for x86 Macs on pouet.net. Try getting in touch with some of the coders in the active groups. Some of them may be willing to share ideas and code and maybe even get you motivated to write your own.
This is how I got started back in the day, but on an Atari 8-bit.
Upvotes: 1
Reputation: 145
I learned MIPS and tested in SPIM for a class on "computer organization."
Not sure if this book will work, but it might be worth a shot. We used a "book" (more like a tutorial, and a cheatsheet really) written by the professor, so it's otherwise unavailable.
Upvotes: 0
Reputation: 143755
My suggestion is to act with the best assembler producer out there: gcc.
Write simple programs in C and then compile them with the -S switch. you will get a file.s containing the assembler code. Tinker with it and you will learn it. The best part is that if you want to learn a different assembler, you can just compile gcc as cross compiler, and produce assembler for any supported platform.
Remember to disable optimizations with -O0, otherwise you could find strange tricks.
This is hello world in assembler
.cstring
LC0:
.ascii "hello world!\0"
.text
.globl _main
_main:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $20, %esp
call L3
"L00000000001$pb":
L3:
popl %ebx
leal LC0-"L00000000001$pb"(%ebx), %eax
movl %eax, (%esp)
call L_puts$stub
movl $0, %eax
addl $20, %esp
popl %ebx
leave
ret
.section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5
L_puts$stub:
.indirect_symbol _puts
hlt ; hlt ; hlt ; hlt ; hlt
.subsections_via_symbols
Upvotes: 21
Reputation: 121
A few (OK many) years ago I picked up Peter Norton's book on Assembly http://www.amazon.com/Assembly-Language-Primer-Personal-Computer/dp/0136619010. It was a fantastic way to begin assembly programming for the PC. I wonder if you can still get this and use DOSbox to work through it.
Upvotes: 2
Reputation: 9806
Well even though it isn't what some people call the "best" assembly out there, I would recommend learning X86 / X86-64 as it is the most widely used. To run the program, you can simply use GCC to translate it into binary and then run it through your console.
Upvotes: 1