Today has been quite a busy day, I’ve been playing around with the GNU AS assembler, it took me quite a while to figure it out as I’m not used to the AT&T syntax. Personally I prefer the Intel syntax over AT&T, but as the AT&T syntax is used in C inline it’s well worth learning.
Here is a simple ‘Hello World’ program written for GAS and Linux
.text
.global _start
_start:
nop # Breakpoint for GDB
movl $4,%eax
movl $1,%ebx
movl $msg,%ecx
movl $13,%edx
int $0x80
movl $0,%ebx
movl $1,%eax
int $0x80
ret
.data
msg:
.string "Hello World!\n"
EAX = 4 is the SYS_WRITE call, with EBX being STDIN, ECX being the memory address of msg, and finally EDX being the msg length.
EAX = 1 is SYS_EXIT, EBX being the return value.
Now here it is in Intel syntax using NASM, again for Linux.
section .text
global _start
_start:
nop
mov eax,0x4
mov ebx,0x1
mov ecx,msg
mov edx,len
int 0x80
mov eax,0x1
mov ebx,0x0
int 0x80
section .data
msg db 'Hello World!',0xA
len equ $-msg
Well that’s all for now, I’m going to work on a little boot loader now.
Posted by chryseus8086