Assembly sanity check

Programming, for all ages and all languages.
Post Reply
rbmj
Posts: 11
Joined: Tue Jan 13, 2009 4:24 pm

Assembly sanity check

Post 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
rbmj
Posts: 11
Joined: Tue Jan 13, 2009 4:24 pm

Re: Assembly sanity check

Post by rbmj »

Should I also then use inline assembler for lxdt, manipulating crx, and pretty much everything except kernel interrupts?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Assembly sanity check

Post 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?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Fanael
Member
Member
Posts: 38
Joined: Fri Oct 16, 2009 9:20 am

Re: Assembly sanity check

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Assembly sanity check

Post by Combuster »

And doubled be the work to do. Should I keep posting counterarguments for people that only post advantages? :roll:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Fanael
Member
Member
Posts: 38
Joined: Fri Oct 16, 2009 9:20 am

Re: Assembly sanity check

Post 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.
Post Reply