How to Pop From a Stack Using Loop in LEGv8 Assembly Language

  Kiến thức lập trình

So I’m supposed to push into and pop from a stack using LEGv8 Assembly Language. I think I’ve managed to push using loop but I can’t figure out how to pop using a loop.

SUBI    SP, SP, #48
    ADDI    X9, X9, #1
    ADDI    X26, X26, #0
    ADDI    X10, X10, #0
LOOP:
    SUBI    X11, X10, #6
    CBZ X11, POP
    LSL X12, X26, #3
    ADD X12, X12, SP
    STUR    X9, [X12, #0]
    ADDI    X9, X9, #1
    ADDI    X26, X26, #1
    ADDI    X10, X10, #1
    B   LOOP
POP:
    MOV X26, XZR
    LSL X12, X26, #3
    ADD X12, X12, SP
    LDUR    X19, [X12, #40]
    LDUR    X20, [X12, #32]
    LDUR    X21, [X12, #24]
    LDUR    X22, [X12, #16]
    LDUR    X23, [X12, #8]
    LDUR    X24, [X12, #0]
    ADDI    SP, SP, #48

    B   HALT
HALT:

This is my code and my main issue is I’m not sure how to pop without changing temporary registers in a loop (For example x19 x20 etc).

New contributor

Melih is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

LEAVE A COMMENT