flat assembler
Message board for the users of flat assembler.
Index
> Main > How to use large numbers? 
Author 

bitRAKE
IIRC, the board has routines for large integer arithmetic. Here is a tut to get you started though...
http://www.x86asm.net/articles/workingwithbignumbersusingx86instructions/ 

02 Mar 2013, 02:07 

Bob++
Thanks. I have read it,but I'm a bit confusing how to implement for example, cmp.


02 Mar 2013, 02:42 

bitRAKE
Start at the most significant dwords, exit when not equal, or when least significant dword is reached. Or just use REPZ CMPSD.
To use REPZ CMPSD correctly the direction flag would need to be clear if dwords are ordered greatest to least; and set if ordered least to greatest. Also, in the later case you would start with the larger addresses in ESI/EDI. Of course, an example: Code: NUMBER.limbs = 2 ; because each number is two DWORDs A.NUMBER dd $1FFFFFFF,$FFFFFFFF ; nineth mersenne prime B.NUMBER dd $1FFFFFFF,$FFFFFFFF entry $ NUMBER.Compare: cld ; most significant DWORDs are at low addresses lea esi,[A.NUMBER] lea edi,[B.NUMBER] mov ecx,NUMBER.limbs repz cmpsd jz .equal jg .greater nop .equal: nop .greater: nop 

02 Mar 2013, 03:11 

cod3b453
Unless you want to support numbers larger than 32bit or signed 32bit values (numbers you listed were positive and fit in 32bits), they're only negative if you treat them as a signed numbers. You can use cmp as normal with the correct [unsigned] condition codes.


02 Mar 2013, 12:29 

Bob++
bitRAKE,thank you! I will try it!
cod3b453,so is my mistake? if they are positive,why I'm getting as negative value? in the below code,less run. Code: cmp eax,0 jl less give me an example please,I'm very new to asm. Also a routine that converts an integer to ascii give me back eax value as negative,including  symbol. 

02 Mar 2013, 17:45 

cod3b453
I suggest you look at the descriptions for cmp and jcc for full info. The cmp instruction will update a number of flags for both signed and unsigned comparison at the same time. The jcc instruction (and others) will use one or more of these flags for the condition. In this case you've used signed jumpiflessthan (jl); if you wanted the unsigned version you'd use the unsigned jumpifbelow (jb). Note that in your example cmp eax,0 would always be false for jb because no unsigned (i.e. positive) value (or zero) is less than 0.
Again this is assuming you don't want signed values? 

02 Mar 2013, 18:09 

bitRAKE
Here is a quick reference tool by Svin to help with conditional jump selection. The tool is over 10 years old and I don't know where Svin is on the internet  I feel he would be okay with me posting this as he was always trying to educate.


03 Mar 2013, 03:08 

revolution
Actually doing magnitude for multi precision numbers is not as easy as it might first appear. I've always ended up just using the standard subtraction routine and then check the result for negativity or allzeros.
Trying to use MSW down approach can easily lead to tricky and fragile code. 

07 Mar 2013, 07:31 

bitRAKE
Yeah, I made a lot of assumptions to validate my approach  which makes me tricky and fragile. It's simple enough to switch to LSW up method, and a little more for different limb sized operands. String instructions might even be faster than writing that subtraction back to memory. <More Assumptions \>


07 Mar 2013, 08:45 

< Last Thread  Next Thread > 
Forum Rules:

Copyright © 19992020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.