 # Binomial Coefficients Program

Subject Computer Science Assembly Language Programming

## Question

Binomial Coefficients Program Requirements

Write an assembly language program and create an accompanying problem document.

Program Requirements

Design a recursive procedure to calculate Binomial Coefficients.

The procedure should expect two arguments on the stack, and should return the answer in eax. Only eax may be altered by your procedure. If you use local storage, it must be allocated on the stack.

Binomial(4,2) should return 6
Binomial(3,0) should return 1
etc.

This procedure must be in a file by itself.

You must also create an application that allows the user to enter an integer. The program then must use the binomial coefficient procedure to calculate the coefficients of (a+b)n. These should be displayed on one line of output.

The program should repeat until 0 is entered.

Remember to document the program, as well as each procedure, as required by the CS370 Coding and Documentation Standards.

Sample Output

1 3 3 1
1 4 6 4 1
Bye!

Problem Document

The problem document will contain:

1. Pseudo-code algorithm(s) for main and the binomial procedures.
Do NOT mention the stack or registers in the pseudo code.
2. A test plan and results.

## Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

Pseudo-code:

1) binomial procedure

if k equals 0 then return 1;
if k equals n then return 1;
if k is less than 0 then return 0;
if k is greater than n then return 0;
if n is less than 0 then return 0;

else return
binomial procedure(n-1, k) + binomial procedure(n-1, k-1);

C code :
int binomial_coef(int n, int k)
{
if(k==0 || k==n) return 1;

if(k<0 || k>n || n<0) return 0;

return binomial_coef(n-1, k) + binomial_coef(n-1, k-1);
}

2) main procedure

clear screen;

enter integer loop:
print “enter integer” message;
test if the integer equals 0; if true then go to exit;
save integer;
initialize counter variable with 0 value;

binomial loop:
test if counter is greater than the integer value; if true then go to the enter integer loop start;
call binomial procedure (integer, counter);
print result;
increment counter variable;
go to the binomial loop start;

exit:
print “bye” message;
end;...

This is only a preview of the solution. Please use the purchase button to see the entire solution

## Related Homework Solutions

Iterative Factorial Calculation in Assembly \$10.00
Computer Science
Programming
Iterative Factorial Calculation
Assembly Language
Loops
Functions
Input
Output
Procedures
Error Conditions
Assembly Language Instructions \$15.00
Computer Science
Assembly Language
Instructions
Functions
Examples
Programs
Rotate
Registers
Significant Bits
MSB Location
Carry Flag
LSB
Assembly Language Programming \$30.00
Standard Swap Functions
Programming
Assembly Language Programming
Code
Convert C Function into Assembly Equivalent \$8.00
CountZeros
Assembly Equivalent
C
Given Space
Num
Language Programming
Computer
Science
Assembly Language Problems With Fibonacci Numbers \$30.00
Assembly Language
Computer Science
Programming
Fibonacci Numbers
Arrays
European Mathematics
Indian Mathematics
Sequences
Characters
Strings
Columns
Rows
Values
Memory
Stack
Macros
Boolean
Registers
Live Chats