0

Hi this is for Sparc Assembly Language and I have a loop with a counter to keep track of how many cycles it's looping through. How can I have it check that counter if it is multiples of 4 to print "blah blah blah" and so on. So at counts 4,8,12,16,20.....etc it should print that statement "blah blah blah". What is the most efficient way and easiest to understand since I am a beginner. Thanks.

Ruud Helderman
  • 10,563
  • 1
  • 26
  • 45
Selena Gomez
  • 69
  • 1
  • 7

1 Answers1

0

Following your own example of 4... What you want, can be achieved by dividing the counter by 4 on every loop iteration. Print the message only when the remainder of that division is zero.

Since 4 is a power of 2, there is an efficient alternative, based on the fact that the rightmost (i.e. least significant) bits of counter (its binary representation) become 00 every four steps. Just take the bitwise 'and' of counter and 3 (= 4 - 1); print the message if the result is zero.

I have no Sparc experience, so here goes nothing:

    and  %L1,3,%g0      ; assuming register %L1 is the counter
    bne  PastMessage    ; skip the call below if result of 'and' was not zero
    call PrintMessage
PastMessage:
    ...
Ruud Helderman
  • 10,563
  • 1
  • 26
  • 45