Click here to Skip to main content
15,886,199 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Open Logical drives using Createfile function Pin
SoftEngi21-Feb-05 16:43
SoftEngi21-Feb-05 16:43 
GeneralRe: Open Logical drives using Createfile function Pin
Blake Miller22-Feb-05 5:16
Blake Miller22-Feb-05 5:16 
GeneralXP System Restore Pin
Monty220-Feb-05 22:06
Monty220-Feb-05 22:06 
GeneralRe: XP System Restore Pin
22491720-Feb-05 23:43
22491720-Feb-05 23:43 
GeneralRe: XP System Restore Pin
Monty220-Feb-05 23:51
Monty220-Feb-05 23:51 
GeneralService for serial port on Visual C++ 6.0 (Win2K) Pin
ILIA_M20-Feb-05 21:59
ILIA_M20-Feb-05 21:59 
GeneralRe: Service for serial port on Visual C++ 6.0 (Win2K) Pin
Antony M Kancidrowski21-Feb-05 1:09
Antony M Kancidrowski21-Feb-05 1:09 
QuestionThere is a better way to achieve that? Pin
Stephan Poirier20-Feb-05 19:25
Stephan Poirier20-Feb-05 19:25 
Hi everyone,

I need to know if there is a better way to swap variables values in assembly code. I have a thread that sort some variables and I wanted to make it as fast as possible. Also, I wanted to do it in assembly code just to learn a little about it. It is my first attempt in assembly code so apologize for mistakes. If you know how to do it in a better way, let me know! The code you see below works great but I'm sure we can do that in a more "fancy" way.

This how I call the function :

UltraSwap( &Var1, &Var2 );

Then this is the function in assembly code :

#pragma warning (disable:4035) // disable warning 4035 (function must return something)<br />
<br />
_inline PVOID UltraSwap( LONG* a, LONG* b ) <br />
{ <br />
	LONG x = *a;<br />
	LONG y = *b;<br />
	__asm	mov eax, x<br />
	__asm	mov ebx, y<br />
	__asm	mov x, ebx<br />
	__asm	mov y, eax<br />
			<br />
	*a = x;<br />
	*b = y;<br />
}<br />
<br />
#pragma warning (default:4035)        // Reenable it


The only thing I don't understand is that I can't move *x or *y into eax and ebx respectively. I had to declare two local variables to achieve that. I think that just declaring that will take some times. I didn't tested what's the difference in time between swapping two variables in C++ code and in assembly because I didn't know how to, since GetTickCount() isn't too much reliable and not so much fast.

Let me know if you guys find something!
Have a nice day!

Stef

Progamming looks like taking drugs...
I think I did an overdose. Poke tongue | ;-P
AnswerRe: There is a better way to achieve that? Pin
22491720-Feb-05 23:10
22491720-Feb-05 23:10 
AnswerRe: There is a better way to achieve that? Pin
V.21-Feb-05 0:34
professionalV.21-Feb-05 0:34 
GeneralRe: There is a better way to achieve that? Pin
22491721-Feb-05 0:37
22491721-Feb-05 0:37 
GeneralRe: There is a better way to achieve that? Pin
V.21-Feb-05 4:35
professionalV.21-Feb-05 4:35 
AnswerRe: There is a better way to achieve that? Pin
Zdeslav Vojkovic21-Feb-05 5:58
Zdeslav Vojkovic21-Feb-05 5:58 
GeneralRe: There is a better way to achieve that? Pin
22491721-Feb-05 16:35
22491721-Feb-05 16:35 
GeneralRe: There is a better way to achieve that? Pin
Stephan Poirier21-Feb-05 19:57
Stephan Poirier21-Feb-05 19:57 
GeneralRe: There is a better way to achieve that? Pin
Zdeslav Vojkovic22-Feb-05 0:36
Zdeslav Vojkovic22-Feb-05 0:36 
GeneralRe: There is a better way to achieve that? Pin
Stephan Poirier21-Feb-05 21:00
Stephan Poirier21-Feb-05 21:00 
GeneralRe: There is a better way to achieve that? Pin
Zdeslav Vojkovic22-Feb-05 2:27
Zdeslav Vojkovic22-Feb-05 2:27 
GeneralRe: There is a better way to achieve that? Pin
Stephan Poirier22-Feb-05 14:47
Stephan Poirier22-Feb-05 14:47 
GeneralRe: There is a better way to achieve that? Pin
Stephan Poirier22-Feb-05 14:56
Stephan Poirier22-Feb-05 14:56 
AnswerRe: There is a better way to achieve that? Pin
Stephan Poirier21-Feb-05 16:18
Stephan Poirier21-Feb-05 16:18 
Questionhow to achieve a secure file system against information leak? Pin
zymoonstone20-Feb-05 19:12
zymoonstone20-Feb-05 19:12 
AnswerRe: how to achieve a secure file system against information leak? Pin
22491721-Feb-05 0:45
22491721-Feb-05 0:45 
GeneralRe: how to achieve a secure file system against information leak? Pin
zymoonstone21-Feb-05 13:54
zymoonstone21-Feb-05 13:54 
QuestionConnected or not? Pin
wasife20-Feb-05 18:58
wasife20-Feb-05 18:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.