In an assignment we are to use a specific algorithm to find the greatest common divisor in assembly, written in assembly.
The algorithm is as follows:
Input:a,b
Local: c
While a <> b
While a > b
c = a - b
a = c
End While
While b > a
c = b - a
b = c
End While
End While
At this point, GCD(a,b)=a=b.
What does a <> b mean in the third line?
!= means "is not equal to". A minus before a variable means 0 minus that variable. For example, -a means (0 - a) . The << operator in the pseudocode is a bitwise left shift, with both sides of the operator being integers.
Words such as set, reset, increment, compute, calculate, add, sum, multiply, ... print, display, input, output, edit, test , etc. with careful indentation tend to foster desirable pseudocode.
Using For Loops Say we wanted to loop through a block of code 5 times, we use i, a local variable, that is built into most programming languages, and can be used in pseudocode too. We would say: For i = 1 To 5; 5 being the number of times you want to loop the code; you can change this to what you would like.
Assigning a value to a variable is indicated in pseudocode using an arrow symbol (←). The arrow points from the value being assigned towards the variable it is being assigned to.
In certain old languages, the <>
operator meant "not equal" (you can see it as "less than or greater than"). The convention !=
has largely taken over nowadays.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With