gpt4 book ai didi

assembly - Sparc 程序集调用损坏数据

转载 作者:行者123 更新时间:2023-12-04 06:52:30 25 4
gpt4 key购买 nike

我目前正在使用 Sparc 处理器系列的一些汇编代码,但我在处理一段代码时遇到了一些麻烦。我认为代码和输出解释了更多,但简而言之,这是我的问题:

当我调用函数时 println()我写入 %fp - 8 的变量内存位置被破坏。这是我试图运行的汇编代码:

    !PROCEDURE main
.section ".text"
.global main
.align 4
main:
save %sp, -96, %sp

L1:
set 96, %l0
mov %l0, %o0
call initObject ; nop
mov %o0, %l0
mov %l0, %o0
call Test$go ; nop
mov %o0, %l0
mov %l0, %o0
call println ; nop
L0:
ret
restore
!END main

!PROCEDURE Test$go
.section ".text"
.global Test$go
.align 4
Test$go:
save %sp, -96, %sp

L3:
mov %i0, %l0
set 0, %l0
set -8, %l1
add %fp,%l1, %l1
st %l0, [%l1]
set 1, %l0
mov %l0, %o0
call println ; nop
set -8, %l0
add %fp,%l0, %l0
ld [%l0], %l0
mov %l0, %o0
call println ; nop
set 1, %l0
mov %l0, %i0
L2:
ret
restore

!END Test$go

这是 println 代码的汇编代码
    .global println
.type println,#function
println:
save %sp,-96,%sp

! block 1
.L193:

! File runtime.c:
! 42 }
! 43
! 45 /**
! 46 Prints an integer to the standard output stream.
! 47
! 48 @param i The integer to be printed.
! 49 */
! 50 void println(int i) {
! 51 printf("%d\n", i);

sethi %hi(.L195),%o0
or %o0,%lo(.L195),%o0
call printf
mov %i0,%o1
jmp %i7+8
restore

这是我运行这段汇编代码时得到的输出
1

67584

1

如您所见,位于 %fp - 8 的数据已被摧毁。拜托,所有的反馈都是apprecated。

最佳答案

自调用 println肯定不是 NOP,这是一个奇怪的评论:

call println ; nop
set -8, %l0
add %fp, %l0, %l0

我不是 Sparc 组装方面的专家,但看着这个我想知道 call/ jmp具有所谓的“延迟槽”,因此分支后的指令在分支生效之前执行。他们这样做:

http://moss.csc.ncsu.edu/~mueller/codeopt/codeopt00/notes/delaybra.html

那么您是否注释掉了实际上是有目的的 NOP 操作,因为它们试图填充延迟槽?
call println
nop
set -8, %l0
add %fp, %l0, %l0

关于assembly - Sparc 程序集调用损坏数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2922958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com