OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 8:24 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Invalid asm in example for PIT in wiki?
PostPosted: Wed Jul 27, 2022 5:38 pm 
Offline
Member
Member

Joined: Sun May 08, 2022 2:10 am
Posts: 70
In the OSDev Wiki Page for the PIT, the code for the "TimerIRQ" part appears to be invalid. When I tried compiling it in nasm (to see it in the more familiar GAS syntax), it gives an error about the line:
Code:
or eax, or eax ; quick way to compare to 0

Does anyone know if I'm missing something (wrong assembler maybe?) Or is this just supposed to be psuedocode or something?


Top
 Profile  
 
 Post subject: Re: Invalid asm in example for PIT in wiki?
PostPosted: Wed Jul 27, 2022 6:28 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
It's a typo. It's supposed to be "or eax, eax".

There are other problems besides typos. The sleep function doesn't need to disable interrupts, and should use HLT or yield for other tasks to run instead of that incredibly wasteful NOP loop. (I'd argue it shouldn't be written in assembly in the first place - using assembly makes it more difficult to understand what the code is doing.)


Top
 Profile  
 
 Post subject: Re: Invalid asm in example for PIT in wiki?
PostPosted: Wed Jul 27, 2022 8:32 pm 
Offline
Member
Member

Joined: Sun May 08, 2022 2:10 am
Posts: 70
Octocontrabass wrote:
It's a typo. It's supposed to be "or eax, eax".

There are other problems besides typos. The sleep function doesn't need to disable interrupts, and should use HLT or yield for other tasks to run instead of that incredibly wasteful NOP loop. (I'd argue it shouldn't be written in assembly in the first place - using assembly makes it more difficult to understand what the code is doing.)

Alright, I'll see if it works.
I agree, however it being written in assembly does make it fast. Also I replaced the nops with the io wait assembly example (basically just send a 0 to io port 0x80 to waste a few microseconds)


Top
 Profile  
 
 Post subject: Re: Invalid asm in example for PIT in wiki?
PostPosted: Wed Jul 27, 2022 9:15 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Techflash wrote:
it being written in assembly does make it fast

Modern compilers usually beat hand-written assembly for speed, and they let you optimize for different CPUs without changing your code.

Even in this example code there's obvious room for improvement: the "or eax, eax" instruction causes a false dependency.

Techflash wrote:
Also I replaced the nops with the io wait assembly example

That still doesn't wait for long enough. You should use HLT instead.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 55 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group