0

I am determining if a number is zero in my function. If it is zero I need to pass some string like "Is Zero" into the variable I have declared as B. My function to determine if it is zero works but when I try to pass the string into the variable B with my SPARC source code I seg fault.

Here is what I have been trying in my C driver:

void display( double, char* );   
char B[100];
double x = 0.000;
display(x, &B);

printf("%s", B);

Here is my SPARC code:

 ZERO: .asciz "Is Zero\n"



.global display
.section ".text"
.align 4
display:    
         save   %sp, -96, %sp


         mov    %i0, %o0
         mov    %i1, %o1
         mov%i2, %o2

         call   is_zero         ! check if number is zero
         cmp    %o0, 0
         bne    zero
         nop


zero:
        save    %sp, -96, %sp
        set     ZERO, %l0
        ldub    [%l0], %l1
        cmp     %l1, 0          ! exit when zero byte reached
        beq     done
        nop
        stb     %l1, [%i2]
        inc     %l0
        inc     %i2

        ba      zero
        nop
done:
        ret
        restore
Alfred
  • 21
  • 4

1 Answers1

2

&B is the pointer to char array B. display function take a char pointer in 2nd parameter. display(x, &B) should be display(x, B).

bkyee
  • 74
  • 5
  • That removes my "passing arg 2 of `classify' from incompatible pointer type" warning when I compile my code but it does not solve the seg fault. – Alfred Nov 06 '14 at 03:22
  • @Alfred, I propose you write the `display` function in C to test your program. After that, you may convert the `display` function to assembly language. – bkyee Nov 07 '14 at 06:56