Computer Organization - Lab 4: Questions | CPSC 2105, Lab Reports of Computer Architecture and Organization

Material Type: Lab; Class: Computer Organization; Subject: Computer Science; University: Columbus State University; Term: Spring 2006;

Typology: Lab Reports

Pre 2010

Uploaded on 08/04/2009

koofers-user-sgi
koofers-user-sgi 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CPSC 2105 Lab 4 Wednesday, April 5, 2006
This lab must be completed on or before Wednesday, April 12.
The following lab problem is based on the factorial function, defined as follows:
If (N < 2) Then Factorial(N) = 1
Else Factorial(N) = N Factorial(N – 1).
The MARIE does not support multiplication, so we base the lab on another function.
If (N < 1) Then F(N) = 0
Else F(N) = N + F(N – 1)
The code has two parts. The first is a helper function that avoids calling the recursive
function in cases in which it is not appropriate. It also handles the output of the result.
// Program for CPSC 2105 Lab 04
// Written by Ed Bosworth
// Written on Wednesday, April 5, 2006.
//
Clear
Store M // Set the result to zero (really redundant)
Input // Get the number for the computation
Store N // Put the number into N
Skipcond 800 // Skip the next if the input is positive.
Jump End // Just quit if the number is not positive.
JnS F // Call the function.
End, Load M // Function should return value in M
Output // Output the result
Halt // and quit.
N, HEX 0000
M, HEX 0000
One, HEX 0001
F, HEX 0000
L1, Load N // Get N back into the AC
Subt One // Subtract 1 to see if N > 1.
Skipcond 800 // Skip if N > 1
Jump LE1 // Go here for N <= 1
GT1, Load N
Add M
Store M // Set M = M + N
Load N
Subt One
Store N // N is decremented
JNS F // Recursive call
JumpI F
LE1, Load One // If N == 1 then the result is 1.
Store M
JumpI F
Trace the execution of the program for three input values: 0, 1 and 2.
What happens when each number is input. DO THE VALUE 2 AS THE LAST CASE.

Partial preview of the text

Download Computer Organization - Lab 4: Questions | CPSC 2105 and more Lab Reports Computer Architecture and Organization in PDF only on Docsity!

CPSC 2105 Lab 4 Wednesday, April 5, 2006

This lab must be completed on or before Wednesday, April 12.

The following lab problem is based on the factorial function, defined as follows:

If (N < 2) Then Factorial(N) = 1

Else Factorial(N) = N  Factorial(N – 1).

The MARIE does not support multiplication, so we base the lab on another function.

If (N < 1) Then F(N) = 0

Else F(N) = N + F(N – 1)

The code has two parts. The first is a helper function that avoids calling the recursive

function in cases in which it is not appropriate. It also handles the output of the result.

// Program for CPSC 2105 Lab 04 // Written by Ed Bosworth // Written on Wednesday, April 5, 2006. // Clear Store M // Set the result to zero (really redundant) Input // Get the number for the computation Store N // Put the number into N Skipcond 800 // Skip the next if the input is positive. Jump End // Just quit if the number is not positive. JnS F // Call the function. End, Load M // Function should return value in M Output // Output the result Halt // and quit. N, HEX 0000 M, HEX 0000 One, HEX 0001 F, HEX 0000 L1, Load N // Get N back into the AC Subt One // Subtract 1 to see if N > 1. Skipcond 800 // Skip if N > 1 Jump LE1 // Go here for N <= 1 GT1, Load N Add M Store M // Set M = M + N Load N Subt One Store N // N is decremented JNS F // Recursive call JumpI F LE1, Load One // If N == 1 then the result is 1. Store M JumpI F

Trace the execution of the program for three input values: 0, 1 and 2.

What happens when each number is input. DO THE VALUE 2 AS THE LAST CASE.