How do you do signed comparing statements in 65816

Strictly for discussing ZSNES development and for submitting code. You can also join us on IRC at irc.libera.chat in #zsnes.
Please, no requests here.

Moderator: ZSNES Mods

Post Reply
undisbeliever
Rookie
Posts: 35
Joined: Sat Aug 21, 2004 2:31 am
Location: is an eight lettered word

How do you do signed comparing statements in 65816

Post by undisbeliever »

I'm having a bit of trouble working with signed values in my SNES Small C Compiler. It currentaly supports unsigned values, but I want it to support signed variables.

Super Mario World uses signed values: As shown here

Code: Select all

LDA lifecounter
BMI +
CMP #99
BCS +
; do code here
+
This is the code to do a signed comparing on the life counter. (it first checks if it is neg then if it is less then 4 (I think)

Anyway, If the first value is in the stack and the second value is in the accumulator, how do I write a piece of code that will work in all situations???
undisbeliever
Rookie
Posts: 35
Joined: Sat Aug 21, 2004 2:31 am
Location: is an eight lettered word

Post by undisbeliever »

Currentally I'm using unsigned values.

With signed values (a == b) and (a != b) are the same, but when I use (a < b) it tends to get complicated.

This is what I currentlally have for unsigned value (assume 16 bit acc,index):

Code: Select all

;first value in stack
;next value in acc

  CMP $01,S  ;if(a < b)
  BGE +      ; = if(!(b >=a))
  LDA #$FFFF ;     true
  BRA ++
+            ;   else
  LDA #$0000 ;     false
++
  PLY
I'm thinking that I should be able to do this if I divide this into two sections, positive and negitive (but it starts etting confusing)

Can Any suggestions be made???
anomie
Lurker
Posts: 151
Joined: Tue Dec 07, 2004 1:40 am

Post by anomie »

Have you tried that with BPL/BMI instead of BGE/BLT?
undisbeliever
Rookie
Posts: 35
Joined: Sat Aug 21, 2004 2:31 am
Location: is an eight lettered word

Post by undisbeliever »

That's the idea. I need to first check the sign of the two variables and then compare them, The above example is what I used for UNSIGNED values.
Post Reply