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


5 - Onto the Code!

Now with all the necessary opcodes under our belt, let's look at our assembly version of the Sieve:
void AssemblySieve(unsigned char *array,int limit)
{
  asm("

    ldc 3 ; init i/r7
    mov t,r7

.i_loop ; label format for our jump

The top of our function shows how we place assembly code into a standard function. The function passes a bitflag array pointer, and a limit on the numbers tested. For simplicity, we pass the array already zeroed, and our code simply sets appropriate bits for the composite numbers.

Notice several things:

  • Semicolons are used only for comments, and not to end instructions.
  • Lowercase is used for all instructions and registers.
  • asm(" introduces the assembly code, while "); at the function's end concludes it.
  • .i_loop is a label - this will be the destination of our outer loop's branch.


Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice