Shop OBEX P1 Docs P2 Docs Learn Events
SX48 Dividing and Bank Handling — Parallax Forums

SX48 Dividing and Bank Handling

YendorYendor Posts: 288
edited 2010-05-20 13:34 in General Discussion
I'm still converting code from sx28 to sx48, and looking for some tips with the following:

I have a word variable in bank $60 called TickTimer
Im passing a byte·into the sub and have aligned the value to be in the same bank ($60)


Sub Setit

·tmptimerB1 = __PARAM1

···\ BANK Timing
··TickTimer =·12590 / tmpTimerB1
····TickTimer = TickTimer + tmpTimerW1
··\ BANK $00

ENDSUB

First of all, I'm finding that I need to add ASM bank statements in order for it to start right.
Secondly, when running through SXSim, the banks are not updatating to bank $60 to do the calculation correctly when accessing the TickTimer_LSB and _MSB bytes.

Do I need to go to assembly and add the necessary bank statments for it to work correctly? Note Bold code updates at BANK $00, and not BANK $60 where the variables are located.

Thanks again!
MOV __PARAM1,#12590& 255 ; tmpTimerW1 = 12590 / tmpTimerB1
MOV __PARAM2,#12590 >> 8 
MOV FSR,#tmpTimerB1 
MOV __PARAM3,IND 
CLR __PARAM4 
CLR FSR 
[b]CLR tmpTimerW1_LSB 
CLR tmpTimerW1_MSB[/b] 
MOV W,__PARAM3 
OR W,__PARAM4 
JZ @$+41 
CLR __PARAM5 
JMP @$+5 
CLC 
RL __PARAM3 
RL __PARAM4 
INC __PARAM5 
JNB __PARAM4.7,@$-4 
JMP @$+7 
CLC 
[b]RL tmpTimerW1_LSB 
RL tmpTimerW1_MSB[/b]

·

Comments

  • ZootZoot Posts: 2,227
    edited 2010-05-19 04:42
    Hit the docs -- in ASSEMBLY the vanilla BANK statement will not set all bits of the upper nibble of FSR, only three.

    On the SX28, it doesn't matter, as it doesn't have the upper 8 banks of RAM.

    Generally, if doing assembly, it helps to use a macro for BANK, e.g.

    
    ASM
    _BANK MACRO 1
      BANK \1 
      IFDEF SX48_52; For SX48/52 change
         IF \1 & %10000000 ; FSR bit 7
             SETB FSR.7
         ELSE
             CLRB FSR.7
         ENDIF
      ENDIF
      ENDM
    ENDASM
    
    ' then in use ....
    ASM
    _BANK someVarName
     MOVE W, someVarName
    _BANK someOtherVar
    MOV someOtherVar, W
    ENDASM
    
    



    I generally *always* use the macro for all assembly so it doesn't matter if it compiles for an SX28 or SX48.

    Note that on the SX48 it will always take TWO instructions to properly set the bank.

    The "BANK" instruction in SX/B handles this for you, so you may not ever have seen it, unless you check the assembly output carefully.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • YendorYendor Posts: 288
    edited 2010-05-19 12:50
    Thanks again Zoot!

    I knew it had to do with the extra fsr bits and new I had to do a 'bank' - that's killed me enough - but I guess naive (still!) in thinking SX/B handles most of it for us (esp. wiithin a divide function), and didn't think I'd have to convert to assembly.

    Just wasn't sure if it was 'the way' or not.

    Much appreciated!
  • ZootZoot Posts: 2,227
    edited 2010-05-19 13:16
    You DON'T have to convert to assembly. The SX/B BANK statement will do everything properly for the '48 or the '28.

    HOWEVER, in your code snippet, the BANK statements were "assembly":

    BANK someVar ' SX/B
    \BANK someVar ' assembly because of the backslash

    The first will set all FSR bits properly on an SX48, the second will NOT.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • YendorYendor Posts: 288
    edited 2010-05-19 16:57
    Hmm, something is fishy then

    If I do:
    TickTimer = 12590 / tmpTimerB1

    by itself, In sx/b, it fails miserably because it updates the wrong registers.

    I put the ASM bank statements in there because I was getting an error, and to try to force it in the appropriate bank.

    I even had this

    INC I

    in sx/b and i had to put a bank statement in manually before it to get it to increment.

    Let me skeletonize some code tonight to illustrate the point. It's probably just me as usual.

    Thanks so much!
  • ZootZoot Posts: 2,227
    edited 2010-05-19 17:11
    How do you have the Word var assigned in the bank? If it's with @ then you have to do manual banking (which is good a lot of the time as it's much more efficient code-wise).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • YendorYendor Posts: 288
    edited 2010-05-19 17:24
    Yeah, it's with @. I'm sure it is, but trying to get my head around it has been a challenge, to say the least. Then it's been so long that I've worked with then, but finally solved all my problems, then ran out of code space for my data! So figured I'd move to the '48.

    I really appreciate you + the others still frequenting the sx forums!

    I will still post some code tonight (prob late - so don't wait up[noparse]:o[/noparse]) ), and would apreciate any advice and pointers.

    Thanks!
  • ZootZoot Posts: 2,227
    edited 2010-05-19 18:35
    Defining variables with @ allows for manual banking, which can be advantageous. If you are unsure, then use only SX/B BANK and not assembly, and it should be fine. But you *must* properly bank with @, e.g.

    myWord VAR Word @$30
    myWord2 VAR Word @$32
    
    BANK @myWord
    myWord = myWord / 54321
    myWord = myWord * 12345
    myWord2 = myWord
    myWord2 = myWord2 // myWord
    BANK __DEFAULT
    
    



    This is covered in the SX/B docs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • skynuggetskynugget Posts: 172
    edited 2010-05-20 01:18
    yendor i had a similar problem, it drove me nuts, i ended up giving up and defining my wordvar high in my varlist so it ended up in bank $00 and all was great. not much help, but might give someone an aha moment?
  • YendorYendor Posts: 288
    edited 2010-05-20 13:34
    Thanks guys - will have to be sometime this weekend before I post again, so stay tuned!
Sign In or Register to comment.