I'm writing a compiler and I have gone through all the steps (tokenizing, parsing, syntax tree structures, etc.) that they show you in all the compiler books. (Please don't comment with the link to the "Resources for writing a compiler" question!).
I have chosen to use NASM together with alink as my backend.
Now my problem is: I just can't find any good resources for learning NASM and assembly in general.
The wikibook (german) on x86 assembly is horrible. They don't even explain the code they write there, I currently can't even get simple things like adding 1 to 2 and outputting the result working.
The current most popular are ARM, MIPS, and x86. ARM is used on lots of cell phones and many embedded systems. MIPS is popular on IBM CPUs and is found on systems such as Macs, some video game consoles, and a few I'm sure I'm missing. x86 assembler is used on Intel PCs.
The difference between compiler and assembler is that a compiler is used to convert high-level programming language code into machine language code. On the other hand, an assembler converts assembly level language code into machine language code.
Better Understanding of Architecture Issues Learning and spending some time working at the assembly language level provides a richer understanding of the underlying computer architecture. This includes the basic instruction set, processor registers, memory addressing, hardware interfacing, and Input/ Output.
On average the compiler will do far better than a human for a large project, but it is not hard in a decent sized project to find performance issues in the compiled code. Actually, the short answer is: Assembler is always faster or equal to the speed of C.
Unless you've checked it out, NASM manual is quite good resource for learning about NASM: http://www.nasm.us/doc/
Comparison of NASM and GAS also helps out a bit: http://www.ibm.com/developerworks/linux/library/l-gas-nasm.html
irc channel #asm at Freenode se(r)ver provides these links:
I also devoted some time to mash up a little hello world up for you:
bits 32
section .data
greeting db "hello world", 10
section .text
global _start
_start:
mov eax, 4 ; sys_write
mov ebx, 1 ; stdout
mov ecx, greeting
mov edx, 12 ; greeting.length
int 0x80 ; system call interrupt
mov eax, 1 ; sys_exit
mov ebx, 0
int 0x80
Assemble this with:
nasm -f elf -o example.o example.asm
ld -o example example.o -melf_i386
I've myself written a small code generator in python. Though I left that thing in middle while ago. Recently I've written some bit different tool that might become useful for anyone tackling with assembly. Right now I'm also asking some help.. Except seems I have to do some self-help there: x86 instruction encoding tables
The old code generator piece I've got is in http://bitbucket.org/cheery/g386/ until I'll get my new table-based code generator up and running.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With