The control flow graph tool can be invoked with the -action=cfg option to Avrora. It can generate output in one of two formats: a text-based straight-line representation of each basic block with successors listed at the end of the code for each block, and as a textual format supported by the dot graph rendering tool that is freely available. These two output formats can be selected with the -output option.
;-------------------------------------------------------------- ; example.asm: Example program for control flow graph utility ;-------------------------------------------------------------- start: jmp begin ; entrypoint of program .org 0x80 ; skip interrupt table bad_interrupt: reti begin: ; begin main program call wait ; wait before we get started ldi r17, 1 ldi r18, 2 ldi r19, 1 ldi r20, 10 loop: ; beginning of fibonacci loop mov r21, r17 add r21, r18 mov r17, r18 mov r18, r21 inc r19 ; increment trip count cpi r19, 10 breq again ; do it again? jmp loop again: call wait ; wait for a little bit call wait ; wait again jmp begin ; do it again wait: ldi r16, 1 inc r16 cpi r16, 0 brne wait ret
After rendering with dot, the finished product will look like this:
Each node represents a basic block of instructions. The square nodes are places that can be entered from an interrupt (i.e. the interrupt handler table). Double octagon nodes are the entrypoints of procedures. Hexagonal nodes are basic blocks that end with a return or return-from-interrupt instruction. Normal edges correspond to normal control flow such as jumps, branches, and fall-throughs. Red edges correspond to call edges. Dotted edges correspond to indirect calls or jumps within the program.
By default, the control flow graph utility attempts to use the call instructions to determine the entrypoints into procedures and then tries to group basic blocks into procedures and then color them. This functionality can be adjusted with the options available to the control flow graph utility. For more information on the cfg action, see the online help.