Analyzing SPARC assembly
 
Contents
  Introduction
Synthetic
Delay slots
Conditionals
Branches
Final
References
 
Phase #5: Final

Now the code is prepared for easier analysis. The control flow is less complex, there are fewer (or no) unused opcodes and labels and no more stateful conditional codes handling.

At this stage, high level language constructs are ready to be detected.

Final sample
 
    .section ".rodata1",#alloc
    .align  4

.l0:
    .asciz  "%u %u\n"

    .section ".text",#alloc,#execinstr
    .align  4

    .global main
main:
    save    %sp,-96,%sp
    set     .l0,%i0
    mov     1,%i1
    clr     %o1
    mov     1,%o0
    clr     %i2
.l1:
    cmp     %i1,1
    be      .l7
    nop
.l2:
    srl     %o0,1,%g2
    btst    1,%o0
    bne     .l3
    nop
    inc     %i2
    srl     %o0,1,%o0
    ba      .l4
    nop
.l3:
    add     %o0,%g2,%g2
    inc     2,%i2
    add     %g2,1,%o2
    cmp     %o2,%o0
    bcs     .l6
    nop
    mov     %o2,%o0
.l4:
    cmp     %o0,1
    bne     .l2
    nop
.l7:
    cmp     %i2,%o1
    bgu     1f
    nop
    inc     %i1
    ba      .l9
    nop
1:
    mov     %i0,%o0
    mov     %i1,%o1
    mov     %i2,%o2
    call    printf
    nop
    inc     %i1
    mov     %i2,%o1
.l9:
    mov     %i1,%o0
    clr     %i2
    ba      .l1
    nop
.l6:
    restore %g0,0,%o0
    retl
    nop
    .type   main,2
    .size   main,(.-main)
Next

What's next?

A next step is to identify code repetitions which are introduced by optimizers to e.g. minimize branches or work around inefficiencies in loop entry, and also to duplicate delay slot operation into the first iteration.

Now seems to be the right time for a flow chart for further code analysis.

References

The SPARC Architecture Manual, Version 8, SPARC International, Prentice Hall, 1992


code repetitions: Identifying them can be a costly thing since the (high level programming language) optimizers usually both expand special cases (i.e. take them out of loops) and make checks for special cases that are not obvious to the high level programmer.

   previous
 
Copyright © 1999 Eric Laroche December 19, 1999