Sparc 汇编调用损坏数据

发布于 2024-09-03 09:02:39 字数 1584 浏览 0 评论 0原文

我目前正在处理 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 已被破坏。请接受所有反馈。

I am at the moment working with some assembler code for the Sparc processor family, and i am having some trouble with a piece of code. I think the code and output explains more, but in short, this is my problem:

When i do a call to the function println() the variables that i have written to the %fp - 8 memory location are destroyed. Here is the assembler code that i am trying to run:

    !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

Here is the assembler code for the println code

    .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

This is the out put i get when i run this piece of assembler code

1

67584

1

As u can see, the data that is located at %fp - 8 has been destroyed. Please, all feedback is aprecated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

行雁书 2024-09-10 09:02:39

由于调用 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

Since calling println is certainly not a NOP, this is a strange comment:

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

I'm no expert in Sparc assembly but looking at this I wondered if call/jmp have what are called "delay slots", so the instruction following the branch is executed before the branch takes effect. And they do:

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

So did you comment out NOP operations that were actually purposeful, because they were trying to fill the delay slot?

call println
nop
set -8, %l0
add %fp, %l0, %l0
以往的大感动 2024-09-10 09:02:39

我注意到我忘记将保存的大小从 96 增加到 104,然后它就像一个魅力一样工作:

save %sp, -104, %sp

而不是 go 函数中的 96..

I noticed that I had forgoten to incease the size of the save from 96 to 104, and then it worked like a charm:

save %sp, -104, %sp

Instead of 96 in the go function..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文