Shop OBEX P1 Docs P2 Docs Learn Events
can't pass variables between sxb and assembly — Parallax Forums

can't pass variables between sxb and assembly

warnerwarner Posts: 17
edited 2008-02-20 12:25 in General Discussion
Hello still not working still.
·
In the program below I am trying to use the variable byte try4 in the assembly code I have included in the sxb program. It doesn’t seem to be working. Can you tell me how to pass variables between sxb and assembly?
·
Thanks Warner


DEVICE········· SX28, OSCHS2, TURBO, STACKX, OPTIONX
FREQ··········· 50_000_000

'
' IO Pins
'
led············ VAR···· Rc.7


'
' Variables
'

try1··var ·byte
try2··var ·byte
try3··var ·byte
try4··var·byte
· PROGRAM Start

Start:

Main:
·try4 = 255
····· ·high led
·pause try4
·low led
·pause try4
· ·'SHIFTIN ra.0, ra.1, msbpost, datain
asm

Comments

  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-03-20 20:35
    Where's the rest of your code?
  • JonnyMacJonnyMac Posts: 9,217
    edited 2007-03-20 20:44
    SX/B uses the __PARAMx and __WPARAMxx variables to pass values. Here's an example of assembly accepting a value from a standard SX/B call (program is from my May 2007 Nuts & Volts column):

    ' Use: TX_BYTE aByte
    ' -- if TX UART is busy, will wait for it to clear
    
    TX_BYTE:
      ASM
      BANK  serial
      TEST  txCount                                 ' transmitting now?
      JNZ   TX_BYTE                                 ' >0 = yes, so wait
      MOV   txHi, __PARAM1                          ' move byte to tx buffer
      CLR   txLo                                    ' set start bit
      MOV   txCount, #10                            ' start + 8 data + 1 stop    
      BANK  0
      ENDASM
      RETURN
    



    The byte to transmit was passed in __PARAM1 and you can see it used about half way down the listing. Note that the compiler takes care of moving your value (constant or variable) to the correct internal (__PARAMx or __WPARAMxx) variable.

    Post Edited (JonnyMac) : 3/20/2007 8:49:25 PM GMT
  • warnerwarner Posts: 17
    edited 2007-03-20 21:18
    I don’t see the difference between this and what I’m doing in this code.

    Main:
    try4 = 255
    high led
    pause try4
    low led
    pause try4

    'SHIFTIN ra.0, ra.1, msbpost, try4

    end


    asm

    loopy

    call delay ;delay
    mov W,/RC ;toggle all of RC port
    mov RC,W
    jmp loopy


    Delay clr try1
    clr try2
    mov try3,#try4

    Loop djnz try1,loop ;Decrement until all are zero
    djnz try2,loop
    djnz try3,loop
    ret
    endasm
  • JonnyMacJonnyMac Posts: 9,217
    edited 2007-03-20 21:31
    Well, my code is actually passing a variable through the SX/B mechanism of using the __PARAMx or __WPARAMxx variables which are in the global address space; when you're using your own variables you may need to ensure that you've got the correct BANK selected when you're working in the Assembly code. If you look in my example above I point to the serial bank because that's where txCount resides. __PARAM1 is in the global space so I don't have to switch to BANK 0 to get to it.

    If you don't have it you might want to get a copy of Guether Daubach's excellent book, "Programming the SX Microcontroller."
  • BeanBean Posts: 8,129
    edited 2007-03-20 21:34
    You don't use the # here "mov try3,#try4"

    The easiest thing to do is look at the SX/B output to see how to use variables and stuff.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Educate your children to self-control, to the habit of holding passion and prejudice and evil tendencies subject to an upright and reasoning will, and you have done much to abolish misery from their future and crimes from society"

    Benjamin Franklin
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Cheap used 4-digit LED display with driver IC·www.hc4led.com
    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Coming soon! Propeller based OSD module www.hittconsulting.com
    ·
  • warnerwarner Posts: 17
    edited 2007-03-20 21:43
    Thank you
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-03-21 04:58
    · 168· =00000048······ Main:··························· ;Main:
    ·· 169·················
    ·· 170·················
    ·· 171· 0048· 05E7······· SETB led······················ ;············· high led
    ·· 172· 0049· 0CFC······· MOV FSR,#__TRISC·············
    ······· 004A· 0024
    ·· 173· 004B· 04E0······· CLRB IND.7···················
    ·· 174· 004C· 005F······· MODE $0F·····················
    ·· 175· 004D· 0200······· MOV !RC,IND··················
    ······· 004E· 0007
    ·· 176· 004F· 0018······· BANK $00·····················
    ·· 177· 0050· 05E7······· SETB led·····················
    ·· 178·················
    ·· 179· 0051· 0CFF······· MOV __PARAM2,#255············· ;····· pause try4
    ······· 0052· 0029
    ·· 180· 0053· 0C04······· MOV __PARAM3,#4··············
    ······· 0054· 002A
    ·· 181· 0055· 0C1C······· MOV __PARAM4,#28·············
    ······· 0056· 002B
    ·· 182· 0057· 02EB······· DJNZ __PARAM4,@$·············
    ······· 0058· 0010 0A57
    ·· 183· 005A· 02EA······· DJNZ __PARAM3,@$-3···········
    ······· 005B· 0010 0A57
    ·· 184· 005D· 02E9······· DJNZ __PARAM2,@$-10··········
    ······· 005E· 0010 0A53
    ·· 185·················
    ·· 186· 0060· 04E7······· CLRB led······················ ;····· low led
    ·· 187· 0061· 0CFC······· MOV FSR,#__TRISC·············
    ······· 0062· 0024
    ·· 188· 0063· 04E0······· CLRB IND.7···················
    ·· 189· 0064· 005F······· MODE $0F·····················
    ·· 190· 0065· 0200······· MOV !RC,IND··················
    ······· 0066· 0007
    ·· 191· 0067· 0018······· BANK $00·····················
    ·· 192· 0068· 04E7······· CLRB led·····················
    ·· 193·················
    ·· 194· 0069· 0CFF······· MOV __PARAM2,#255············· ;····· pause try4
    ······· 006A· 0029
    ·· 195· 006B· 0C04······· MOV __PARAM3,#4··············
    ······· 006C· 002A
    ·· 196· 006D· 0C1C······· MOV __PARAM4,#28·············
    ······· 006E· 002B
    ·· 197· 006F· 02EB······· DJNZ __PARAM4,@$·············
    ······· 0070· 0010 0A6F
    ·· 198· 0072· 02EA······· DJNZ __PARAM3,@$-3···········
    ······· 0073· 0010 0A6F
    ·· 199· 0075· 02E9······· DJNZ __PARAM2,@$-10··········
    ······· 0076· 0010 0A6B
    ·· 200·················
    ·· 201·················
    ·· 202· 0078· 0010······· JMP @Main····················· ;GOTO Main
    ······· 0079· 0A48
  • Sens-a-DatSens-a-Dat Posts: 44
    edited 2008-02-20 03:33
    Gents,

    I was having the same issue for the past days, and I believe I have figured out what you need to know. The situation is where one has defined a VAR and CON SX/B and they want them to also be used in an assembly routine which is part of the overall SX/B program.

    Let me give two examples which may help illustrate this. For each example in assembly, we will make X = Y.

    If Y is a variable in SX/B, then use in assembly: mov X,Y

    If Y is a constant in SX/B, then use in assembly: mov X,#Y

    If anyone has other tidbits of information not noted in the documents, I would enjoy knowing about them.

    Thanks
  • BeanBean Posts: 8,129
    edited 2008-02-20 12:25
    The thing to remember is that a variable name does NOT contain the value of the variable. It really is a constant that contains the ADDRESS of the value of the variable.

    For example let's say that you have a variable named "X" that is stored at RAM location $0F and has the value 123. The "value" of X is $0F, and the value contain in RAM at location $0F will be 123.

    In assembly the instruction "MOV X,Y" means to move the value in RAM location "Y" to RAM location "X". Where "MOV X,#Y" means to move the actual value of "Y" to RAM location "X".

    When you use arrays what you do is assign the array location (held in the array name) to the FSR register, then access the array element with the IND register. But·in this case you really DO want the RAM location, so·you need to put a "#" in front of the array name.

    These two instructions are the same as "MyArray(0) = 123"

    MOV FSR,#MyArray
    MOV IND,#123

    I hope this helps,

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com



    Post Edited (Bean (Hitt Consulting)) : 2/20/2008 4:26:00 PM GMT
Sign In or Register to comment.