OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Sep 30, 2020 8:04 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Inline (was Buffer not filled while reading disk)
PostPosted: Mon Feb 24, 2020 11:54 am 
Offline
Member
Member
User avatar

Joined: Fri Nov 22, 2019 5:46 am
Posts: 338
In the other thread (" Buffer not filled while reading disk...") we were talking about operating with CPU registers in inline asm.

Octocontrabass wrote:
This is handled by the constraints in the inline assembly. You can read about it in the GCC manual.

psimonson1988 wrote:
Oh by the way, "a"(val), "b"(buffer), "c"((c << 8) | s), "d"((h << 8) | p->drive) is how you set ax, bx, cx, and dx in GNU inline assembly. Just in case you didn't know.

Woooah! That's both too sophisticated for me! I think I stick to Nasm and C, neatly separated...

But ok, I give it a try:
"a"(0x0201), "b"(buffer) etc. where buffer is the variable name for the buffer. Would that be correct?
Edit: I think it must be "a"($0x0201)

But I don't understand the constraints from the GCC manual. Any chnace there's a more easy to understand text about it?

Next thing to learn for me is Git. I hope I can understand at least that. I will get two books about it from the library.

_________________
https://wiki.osdev.org/User:PeterX


Top
 Profile  
 
 Post subject: Re: Inline (was Buffer not filled while reading disk)
PostPosted: Mon Feb 24, 2020 12:36 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 2330
PeterX wrote:
But I don't understand the constraints from the GCC manual. Any chnace there's a more easy to understand text about it?

This page on the wiki might help.

Constraints are the letters inside the quotation marks that tell the compiler where the input or output may be located. To use the quoted code as an example, the "a" and "b" are constraints. The "a" tells the compiler to use AL or AX or EAX for the operand, chosen depending on the operand size. The "b" constraint does the same thing, but for BL/BX/EBX. There are constraints for all kinds of registers, memory references, and immediate values.

The part inside the parentheses is the C expression that describes the input or output. So, for example, an input operand specified as "a"(0x0201) tells the compiler to put the value 0x201 into EAX before running the inline assembly code. (Why EAX instead of AX? In C, integer literals are of type int by default.)

GCC's inline assembly is notoriously difficult, so it's not a good idea to use it if you're not entirely certain it will work how you want.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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