Page 1 of 1

Assembly sanity check

Posted: Mon May 09, 2011 6:59 pm
by rbmj
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 :D)

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

Re: Assembly sanity check

Posted: Tue May 10, 2011 12:41 pm
by rbmj
Should I also then use inline assembler for lxdt, manipulating crx, and pretty much everything except kernel interrupts?

Re: Assembly sanity check

Posted: Tue May 10, 2011 12:52 pm
by Combuster
Berkus is looking for a few more cycles around extremely slow or rare operations (the difference in code around the out costs like 0-1% of the out itself). In exchange for that marginal advantage he loses the compiler-independence dedicated assembly has which you may or may not care about. The extra percents are his choice, portability is mine. What will yours be?

Re: Assembly sanity check

Posted: Wed May 11, 2011 8:43 am
by Fanael
Combuster wrote:In exchange for that marginal advantage he loses the compiler-independence dedicated assembly has
No, he doesn't lose that. If he wants to support other compilers, he can put an #ifdef around the code specific to one compiler and still provide a generic implementation for other compilers.

Re: Assembly sanity check

Posted: Wed May 11, 2011 8:46 am
by Combuster
And doubled be the work to do. Should I keep posting counterarguments for people that only post advantages? :roll:

Re: Assembly sanity check

Posted: Wed May 11, 2011 9:57 am
by Fanael
Combuster wrote:And doubled be the work to do.
In this case (in majority of cases, actually) doing that wouldn't buy much, but in cases where efficiency is everything, well, efficiency is everything. I think I should've pointed this out in the original post.