CSC231 Homework 6 2014
--D. Thiebaut (talk) 18:42, 4 November 2014 (EST)
This homework assignment is due on Tuesday, Nov 11, at 11:55 p.m.
Note: All problems are similar to the problems of Homework 5, with the exception of a few important details:
- All the functions must return their result in the stack, and not eax.
- All the functions must save all the registers they modify.
- The functions that compute the sum of the series x + (x-1) + (x-2) + ... + 2 + 1 must do so recursively.
Problem #1
Write a program called Hw6_1.asm that contains 1 function called f1 that will compute f1( x ) = (3 * x) - 1, and returns the result in the stack.
Your program cannot contain a main program with a label _start. You have to create your own main program to test your function.
Your function cannot modify any of the registers.
You only submit Hw6_1.asm to Moodle, and keep your test program.
Problem #2
Write a program called Hw6_2.asm that contains 1 recursive function called f2 that computes f2( x ) = x + (x-1) + (x-2) + ... + 2 + 1, and returns the result in the stack. We assume that x will always be strictly positive, and your function does not have to deal with negative numbers.
Examples:
f(1) = 1 f(2) = 2+1 = 3 f(3) = 3+2+1 = 6 f(4) = 4+3+2+1 = 10 f(5) = 5+4+3+2+1 = 15 etc.
Your function cannot modify any of the registers.
Submit your Hw6_2.asm program to Moodle, and keep your test program.
Problem #3
Write a program called Hw6_3.asm that contains 2 functions, f3 and f4, defined as follows:
- f3( x, y ) = 2 x + 3 y
- f4( x ) = 3 f3( x, 3 ) + f3( x-1, x+1 )
Your functions cannot modify any of the registers and return the result in the stack. For f3, x is pushed first, then y next.
Submit your program to Moodle, and keep your test program.
Problem #4
Write a program called Hw6_4.asm that contains 2 functions, f5, and f6, defined as follows:
- f5( x ) = x + (x-1) + (x-2) + ... + 2 + 1
- f6( x ) = f5( x ) + f5( x-1 ) + f5( x-2 ) + ... + f5( 2 ) + f5( 1 )
Your functions cannot modify any of the registers. f5 and f6 must compute their result recursively.
Submit your Hw6_4.asm program to Moodle, and keep your test program.
Problem #5
Write a program called Hw6_5.asm that contains a function called f7 defined as follows:
- f7( 1 ) = 1
- f7( 2 ) = 1
- f7( n ) = f7( n-1 ) + f7( n - 2 ) for any n > 2
Your functions cannot modify any of the registers. f7 must compute its result recursively.
Submit your Hw6_5.asm program to Moodle, and keep your test program.