我目前正在使用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
的數據已被銷燬。請所有反饋意見都是贊成的。
Thx的提示,我試了一下,但我仍然得到同樣的錯誤..我已經計算出%fp - 4是好的,但之後的一切都被破壞.. – Sigge 2010-05-27 17:14:37