• Advertisement

Archived

This topic is now archived and is closed to further replies.

In line assembly to Get Time?

This topic is 5496 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can I in line assembly in C to get a time difference? How do I compile such thing? Thank you all (crazy!) assembly programmers!

Share this post


Link to post
Share on other sites
Advertisement
Inline assembly was built into many C compilers to make optimisations to your code easy to do. Instead of using modules of assembly and having to interface them to your C code, compilers like Microsoft C, Turbo C, and many more of the newer compilers have implemented the non-standard keyword asm. To use the asm keyword is using assembly code inline, as you said. It's simple to do, and much less complex than coding an interface. The keyword asm is implemented like such:


function(){
asm assembly_here
asm assembly_here
asm assembly_here
}
// Or the asm keyword can act as a line break, and the above is equivilent to:
function(){
asm assmebly_here asm assembly_here asm assembly_here
}
// Or the asm keyword can be the header of a block of assembler code, the following is equilvilent the former:
function(){
asm{
assembly_here
assembly_here
assembly_here
}


It's good to use inline assembly when only absolutely necessary. For instance, you wouldn't want to code a function that's only called once, in assembly. But, if a function is iterated thosands of times, you will notice a considerable amount of speed increase in your program if you code that function in assembly. You may find that certain operations are more time consuming than others. take multiplication; it's slower than addition, but is necessary sometimes.

EDIT: To use the asm keyword specific to your compiler, look in your compilers help contents for the word and see how it's used, or to see it's written syntax. Some compilers like mine, Dev Studio C++, likes asm written as _asm or __asm.

[edited by - Californium on February 2, 2003 11:20:37 PM]

Share this post


Link to post
Share on other sites
Californium gave you a nice review of inline assembly language, but as far as I can tell that''s not what you''re asking for. Looking at your other thread I see that you want the inline assembly code to change the system''s timer resolution to something higher that 18.6 Hz in Dos. I don''t know how to do this but there is code in the book "Learn Game Programming in 21 days." This is a very old book about dos game programming and it''s probably out of print, so I''m not sure how you would get a copy. I would post the code if I had the book with me now but unfortuanately I don''t. My best advice is to search for it on google, it shouldn''t be too hard to find.

Share this post


Link to post
Share on other sites
Thanks Californium for the review and Impossible for keeping track of my questions.
I''ll check it all up.
See ya!

Share this post


Link to post
Share on other sites

  • Advertisement