Sparc 汇编调用损坏数据
我目前正在处理 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于调用 println 肯定不是 NOP,这是一个奇怪的评论:
我不是 Sparc 汇编方面的专家,但看到这个我想知道是否
call
/jmp
有所谓的“延迟槽”,因此分支后面的指令会在分支生效之前执行。他们这样做:http://moss.csc.ncsu .edu/~mueller/codeopt/codeopt00/notes/delaybra.html
那么您是否注释掉了实际上是有目的的 NOP 操作,因为它们试图填充延迟槽?
Since calling
println
is certainly not a NOP, this is a strange comment: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?
我注意到我忘记将保存的大小从 96 增加到 104,然后它就像一个魅力一样工作:
而不是 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:
Instead of 96 in the go function..