Assembly sanity check
Posted: Mon May 09, 2011 6:59 pm
I'm new to os development, and have relatively extensive experience in C, but not very much in assembler. I personally hate inline assembler code (I'd much prefer to have it all in separate files), and just need to make sure i'm not going to blow something up with my inx/outx code. I don't really get the whole prelude thing, as I don't understand why one wouldn't just use offsets from esp instead of worrying about another pointer.
So here's the code (I'm using clang, which is gnu as compatible I think- well it compiles it all, at least )
So here's the code (I'm using clang, which is gnu as compatible I think- well it compiles it all, at least )
Code: Select all
.code32
.intel_syntax noprefix
.section .text
.globl io_wait
io_wait:
xor eax, eax
//this port is apparantly open cf linux :)
out 0x80, al
ret
.globl outb
outb:
mov al, byte ptr [esp+0x8]
mov dx, word ptr [esp+0xc]
out dx, al
ret
.globl outw
outw:
mov ax, word ptr [esp+0x8]
mov dx, word ptr [esp+0xc]
out dx, ax
ret
.globl outl
outl:
mov eax, dword ptr [esp+0x8]
mov dx, word ptr [esp+0xc]
out dx, ax
ret
.globl inb
inb:
mov dx, word ptr [esp+0x8]
in al, dx
ret
.globl inw
inw:
mov dx, word ptr [esp+0x8]
in ax, dx
ret
.globl inl
inl:
mov dx, word ptr [esp+0x8]
in eax, dx
ret