This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Assembler Jumptable and stack question.

Hi,

Im using the STM32F103ZE uC.

I wrote an assembler function calling it from C (vS00StmJmp(x)) with one argument representing an index in a jumptable. The assembler function then jumps to the selected C-function.

;------------------------------------------------------------
vS00StmJmp

;       push r3                 ; save used register r3 on stack
        adr r3, JumpTable000    ; store jump-table start address in register r3
        cmp r0, #nLstJmpNum     ; check requested jump table entry number
        ble lblRunJmp           ; on valid number then jump to table jump execution
        mov r0, #0              ; on invalid number, select table record #0
lblRunJmp                       ; destination label
        LDR pc, [r3,r0,LSL#2]   ; jump to address in r3 with offset in r0 with offset-size 4 (LSR#2)
;------------------------------------------------------------

As one argument is used which is automaticaly tranferred by register R0 I assume the compiler will take care of the correct handling of this register. But the assembler function uses register R3 so I asume I must prepair to return the previous value back into R3 when exiting from the jump. But how can I achieve this as a jump is executed to the selected C-function. Should I somehow execute an assembler function after executing vS00StmJmp(x) which pops R3 back from stack (after having in pushed on stack in the first line of my assembler code?)

Just let me know...Thanks

Henk

  • But how can I achieve this as a jump is executed to the selected C-function.

    If you can't figure that out by yourself, I think you shouldn't be trying to do this. You're buying yourself considerably more trouble than benefit.

    Write that code in C and be done with it. Any modern compiler worth its salt is able to pull this off by itself with just a little incentive from your end. Either spell it out as a switch with densely packed case numbers that the compiler will almost certainly compile into a jump table, or set up an array of function pointers that you index directly.