Sparc Assembly Call corrupts data
Posted
by Sigge
on Stack Overflow
See other posts from Stack Overflow
or by Sigge
Published on 2010-05-27T16:31:21Z
Indexed on
2010/05/27
17:01 UTC
Read the original article
Hit count: 173
I am at the moment working with some assembler code for the Sparc processor family, and i am having some truble with a piece of code.. I think the code and output explains more, but in the short..
When i do a call to the function println my varaibels that i have written to the %fp - 8 memory location is destoryed.. here is my 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 apritiated
© Stack Overflow or respective owner