Reputation: 21
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
Upvotes: 0
Views: 186
Reputation: 74
&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).
Upvotes: 2