简体   繁体   中英

Seg Faulting SPARC Assembly

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

&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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM