Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 14th, 2005, 2:32 PM   #1
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 296
Rep Power: 4 Klarre is on a distinguished road
[x86 inline]Register needs to be prepared?

I want to do a call to the win32 api function GetTickCount(). Sadly it crashes. So I got two questions to ask you:
1. Why does it crashes?
2. In which register do the function put its return value? eax?
#include <iostream>
#include <windows.h>

int main()
{
	_asm
	{
		call GetTickCount
	}

	system("pause");
	return 0;
}
Klarre is offline   Reply With Quote
Old Nov 14th, 2005, 2:43 PM   #2
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
1. Sorry, I don't know.

2. It stores its return value in eax.
Polyphemus_ is offline   Reply With Quote
Old Nov 14th, 2005, 3:20 PM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Can I ask why you don't just call this in the C++ code?
int current_time = GetTickCount();
Is this for an assignment or something? If it is, please make a decent attempt at it yourself first. Oh, and a "please" or a "thanks for your time" always helps.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 14th, 2005, 3:45 PM   #4
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 296
Rep Power: 4 Klarre is on a distinguished road
Quote:
Originally Posted by Ooble
Can I ask why you don't just call this in the C++ code?
int current_time = GetTickCount();
Is this for an assignment or something? If it is, please make a decent attempt at it yourself first. Oh, and a "please" or a "thanks for your time" always helps.
I shall ask your questions. If you have read in the assembly forum the last week you might have seen that I have been doing a lot of posts. This because I am working on an OpenGL application totally written in assembly code (to minimize file size, and for learning/fun). I do have bad debugging opportunities in my GL app, so I have been testing all my code in inline first. The next step in my project is to make a timer that calculates the delta time between each frame, and therefor I need a call to the GetTickCount function.

This is not an assignment. And I have been testing to solve the problem for a while now. But a strange thing is (that probably are not strange) that it worked great to call the function from my assembly app! To bad I can't see if it works...yet.

And oh! Thank you guys for taking time answearing my questions!

/Klarre
Klarre is offline   Reply With Quote
Old Nov 14th, 2005, 5:25 PM   #5
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 824
Rep Power: 4 The Dark is on a distinguished road
I had a look at the code generated by the C compiler when calling
GetTickCount();

and it seems you need to use
  _asm
  {
    call dword ptr GetTickCount
  }

and yes, the result is in EAX
The Dark is offline   Reply With Quote
Old Nov 15th, 2005, 2:48 AM   #6
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 296
Rep Power: 4 Klarre is on a distinguished road
Quote:
Originally Posted by The Dark
I had a look at the code generated by the C compiler when calling
GetTickCount();

and it seems you need to use
  _asm
  {
    call dword ptr GetTickCount
  }

and yes, the result is in EAX
Problem solved!
Thank you The Dark! It works great now!
Klarre is offline   Reply With Quote
Old Nov 15th, 2005, 10:51 AM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Damn... gotta pay more attention to post count, I guess. Sorry 'bout that...
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:54 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC