【问题标题】:Assembly: Loop to pop up from Stack装配:循环从堆栈中弹出
【发布时间】:2013-11-01 23:32:50
【问题描述】:

我在组装 MIPS 中搞乱堆栈推送和弹出。我只能通过更改指针的索引手动从堆栈$sp 中弹出数据,但是如何使用循环来做到这一点?

例子:

lw $t1, 0($sp) ## pops the first data at index 0
lw $t1, 4($sp) ## pops the second data at index 4
lw $t1, 8($sp) ## pops the third data at index 8
addui $sp, $sp, 12 ## Lets free our stack

现在我的问题是,如何循环执行此操作?如果我使用以下

addui $sp, $sp, 4 这意味着在我们的堆栈中释放 1 个空间。这并不意味着将堆栈指针递增到下一个索引。

我希望你们能明白我在这里想说的话。

我认为这里不允许使用 $t2 lw $t1, $t2($sp)

【问题讨论】:

  • 我不明白这个问题。首先,那些lws 不会“弹出”堆栈,它们从堆栈中加载

标签: assembly mips


【解决方案1】:

addiu $sp, $sp, 4 确实意味着将堆栈指针增加 4(这是一个字的大小)。如果你想要一个循环,你可以这样做:

    li $t0, 3            # loop counter
loop:
    lw $t1, 0($sp)       # load top of stack
    addiu $sp, $sp, 4    # free top of stack
    # ...                # do something with $t1
    addiu $t0, $t0, -1   # decrement loop counter
    bgtz $t0, loop       # repeat if not 0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-11
    • 2014-12-19
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 2013-10-02
    • 2018-04-12
    • 2016-11-17
    相关资源
    最近更新 更多