Difference between revisions of "CSC231 Homework 6 2014"

From dftwiki3
Jump to: navigation, search
(Problem #4)
(Testing & Verifying with Python)
Line 65: Line 65:
 
<br />
 
<br />
  
=Testing & Verifying with Python=
 
<br />
 
If you implement the functions in Python and test them for specific values, this is what they output:
 
<br />
 
::<source lang="text">
 
f1( 3 ) = 8
 
f2( 10 ) = 55
 
f3( 5, 7 ) = 31
 
f4( 5 ) = 83
 
f5( 10 ) = 55
 
f6( 5 ) = 35
 
</source>
 
<br />
 
  
 
<!--
 
<!--

Revision as of 18:48, 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 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. f6 must compute its result recursively.

Submit your Hw6_4.asm program to Moodle, and keep your test program.