Shop OBEX P1 Docs P2 Docs Learn Events
memory questions — Parallax Forums

memory questions

Armored CarsArmored Cars Posts: 172
edited 2005-11-02 17:04 in General Discussion
If I set org $0A and then set a list of variables with "variable· ds·· 1" once the ds 1 reaches $10 will that variable be in bank 0 or bank 1?

Comments

  • Armored CarsArmored Cars Posts: 172
    edited 2005-11-02 13:41
    Anybody?
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-11-02 15:15
    How about compiling an example then looking at the generated asm file and list file? The answer may be dependent on whether you are using a SX28 and SX52 since the addressing mode in SX52 is handled differently and bank 0 is a special case.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Armored CarsArmored Cars Posts: 172
    edited 2005-11-02 15:23
    I'll try that.· I am using an SX 52 though.
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2005-11-02 17:04
    Letting the variables "overflow" into the next bank can cause you a lot of sleepless nights. Here is an example:

          org    $8
    aaa          ds 1
    bbb          ds 1
    ccc          ds 1
    ddd          ds 1
    eee          ds 1
    fff          ds 1
    ggg          ds 1
    hhh          ds 1
    iii          ds 1
    
          org    $10
    jjj          ds 1
    
    



    When you look at the list file, you will notice that the assembler has defined address $10 for variable iii due to "overflowing" the bank border but it also has defined address $10 for variable jjj as it is defined immediately following the org $10 directive.

    SASM does not generate an error because in general, it is absolutely legal referring to one value by more than one symbol. The disaster will come up when you indeed assume that iii and jjj are two different variables occupying different RAM locations. As this is not the case, modifying the contents of variable iii also changes the contents of variable jjj, and vice-versa, which is not what you might expect. Therefore, it's a good idea to check the list file for such possible pitfalls.

    BTW, the same is true for code-generation across page boundaries.

        org        $2f3
    ClearVars
        clr   !wdt
        sb      fsr.4               
          setb  fsr.3               
        clr     ind                 
        incsz   fsr                 
          jmp   ClearVars
          
        bank    PWM
        mov     PWM_Prescaler, #PWMPeriod    
    
        mov     !option, #INT_ON
    :MainLoop
        bank    Analog
        mov     w, Analog_ADCresult
        mov     rb, w
        bank    PWM
        mov     PWM_DutyCycle, w
        jmp     :MainLoop
    
    



    When you assemble this code, and look at the list file, you will notice that code generation "overflows" into the next page, i.e. the instruction code for "mov w, Analog_ADCResult" will be located at $02ff, and the instruction code for "mov rb, w" is at $300, with the next instruction codes following at subsequent locations in page $0300. To make the disaster complete, see what happens when the final "jmp :MainLoop" is executed. As the SX-internal program counter is simply incremented as long as no skips, jumps, or calls are executed, there is no problem, crossing the page when this code is executed the very first time. But the final jmp instruction targets to a location which is not in the page currently addressed by the program counter. So, this jump will not go back to address $2fe, the first instruction following the label ":MainLoop" but the jump will go to $3FE instead, i.e. right into "nowhere land".

    Here is a "trick" to let the assembler generate an error on such situations: Place nop instructions at the very first location of each page, as long as you don't need that page for "real" code. When you follow the lines of this sample code with

    org $300
    nop

    SASM will generate an "Overwriting same program counter location" error in this case.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
Sign In or Register to comment.