Difference between revisions of "Assembly Language IF"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Assembly Version)
Line 1: Line 1:
 
==C# example==
 
==C# example==
 
<syntaxhighlight lang=csharp>
 
<syntaxhighlight lang=csharp>
int a = 0;
+
int y = 0;
do
+
int x;
 +
if (y == 10)
 
{
 
{
     a++
+
     x = 9;
 
}
 
}
while ( A != 99);
+
else
 +
{
 +
    y++
 +
}
 +
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Revision as of 09:44, 16 June 2017

C# example

int y = 0;
int x;
if (y == 10)
{
    x = 9;
}
else
{
    y++
}

Assembly Version

   LDR R0, #0
.loop
   ADD R0, R0, #1
   CMP R0, #99
   BNE .loop

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 adds the value 1 to the current value in Register 0 and stores the value back into Register 0.
Line 4 compares the value in Register 0 with the value 99.
Line 5 will branch to the .loop label if the previous compare was NOT EQUAL.