Shop OBEX P1 Docs P2 Docs Learn Events
Example for SCAS instruction ? — Parallax Forums

Example for SCAS instruction ?

Hi,
it would be very helpful for me to have some example code for the SCAS instruction.
"Next instruction's S value = signed (D[15:0] * S[15:0]) >> 14. In this scheme, $4000 = 1.0 and $C000 = -1.0. *"
So I don't need to specify the S for the next instruction or will it be overwritten?
Many thanks!

Comments

  • AribaAriba Posts: 2,690

    SCAS allow multiply and accumulate in 2 instructions. Such MAC instructions are used alot in DSP applications.
    Accu = Accu + (x * y) >> 14 translates in PASM to these instructions:

        scas  x,y
        add   accu,0-0
    
    

    0-0 gets replaced with the result of the scaled multiplication (inside the pipeline of the CPU, not in cogram, it works like the ALTx instructions).
    The advantage of this is: x and y are not affected, you can have many different accumulators, and you can also use SUB or MOV instead of ADD. Other processors need alot of different DSP instructions to reach this flexibelity.

    Andy

  • evanhevanh Posts: 16,027
    edited 2021-09-18 14:13

    It's just dawned on me that the prefixing mechanism here is different to what ALTS does. It is replacing the operand of the next instruction at the ALU rather than replacing the S field of the next instruction.

    Then what happens if the next instruction uses immediate addressing for S field? I'm guessing it makes no difference to the result ...

  • TonyB_TonyB_ Posts: 2,193
    edited 2021-09-19 12:32

    @Ariba said:
    SCAS allow multiply and accumulate in 2 instructions. Such MAC instructions are used alot in DSP applications.
    Accu = Accu + (x * y) >> 14 translates in PASM to these instructions:

        scas  x,y
        add   accu,0-0
    
    

    0-0 gets replaced with the result of the scaled multiplication (inside the pipeline of the CPU, not in cogram, it works like the ALTx instructions).

    @evanh said:
    It's just dawned on me that the prefixing mechanism here is different to what ALTS does. It is replacing the operand of the next instruction at the ALU rather than replacing the S field of the next instruction.

    Then what happens if the next instruction uses immediate addressing for S field? I'm guessing it makes no difference to the result ...

    SCA/SCAS/XORO32 should all work the same way. If reg/immediate opcode bit is ignored in next instruction for these three, unlike ALTx, then doc should say so explicitly.

  • TonyB_TonyB_ Posts: 2,193
    edited 2021-09-19 12:31

    deleted

  • evanhevanh Posts: 16,027

    Chip has worded it as such. It just wasn't obvious because he's used a somewhat vague "value" term instead of calling it the "operand". I'm guessing he wanted to avoid using the technical term to reduce the learning curve.

  • evanhevanh Posts: 16,027

    Okay, well, just tested the earlier question ... and the answer is # matters. With # you just get the immediate number. The SCA result vanishes.

  • TonyB_TonyB_ Posts: 2,193
    edited 2021-09-19 12:46

    @evanh said:
    Okay, well, just tested the earlier question ... and the answer is # matters. With # you just get the immediate number. The SCA result vanishes.

    To be clear then, do not put # before S in next instruction after SCA/SCAS/XORO32.

  • Thanks, everybody!
    It is very helpful for me, to know, how it should work. :)

Sign In or Register to comment.