flat assembler
Message board for the users of flat assembler.

Index > Main > Comparison of numbers

Author
Thread Post new topic Reply to topic
FlashBurn



Joined: 06 Jan 2005
Posts: 87
FlashBurn
I have the problem that I have the amount of ram a pc has and I check if it is more than 8MiB.

The problem is now, that if the PC has more than 2GiB (I think so, my test pc has 3.25GiB) the code works as if it uses negative numbers.

What have I to use to compare 2 numbers w/o negative numbers.

At the moment I use:

Code:
cmp dword[amount_of_ram],0x800000
jnge .end_err
    
Post 06 Aug 2007, 21:26
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
mmm, lets clarify, you want to compare unsigned integers?

In such case your code is almost enough, just change jnge with jnae. The "above" and "below" are for unsigned comparisons and "lower" and "greater" for signed comparisons.
Post 06 Aug 2007, 22:13
View user's profile Send private message Reply with quote
FlashBurn



Joined: 06 Jan 2005
Posts: 87
FlashBurn
Thanks for your reply, it works now.

I´m now a assembly programmer for 7 years, but I had never problems with signed and unsigned integers. And now I know the difference between above/below and less/greater.
Post 07 Aug 2007, 05:21
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
But why...
Code:
cmp dword[amount_of_ram],0x800000
jnge .end_err
    

Actually my approach to any problem is using UNsigned first and if absolutely neccessary - I will try to make it UNsigned - and if I can't... well, then I will use signed Smile Politics Razz

Btw, why make it so hard (I know the syntax and mnemonics allow this, but:
Code:
cmp dword[amount_of_ram],0x800000
jae .end_err ;or jnc .end_err
    

Above or Equal means that RAM is at least 8MB (computer mega Smile, so MiB)
No carry means that it isn't less than 8MB which is also the same, but a little more complicated.

Not greater and not equal Razz wow - this messes even me up Smile

I hope this clarified a bit.
Post 07 Aug 2007, 06:39
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.