Skip to content

Add push/pop asm_xtensa convenience functions #2893

@ARF1

Description

@ARF1

It would be nice if asm_xtensa were to provide push/pop convenience functions for saving/restoring registers.

In asm_thumb one can write very clean code (ignoring the wrong register names for illustration purposes):

@micropyhton.asm_thumb():
def foo():
    push({a5, a6, a7, a8, a9, a10, a11})
    # do your stuff
    push({a5, a6, a7, a8, a9, a10, a11})

The same with asm_xtensa is a nightmare to write and easy to mess up:

@micropyhton.asm_thumb():
def foo():
    # calculate stack pointer to make space for registers
    # but: must be in multiples of 16!
    addi(a1, a1, -32)
    # store registers
    s32i(a5, a1, 0)
    s32i(a6, a1, 4)
    s32i(a7, a1, 8)
    s32i(a8, a1, 12)
    s32i(a9, a1, 16)
    s32i(a10, a1, 20)
    s32i(a11, a1, 24)

    # do your stuff

    # restore registers
    l32i(a5, a1, 0)
    l32i(a6, a1, 4)
    l32i(a7, a1, 8)
    l32i(a8, a1, 12)
    l32i(a9, a1, 16)
    l32i(a10, a1, 20)
    l32i(a11, a1, 24)
    # move stack pointer back
    addi(a1, a1, 32)

And here I am not even checking for stack underflow/overflow!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions