Difference between revisions of "CSC231 Homework 6 2014"
(Created page with "--~~~~ ---- <br /> <bluebox> This homework assignment is due on Tuesday, Nov 11, at 11:55 p.m. </bluebox> <br /> <br /> =Problem #1= <br /> Write a program called Hw6_1.asm th...") |
(→Problem #1) |
||
Line 6: | Line 6: | ||
</bluebox> | </bluebox> | ||
<br /> | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | '''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. | ||
<br /> | <br /> | ||
=Problem #1= | =Problem #1= | ||
<br /> | <br /> | ||
− | 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 | + | 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 | + | Your function cannot modify any of the registers. |
You only submit Hw6_1.asm to Moodle, and keep your test program. | You only submit Hw6_1.asm to Moodle, and keep your test program. |
Revision as of 18:45, 4 November 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 function called f2 that computes f2( x ) = x + (x-1) + (x-2) + ... + 2 + 1, and returns the result in eax. 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 besides eax.
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 besides eax. for f3, x is pushed first, then y, when the function is called
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 besides eax.
Submit your Hw6_4.asm program to Moodle, and keep your test program.
Testing & Verifying with Python
If you implement the functions in Python and test them for specific values, this is what they output:
f1( 3 ) = 8 f2( 10 ) = 55 f3( 5, 7 ) = 31 f4( 5 ) = 83 f5( 10 ) = 55 f6( 5 ) = 35