There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot browser bsod computer cpu crash css dell desktop driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware missing monitor network networking outlook outlook 2003 outlook 2007 outlook express password popups problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Solved: AT&T Inline Assembly


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
pcpro17's Avatar
Senior Member with 233 posts.
 
Join Date: Oct 2006
Location: Wisconsin, USA
Experience: Advanced
19-Dec-2006, 04:18 PM #1
Exclamation Solved: AT&T Inline Assembly
Hello. I'm trying to read the Cycle Counter register in an Intel Pentium processor. I'm trying to use gcc and AT&T inline assembly.

The Pentium assembly instruction RDTSC gets the 64-bit value in the cycle counter register and puts it in EAX (low 32-bits) and EDX (high 32-bits).

Can someone please verify for me that the following code will save this value properly?
Code:
   unsigned long      low_ticks;            // stores low-order cycle count
   unsigned long      high_ticks;           // stores high-order cycle count
 
   __asm( " push %eax" );
   __asm( " push %edx" );
   __asm( " rdtsc" : "=A" (low_ticks), "=D" (high_ticks) );
   __asm( " pop  %edx" );
   __asm( " pop  %eax" );
Thanks.
IMM's Avatar
IMM IMM is offline
Distinguished Member with 3,156 posts.
 
Join Date: Feb 2002
20-Dec-2006, 03:27 AM #2
anti-debugging ?
Chicon's Avatar
Computer Specs
Distinguished Member with 6,512 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
20-Dec-2006, 06:07 AM #3
Hi pcpro17,

In my opinion, if you're invoking an assembly routine from a C/C++ program, the push and pop instructions are not necessary.
You may simply use the following notation :

__asm__ volatile("rdtsc" : "=a" (low_ticks), "=d" (high_ticks));

Last edited by Chicon : 20-Dec-2006 06:15 AM.
pcpro17's Avatar
Senior Member with 233 posts.
 
Join Date: Oct 2006
Location: Wisconsin, USA
Experience: Advanced
20-Dec-2006, 09:29 AM #4
Quote:
Originally Posted by IMM
anti-debugging ?
No, I'm using gcc, so there's no built in debugger like the MS products.

Thanks for the tip, Chicon! I'll let you know how it works out.
pcpro17's Avatar
Senior Member with 233 posts.
 
Join Date: Oct 2006
Location: Wisconsin, USA
Experience: Advanced
20-Dec-2006, 11:41 AM #5
Quote:
Originally Posted by Chicon
Hi pcpro17,

In my opinion, if you're invoking an assembly routine from a C/C++ program, the push and pop instructions are not necessary.
You may simply use the following notation :

__asm__ volatile("rdtsc" : "=a" (low_ticks), "=d" (high_ticks));
Thanks! It worked wonderfully! Do you think the problem was with my asm statement "__asm" versus "__asm__ volatile" or in the capitalization of the "=A" and "=D"?
IMM's Avatar
IMM IMM is offline
Distinguished Member with 3,156 posts.
 
Join Date: Feb 2002
20-Dec-2006, 01:41 PM #6
Quote:
Originally Posted by pcpro17
No, I'm using gcc, so there's no built in debugger like the MS products.
Was actually wondering if you were looking for 0xffff in the register
Probably a bad guess on my part - but that instruction is sometimes used to detect the presence of a debugger and exit or similar.

Last edited by IMM : 20-Dec-2006 02:11 PM.
Chicon's Avatar
Computer Specs
Distinguished Member with 6,512 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
20-Dec-2006, 04:25 PM #7
Quote:
Originally Posted by pcpro17
Thanks! It worked wonderfully! Do you think the problem was with my asm statement "__asm" versus "__asm__ volatile" or in the capitalization of the "=A" and "=D"?
No, the command __asm seems to be specific to Microsoft (link to MSDN).
I only used the syntax that fits to gcc (link to gcc.gnu).
pcpro17's Avatar
Senior Member with 233 posts.
 
Join Date: Oct 2006
Location: Wisconsin, USA
Experience: Advanced
20-Dec-2006, 04:44 PM #8
Quote:
Originally Posted by Chicon
No, the command __asm seems to be specific to Microsoft (link to MSDN).
I only used the syntax that fits to gcc (link to gcc.gnu).
Oic, Thanks!
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:13 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.