Assembly Language FOR

From TRCCompSci - AQA Computer Science
Revision as of 10:29, 22 January 2020 by Admin (talk | contribs)
Jump to: navigation, search

C# example

for (int i=0; i < 10; i++)
{

}

Assembly Version

   MOV R0, #0
   MOV R1, #10
start:
   CMP R0, R1
   BEQ end
   BGT end
   ADD R0, R0, #1
doCodeHere:
   B start
end:

Line 1 sets the value of Register 0 to the value 0. i.e. i in the C# code.
Line 2 sets the value of Register 1 to the value 10. i.e. the condition to continue in the C# code.
Line 3 is the .start label.
Line 4 compares the value in Register 0 with the in Register 1.
Line 5 we branch to the end if equal to.
Line 6 we branch to the end if greater than.
Line 7 adds the value 1 to the current value in Register 0 and stores the value back into Register 0.
Line 8 a label to show where the code inside the for loop will go.
Line 9 will branch to the .start label.
Line 10 is label for the .end of the program.