CMPS problem
Graham Stabler
Posts: 2,510
I have some test code roughly like this:
When wc is set for cmps then c should be set when value1 <= value2 so can anyone tell me why the code acts differently when the line with the jmp is commented out? As zero will always equal zero and hence C should always be set.
The following code works as expected:
Commenting out the jmp line makes no difference.
But this code also does not work as expected:
Again the jmp is getting called even though one will always equal one.
Graham
cmps zero,zero wc if_nc jmp #:nxt ...... long zero 0
When wc is set for cmps then c should be set when value1 <= value2 so can anyone tell me why the code acts differently when the line with the jmp is commented out? As zero will always equal zero and hence C should always be set.
The following code works as expected:
cmps zero,one wc if_nc jmp #:nxt ...... long zero 0 long one 1
Commenting out the jmp line makes no difference.
But this code also does not work as expected:
cmps one,one wc if_nc jmp #:nxt ...... long one 1
Again the jmp is getting called even though one will always equal one.
Graham
Comments
· In the cmps instruction, it's like a subs... c is set when there is a signed borrow in the operation, z is set when the result is zero.·
since zero - zero = zero, only z would be set and c would be clear.
zero - one = -1, so z would be clear and c would be set.
After looking at your posting and typing this I began to wonder why you thought c would be set if value1 <= value2... then I looked in the manual and saw that it may be because that's what I mistakenly wrote in the manual... [noparse]:([/noparse]· I'm sorry, I goofed.· I'll fix it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Jeff Martin
· Sr. Software Engineer
· Parallax, Inc.
Thanks
Graham
would have caught that <= on the carry bit.
I spent all last night staring at this and most of tonight, armed with this info I only needed about 10 minutes more, phew.
Graham
Are you saying that the following two instructions do exactly the same thing?
SUBS [font=ArialNarrow,BoldItalic size=2]SValue1[/font], 〈#〉 [font=ArialNarrow,BoldItalic size=2]SValue2[/font]
[font=ArialNarrow,BoldItalic size=2]CMPS [font=ArialNarrow,BoldItalic size=2]SValue1[/font], 〈#〉 [font=ArialNarrow,BoldItalic size=2]SValue2 WR[/font]
[font=ArialNarrow,BoldItalic size=2]If so, then that would make make CMPS a redundant opcode, which can be eliminated and reused in Prop, the Sequal, (coming to a theater Radio Shack near you ;-) ).[/font]
[font=ArialNarrow,BoldItalic size=2]Mark
[/font][/font][font=ArialNarrow,BoldItalic size=2]
[/font]Post Edited (lucidman) : 10/16/2007 4:22:01 PM GMT
(a) Jeff said: CMPS is something LIKE SUBS
This is a little bit misleading.. In fact it is not! CMP is something just as SUB.
But the carry is handled very differently in CMPS and SUBS. In fact the carry handling of SUBS is rarely understood and deSilve strongly recommends NOT to use SUBS if you do not exactly know what you are doing, just use SUB. You cannot find out the sign after an subtraction, simply as there is no sign flag, as in many other procesors. The sign bit IS bit 31 and you have to check for it. The cleanest way is to do CMPS xx, #0 after a SUB.
(b) There are MANY assembly codes for just the same binary opcode, best known is CALL for JMPRET, or even CMP and SUB which lead to the same opcode.. This is just fine and usage in many assambly languages. It will not help to free any of the op codes...
Post Edited (deSilva) : 10/16/2007 4:45:12 PM GMT
I see now that the carry handling is different. Thanks In this example, why not just do CMPS dval, sval WC,WR instead of SUB(S?) dval, sval WC, if you need to need to know the sign after the subtract?
Generally, I really would like to see some documentation descibing the carry/borrow/overflow logic that defines the carry flag in the add/sub/cmp/adds/subs/cmps instructions. Some simple boolean statements or logic diagrams would suffice.
Mark