tags:

views:

74

answers:

2

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

+2  A: 

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
Hostile Fork
Thx for the tip, i tried it out, but i am still getting the same error.. i have worked out that %fp - 4 is ok, but everything after that is destroyed..
Sigge
+1  A: 

Thx for the tips, but 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..

//Thx

Sigge