ebmDevMag.com home
ebm Developer's Magazine
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


7 - The Inner Loop

Now for the function's core:
.k_loop

    ; get pointer to byte into r5, based on k & i
    rptr r6 ; r5 <- array+(k>>4)
    ldc  4
    lsrt rp ; t <- k>>4
    rptr r0
    add  rp
    mov  t,r5

    ; get bitvalue into r4 & set it
    mov  r6,t ; r4 <- (k>>1)&7
    lsr  t
    mov  t,r4
    ldc  7
    and  rp
    mov  t,r4

    ; shift r4: r4 <- 1<<r4
    ldc  1
    mov  t,r3
    mov  r4,t
    lslt rp
    mov  t,r4

    ; load and adjust byte pointed to by r5: [r5] <- [r5] | r4
    mov  r5,t
    mov8 (t),r3
    mov  r4,t
    or   rp
    mov  t,r4
    mov  r5,t
    mov8 r4,(t)

This code sets the bit representing the current number (k/r6) in the bit array.

One interesting feature of this code is the lack of the rptr instruction. Often it appears the rp operand is used with no idea what register is referenced. In fact, some instructions have as a side effect the changing of the RPTR value, allowing you to perform an action as well as set up for the next rp operation. To find out all the commands that affect RPTR consult the SNK32 Processor Manual in the Franklin SDK, but the more useful ones are the moves to/from t involving rN (which sets RPTR to the rN index value), and unconditional branching (which sets it to 8). The sole exception to the mov-rN group is mov rN,t which doesn't change RPTR (although mov8 rN,(t), mov16 rN,(t) and mov32 rN,(t) do).

Notice also the mov8 instructions for memory reading and writing - you can move 16 or 32 bits at a time as well, but since we are twiddling individual bits, this suffices. However, if you were writing a custom memory fill, you might find mov32 useful, since it moves 4 times the memory in the same single cycle (the beauty of RISC!)


Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice