Hacker News new | ask | show | jobs
by exikyut 3194 days ago
Hmm, interesting.

I've had a look at the examples that come with fasm, which are invaluable.

But I completely forgot to point out (I knew I was forgetting something!) in my previous comment that I'm actually looking for info on 32-bit assembly programming. My motivation comes from the fact that a) a lot of my systems are 32-bit (such as the ThinkPad T43 I'm using to type this), due to circumstances I cannot change; and b) because (as I discovered to my delight) a program written for i386 and statically linked (eg, by fasm's ELF writer) will run on x86_64 without 32-bit glibc/userspace/anything! This makes perfect sense, but is an absolute winner for me for the kinds of things I'm going to want to make.

So x86_64 is in the "it would be monumentally stupid not to learn it" category, and I'm looking forward to doing so, but I'd have to do some seriously inelegant wrangling (something like qemu-x86_64 + 64-bit userspace - on a 32-bit machine, lolol) to actually work with it at this point.

The syscall table you made is very similar to HeavyThing's, heh. I've actually been researching precisely that of late; you most likely generated your copy from https://github.com/torvalds/linux/blob/master/arch/x86/entry.... I of course want https://github.com/torvalds/linux/blob/master/arch/x86/entry....

1 comments

amd64 is just an extension on x86. I took the (64bit) syscalls from a kernel header, that i can't find now, so you can take from that header you found.

C calling convention for x86 is to push everything on the stack (and use call, that is short for "push instruction pointer and jmp", ret being the reverse), while the linux kernel uses a variant of fastcall (aka put stuff in registers (then use int 80)).

When i was learning i found a lot of x86 examples and tutorials (and a book, can't remember the name (is free)), and not much on amd64.

Just play with it, it'l get easy when you go over the wall.

With "normal" C calling convention you have to care about the stack pointer (esp) (i think it's the callee's responsibility (of the called function)), maybe even the bottom pointer (ebp) (i remember the wikipedia page on calling conventions explains it). The other difference between x86 and amd64 is floating point math, where sse is the default on amd64 and x87 on x86 (x87 works on stacks of numbers, the reverse-polish using a stack way IIRC).

Useful tools are: objdump -d ("-M intel" for the intel notation), strace to trace system calls, and fdbg since GDB can't make sense of a valid ELF file. You can also join the flat assembler and/or nasm forums. I like fasm better then nasm for no strong reason, but nasm is a bit easier.

glhf