Archived

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

randomDecay

simple assembly programming

Recommended Posts

Guest Anonymous Poster
Write it in C and look at the assembly code prior to linking.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

Most compilers have an option to output an assembly file. Check the docs on your compiler in question. (I think it''s a -S switch w/ Borland, but I''m not sure).

Then open the assembly file in your favorite text editor.

Actually, writing it in C and then doing the conversion yourself might be better. Some compilers are more efficient than others.

JSwing

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by randomDecay
I was wondering how I can test if a value is within 100 of another value. How would I go about doing this using assembly? Thanks



I can almost guarantee that writing this routine in assembly will not be faster than writing the same routine in C/C++, so if that is why you are writing the routine please reconsider, from one programmer to another.

Share this post


Link to post
Share on other sites
quote:

how do I do that?



In VC Project->Settings->C/C++
change CATAGORY to LISTING FILES
chage LISTING FILE TYPE to ASSEMBLY WITH SOURCE CODE

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
its pretty easy, here is part of what you have to do:

cmp ax,value + 100
jbe label1

label1:
cmp ax,value - 100
jge label2

label2:
here you know that it is within the range, if you don''t come here then its not withing the range

Share this post


Link to post
Share on other sites
C version...



BOOL Range_Within_100(int value, int another_value)
{

return (abs(another_value-value) <= 100);

}



in ASM you'd do something like this...



BOOL Range_Within_100(int value, int another_value)
{

_asm
{

// do subtraction: another_value - value

mov ecx, another_value
sub ecx, value

// absolute value

mov edx, ecx
sar edx, 15
xor ecx, edx
sub ecx, edx

// assume it's not within range

sub eax, eax

// we were correct

cmp ecx, 100
jg done

// no we weren't change it to 1 (withing range)

inc eax
done:

// return value in EAX

}

}



Hope this helps....

Edited by - Gladiator on November 14, 2001 2:41:32 AM

Share this post


Link to post
Share on other sites