I used to think parity was something to do with up/down load testing. It is used in one Euler solution, but I can't folllow why?
I've never seen the OF used and am not sure when it changes.
parity is true if there are an even number of bits set to 1
false if there are an odd number
overflow indicates rollover of a signed size value
i.e., for a 32-bit register, overflow occurs if the result exceeds 31 bits
this is so because the last bit is used for the sign
think of it as a carry flag for signed values :P
Quote from: whakamaru on August 04, 2011, 01:01:23 AM
I used to think parity was something to do with up/down load testing. It is used in one Euler solution, but I can't folllow why?
I've never seen the OF used and am not sure when it changes.
If you are checking the FPU status, I think it is useful. I'll dig out the code.
Dave.
Quote from: whakamaru on August 04, 2011, 01:01:23 AM
I used to think parity was something to do with up/down load testing. It is used in one Euler solution, but I can't folllow why?
I've never seen the OF used and am not sure when it changes.
No luck with my code. I think I saw it in a .cod file from a 'C' compile and adapted it. I'll see if I can can find this.
Dave.
i failed to mention that most of the conditional branch instructions for signed operations use the overflow flag
****************************************************************
Signed Branches
----------------------------------------------------------------
Instruction Description Condition Aliases
----------------------------------------------------------------
JG Jump if greater SF=OF or ZF=0 JNLE
JGE Jump if greater or equal SF=OF JNL
JL Jump if less SF<>OF JNGE
JLE Jump if less or equal SF<>OF or ZF=1 JNG
JO Jump if overflow OF=1
JNO Jump if no overflow OF=0
JS Jump if sign SF=1
JNS Jump if no sign SF=1
****************************************************************
as for the parity flag, i rarely see it used, anymore
in days of old, it was used for serial communications
and, i am sure there are more obscure math/logic uses for it, although i can't think of any offhand :P
it is also worth noting that parity applies only to the lower byte of word or dword values
this is because of serial comm where everything was in bytes, and may account for it's general uselessness
i suppose, if you were to carefully select values in a "state machine", you could make it do something
The FCOMI and related instructions return their result in ZF, PF, and ZF.
http://www.website.masmforum.com/tutorials/fptute/fpuchap7.htm#fcomi
Michael,
Thank you, I knew I had seen this somewhere and that it was related to FPU comparisons.
Dave.
Thanks, quite helpful.
The project euler problem where a parity line is used is in #48, the second post in the forum, by "SEPH", who doesn't accept mail otherwise I would ask him. I don't suppose discussion on these problems is allowed here, but someone might be able to explain the basic logic of the lines.
He aslo has a line...
adc dx,byte 0
which I don't understand. (nor the Norwegian jump addresses!)
there is nothing in the rules against discussion of euler project exercises
use the forum search tool :U
Quote adc dx,0
adds the value of the carry flag to DX and sets the math flags according to the result (zf, cf, sf, pf, of)
you'll see that one quite often
surprised to see a 16-bit instruction in the solution of a euler problem, though :P
maybe it's an old solution
judging from the other prject euler problems that i have looked at in the past, i'd have to say that is the easiest one :P
problem 122 is similar, slightly little more difficult
i may have a good solution for 48 :P
well - that post you are refering to is from 2004 :P
that guy is probably long-gone - lol
i was extremely disappointed to see that the thread has been locked since 2008
i fail to see the purpose of locking it
that means that no further discussion is open for new methods or algorithms
here is my down-and-dirty quick version
as it turns out, i had written the funtions a couple years ago
all i had to do was glue them together :bg
this exercise has Ling Long Kai Fang (Horner's Rule) written all over it - lol
i could make a greatly simplified version because they only require the last 10 digits
however, with the thread locked, i see no point in it
links...
this is the Ling Long Kai Fang integer to ascii function - LLKF9 is the latest one
it includes signed, unsigned, and mode-selectable versions
http://www.masm32.com/board/index.php?topic=12363.msg94779#msg94779
later on in the same thread, i made a Ling Long Kai Fang integer exponentiation function...
http://www.masm32.com/board/index.php?topic=12363.msg100575#msg100575
in the attachment, i used those 2 functions to solve euler #48
it seems pretty fast, although i didn't bother timing it
a smplified/optimized version would be much faster
i sped up the loop a little bit and added timing code
on my 3 GHz prescott, i have it at ~234 million cycles, which is ~78 mS
if i wanted to spend the time on it, i could make it zip because they only want the last 10 digits
that would make a huge difference using the Ling Long Kai Fang method