Shop OBEX P1 Docs P2 Docs Learn Events
CALL and RET — Parallax Forums

CALL and RET

Hallo,

I have a short question:

What is wrong in this ASM code segment? I use the PARALLAX EDITOR/ DEVELOPMENT-System Version 1.3.2

.....
call #mark1

.. do something in ASM code

call #mark1
....



' Routine for call

mark1 nop
mark2 ret

--> Error sign: undefined ?_RET symbol

Thanks for your help.
Heiko

Comments

  • Mark_TMark_T Posts: 1,981
    edited 2019-02-28 14:14
    You haven't provide a return label of the correct form.
            call #mark1
    
    .. do something in ASM code
    
            call #mark1
    ....
    
    
    
    ' Routine for call
    
    mark1 nop
    mark1_ret ret  ' correct label so the call/return mechanism can function.  This instruction is overwritten by each call
    
  • Thanks it run!
    It was my mistake!
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2019-02-28 21:55
    Welcome to the forums ondel,

    The reason for the special form of return label is because there is no call stack in the Propeller chip but instead it uses a jump instruction that modifies the _ret labelled instruction to jump back to the correct spot. Read about CALL in the Assembly Language Reference section of the Propeller manual for a better understanding.

    Here though is an excerpt from it:
    CALL records the address of the next instruction (PC + 1) then jumps to Symbol. The routine
    at Symbol should eventually execute a RET instruction to return to the recorded address
    (PC+1; the instruction following the CALL). For the CALL to compile and run properly, the
    Symbol routine’s RET instruction must be labeled in the form Symbol with “_ret” appended to
    it. The reason for this is explained below.
    Propeller Assembly does not use a call stack, so the return address must be stored in a
    different manner. At compile time the assembler locates the destination routine as well as its
    RET instruction (labeled Symbol and Symbol_ret, respectively) and encodes those addresses
    into the CALL instruction’s s-field and d-field. This provides the CALL instruction with the
    knowledge of both where it’s going to jump to and exactly where it will return from.
    At run time the first thing the CALL instruction does is store the return address (PC+1) into the
    location where it will return from; the “Symbol_ret RET” instruction location.
    The RET instruction is really just a JMP instruction without a hard-coded destination address, and this
    run-time action provides it with the “return” address to jump back to. After storing the return
    address, CALL jumps to the destination address; Symbol.
Sign In or Register to comment.