Assembly Language WHILE

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

C# example

int a = 0;
while ( a != 99)
{
    a++
}

Assembly Version

   MOV R0, #0
while:
   CMP R0, #99
   BNE loop
   HLT
loop:
   ADD R0, R0, #1
   B while


Line 1 sets the value of Register 0 to the value 0.
Line 2 is a label which will be used to branch too.
Line 3 compares the value in Register 0 with the value 99.
Line 4 will branch to the .loop label if the previous compare was NOT EQUAL.
Line 5 halt because condition met
Line 6 is a label which will be used to branch too.
Line 7 increment the register used for a counter.
line 8 will branch to the .while label to recheck the condition of the loop.