lundi 28 septembre 2015

SPARC Assembly Condition Statement

I have this bit of code

swap:

        cmp     %min_r, %y_r    !comparing the minimum

        bg      last            !If result is greater than 0, skip

        nop

        mov     %y_r, %min_r    !branch execution

last:

        add     %x_r, 1, %x_r   !x++

        cmp     %x_r, -1        !comparing x

        bg      loop            !go back to loop

        nop                     !delay slot

        mov     1, %g1

        ta      0

Which technically should move the minimum value if needed, and then jump to last to do the increment and quit the program if needed.. However, if I don't put the labels in and get rid of swap label and it's contents, and also get rid of label last, the increment works perfect and either jumps back to loop or exits. However, once I add the swap in it gives me an error of a "recursive infinite loop"

Here is what gdb says

0x106d4 <loop+92>:      cmp  %l1, %l2  <--- Here I am comparing my current minimum with the y value

(gdb) ni

0x000106d8 in loop ()

1: x/i $pc

0x106d8 <loop+96>:      bg  0x106e4 <last>  

0x106dc <loop+100>:     nop 

(gdb) ni

0x000106dc in loop ()

1: x/i $pc

0x106dc <loop+100>:     nop <---- followed right after by this nop, but instead of jumping to either last or executing the swap, the program exists

(gdb) ni



Program exited with code 0354.

(gdb) 

The program is not being run.

(gdb) 

I followed the example from the book and from the notes I took, and for some reason it's not working, I can't seem to spot the bug...Any suggestions?

Aucun commentaire:

Enregistrer un commentaire