   simple assembly programming
  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  
  Write it in C and look at the assembly code prior to linking.  ;  how do I do that? Thanks.  ;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  ;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.;  relax, it''s kinda a homework assignment ;quote:how do I do that?  In VC Project->Settings->C/C++change CATAGORY to LISTING FILESchage LISTING FILE TYPE to ASSEMBLY WITH SOURCE CODE  ;  its pretty easy, here is part of what you have to do:cmp ax,value + 100jbe label1label1:cmp ax,value - 100jge label2label2:here you know that it is within the range, if you don''t come here then its not withing the range  ;  sorry the jbe should be jle  ;  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 - valuemov ecx, another_valuesub ecx, value// absolute valuemovedx, ecxsar edx, 15xor ecx, edxsub ecx, edx// assume it's not within rangesub eax, eax// we were correctcmp ecx, 100jg done// no we weren't change it to 1 (withing range)inc eaxdone:// return value in EAX}}  Hope this helps....Edited by - Gladiator on November 14, 2001 2:41:32 AM  