Example - 09param.asm Write a procedure that doubles a number. Pass the single parameter into the procedure using a register. Use the same register to return the result.
Write a procedure to invert all the bits in a byte. All the zeros should become ones. All the ones should become zeros. Pass the value to be processed into the procedure using a RAM location. Return the result in the same RAM location.
Write a procedure that works out Factorial N. This example shows one method for working out factorial N. Factorial 5 is 5 * 4 * 3 * 2 * 1 = 120. Your procedure should work properly for factorial 1, 2, 3, 4 or 5. Factorial 6 would cause an overflow. Use the stack to pass parameters and return the result. Calculate the result. Using a look up table is cheating!
Write a procedure that works out Factorial N. Use the stack for parameter passing. Write a recursive procedure. Use this definition of Factorial.
Factorial ( 0 ) is defined as 1.
Factorial ( N ) is defined as N * Factorial (N - 1).
To work out Factorial (N), the procedure first tests to see if N is zero and if not then re-uses itself to work out N * Factorial (N - 1). This problem is hard to understand in any programming language. In assembly code it is harder still.