Shop OBEX P1 Docs P2 Docs Learn Events
another assembly question — Parallax Forums

another assembly question

OwenOwen Posts: 100
edited 2007-07-03 00:42 in Propeller 1
I'm having trouble executing code in assembly based on whether a variable is less than 0. can anyone explain to me
how this be written in assembly:

if variable < 0
execute code

sorry if this is too basic but I wasn't able to understand how to do this from the manual.

Thanks,

Owen

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-02 19:23
    What you're actually testing is whether the sign bit (bit 31) of the variable is set and there are many ways to do this. The most straightforward way is just to do:
                   cmps      variable,#0    wc
         if_nc   jmp        #:skipIt
    ' Here's the code to be executed
    :skipIt
    
    
  • SkogsgurraSkogsgurra Posts: 231
    edited 2007-07-02 19:26
    Something like this?

    cmp t2,t3 wc
    if_c jmp #tongue.gifos
    ' rest of code (negative part) goes here

    tongue.gifos ' code for positive result

    The trick, as I have understood it, is to remember to write the right flag - and then check it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • SkogsgurraSkogsgurra Posts: 231
    edited 2007-07-02 19:28
    Hmm... The ":" + "p" produced some unexpected results.

    Anyhow, you got it from Mike. Trust him.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • OwenOwen Posts: 100
    edited 2007-07-03 00:42
    Worked great! Thank you
Sign In or Register to comment.