| home | |||
|
|||
| links |
|
||
|
developer's mag main page article part 1 part 2 part 3 part 4 part 5 part 6 part 7 part 8 part 9 |
8 - Tidying UpThe final part of the code adjusts k/r6 and i/r7 and checks for loop completion. For i, the test in the C code was against limit/3, but we adjust it in the assembly version, since it's easier to calculate i*3, or i+i+i, than it is to calculate limit/3:
; loop tests and branching
; adjust k - r6=r6+r7+r7 (k=k+i+i)
mov r6,t
rptr r7
add rp
add rp
mov t,r6
; test for end of k loop
rptr r1
sub rp
ldo .k_loop
blt
nop
; inc r7/i - i=i+2
rptr r7
inc2 rp
; test r7/i * 3 against r1/limit
add rp
add rp
rptr r1 ; test: i*3-limit/r1
sub rp
ldo .i_loop
blt
nop
");
}
Notice how the ldo macro is used to calculate the offset for the blt branches. The function ends with the assembler directive closing brace, and the regular function ending. The compiler places the appropriate code in place so that the function can be called normally. The nop codes after each branch aren't typos - according to Franklin, a nop is needed after all branches in order to fill the delay slot. However this is not necessarily a wasted cycle, as the compiler is smart enough to optimize it out if it is deemed unneeded. Previous Section Next Section |
||
| Copyright © 2001-2006 ebmDevMag.com - Legal Notice | |||