Shop OBEX P1 Docs P2 Docs Learn Events
No macros in SX/B? — Parallax Forums

No macros in SX/B?

Paul BakerPaul Baker Posts: 6,351
edited 2005-05-05 22:28 in General Discussion
Im trying to make my first SX/B project more readable through macros, but docs make no mention of macros and using SASM macros doesn't work, are macros availible?

Comments

  • PJMontyPJMonty Posts: 983
    edited 2005-05-04 05:02
    Paul,

    I don't believe that macros are available in SX/B. I'm curious about how big/complicated your project is that you want to use macros on it. Is it already well decomposed into logical functions? Have you considered breaking parts of the program into separate source files? I think the keyword is "Load" which lets you include other source files into a project. That could help break the bulk of the program's source listing into a collection of smaller, more readable source listings.
      Thanks, PeterM
  • BeanBean Posts: 8,129
    edited 2005-05-04 10:52
    Paul,
    You should be able to use macros with-in ASM..ENDASM blocks.
    Also Peter is correct LOAD will load in an external sxb file and INCLUDE will load in an external src file.
    Could you give an example of what you want to do ?
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video Display Module" Available Now.

    www.sxvm.com

    "I thought I was wrong once...But I was mistaken [noparse];)[/noparse]"
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-04 13:27
    Again, let me state the Parallax position that SX/B is designed as a learning tool; it will never have all the fancy features of a compiler that you'd actually have to pay for. I know this won't make some happy, but that's the position we've taken with this product. And no, we have not plans to retool it and charge for it. Our goal is educational, and as the SX contest clearly pointed out, clever programmers are doing really neat things with SX/B -- despite any perceived limitations.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-05-04 15:54
    Its ok, I didn't need macros, I can get along fine without them. My program is programming another microcontroller via SPI using 4 byte command sequences, my code ends up looking like:

    SPI_CMD(0) = $A4
    SPI_CMD(1) = $53
    SPI_CMD(2) = $00
    SPI_CMD(3) = $00
    GOSUB Send_SPI

    I was hoping to define a macro something like

    macro SPI_String 4
    SPI_CMD(0) = \1
    SPI_CMD(1) = \2
    SPI_CMD(2) = \3
    SPI_CMD(3) = \4
    GOSUB Send_SPI
    endm

    then define the following

    Program_Enable CON "($A4, $53, $00, $00)"

    So I can declare in my code:

    SPI_String Program_Enable

    which is more readable than the original code, but like I said its no biggie.

    One final question, does string constant substitution occur in ASM blocks or does SX/B pass ASM blocks straight to SASM without preprocessing the block?


    Post Edited (Paul Baker) : 5/4/2005 3:59:35 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-04 16:18
    It seems like SX/B (1.21)·is already structured to do what you want to do.· Couldn't you do something like this:

    Declare the subroutine:

    SEND_SPI··· SUB··· 1, 4

    Here's the subroutine code:

    SEND_SPI:
    · spiCmd(0) = __PARAM1
    · spiCmd(1) =·__PARAM2
    · spiCmd(2) = __PARAM3
    · spiCmd(3) = __PARAM4

    · DEC __PARAMCNT
    · DO WHILE __PARAMCNT > 0
    ····dataOut = spiCmd(__PARAMCNT)
    ··· ' send it
    ··· DEC __PARAMCNT
    · LOOP·
    · RETURN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA


    Post Edited (Jon Williams) : 5/4/2005 4:22:32 PM GMT
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-05-04 16:34
    Aha, thanks Jon, haven't completely explored subroutines in SX/B yet, I was unaware they supported parameters, that will work nicely.
  • BeanBean Posts: 8,129
    edited 2005-05-04 16:54
    Actually you can't use __PARAMCNT like that. It is the most volitile parameter, any array access will destroy it, and it should be considered READ-ONLY. You MUST store it in a regular variable as the first operation in the subroutine.

    Somthing like:

    SEND_SPI:
    Count=__PARAMCNT
    spiCmd(0) = __PARAM1
    spiCmd(1) = __PARAM2
    spiCmd(2) = __PARAM3
    spiCmd(3) = __PARAM4
    DEC Count
    DO WHILE Count > 0
    dataOut = spiCmd(Count)
    ' send it
    DEC Count
    LOOP
    RETURN

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video Display Module" Available Now.

    www.sxvm.com

    "I thought I was wrong once...But I was mistaken [noparse];)[/noparse]"
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-04 17:33
    That's what I get for writing code on the fly! nono.gif· Hopefully, though, users new to SX/B will get the message that there's more under its hood than what appears at first blush.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-05-05 22:18
    Jon, (or anyone else for that matter) can you explain the declaration of a subroutine's syntax? I couldn't find it in the docs.

    SEND_SPI SUB 1, 4

    Im guessing the 4 is the number of parameters passed, what is the 1 for?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-05 22:28
    SUB is part of version 1.2x -- you can get it here:

    http://forums.parallax.com/showthread.php?p=517621

    You'll find SUB in Reference\Definitions.· Quickly, the first parameter is the minium number of parameters required (if any), the second parameter is the maximum number of parameters allowed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
Sign In or Register to comment.