Skip to main content
gamedev.net
🔒 Locked

simple assembly programming

Started by randomDecay Nov 13, 2001 at 9:52 PM 8 replies 350+ views
Original Post
randomDecay
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
randomDecay
randomDecay
how do I do that? Thanks.
randomDecay
randomDecay
relax, it''s kinda a homework assignment
invective
invective
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
Gladiator
Gladiator
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.