Jump to content
  • Advertisement

Archived

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

SimDemon

Conditional Statements w/ ASM

This topic is 5572 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

Hey there. I hope you can help me. I would like to know how to use ''if'' and ''else'' statements using inline ASM w/ C/C++. Any help such as example code would be appreciated. Thanks, Matt U. If thispost = 0 Then GoBack() Else Read() End If

Share this post


Link to post
Share on other sites
Advertisement
It's been a long while since I've done any kind of assembly, but all platforms have some kind of conditional jump that test flags and then jumps if a certain one is set. IIRC, for the x86 there is cmp and j?? (where ?? = ne for not equal, eq for equal, gt for greater than, le for less than or equal to, etc), so you do something like

//some code
cmp eax, ebx //compare eax to ebx
jne else //if they are not equal, goto else
//if eax=ebx do this
jmp end_if //skip over else part
else:
//else do this
end_if:
//resume normal code here

[edited by - Extrarius on June 18, 2003 3:23:20 PM]

Share this post


Link to post
Share on other sites
Now that I got that working (was simple, thanks for the help), I need some more help. I am trying to call ''cout<<'' using assembly, but I don''t know how. I checked the ''Listing Files'', but I can''t figure it out. Thanks in advance! =)

If thispost = 0 Then
GoBack()

Else
Read()
End If

Share this post


Link to post
Share on other sites
Calling c++ functions like operator << from outside can be very difficult because C++ mangles(adds information to) function names to allow overloading. Pulling a total BS example out of nowhere, a function like
int func1(int x, int y);
might get renamed ifunc1ii(not exactly how it works, but its the same idea) by the c++ compiler so that it doesn''t conflict with other functions called ''func1'' that take different arguments. One thing you might try is telling your compiler to output assembly and then make a simple hello world program and look at the assembly it generates.

Share this post


Link to post
Share on other sites
That is exactly what I did. It shows a lot of weird characters, such as ''¡, ¿, etc''. And I cannot figure out where the code itself is and what is an unnecessary character.

Share this post


Link to post
Share on other sites
With inline assembly you call functions/variables by their actual names; the compiler will replace them with the names it generates. But cout isn''t a function, it''s a object. << is an operator that works on it. You need to call printf.

~CGameProgrammer( );

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!