# Recursive Procedures Using Assembly Language

Subject Computer Science Assembly Language Programming

## Question

Write a windows32 assembly language program that utilizes a recursive procedure.

The main (_MainProc) procedure should:
* accept, from the user, a positive integer.
* guard against non-positive integers being entered using a loop.
* call the sumseries sub-procedure using the cdecl protocol,
* receive the results of the sub-procedure, and
* display the results.

The sumseries sub-procedure should: recursively find the sum of the series:
1*2 + 2*3 + 3*4 + ... + i*(i+1) (This is an iterative definition. Change it to a recursive definition and return the value back to the main procedure)

Notes:
Both main and sumseries must follow the cdecl protocol.
There are ways to do this iteratively, and to even find a closed form expression, but that is not the point of this assignment. Your program must use a recursive sub-procedure.

## 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.

sumseries PROC
push ebp
mov ebp,esp
push ebx ; preserve ebx
mov ebx,[ebp + 8] ; load the number into ebx, it is on address stackpointer + 8 (stack pointer points to EBP, above is the return address of sumseries (+ 4), and above it is the parameter (+8))
cmp ebx,1 ; compare the number with 1
jne sum ; if it is not 1, then jump to sum label
mov eax,2 ; result is 2, because i = 1, result = i * (i + 1) = 1 * 2 = 2

sum:
dec ebx ; decrement the number
push ebx ; push it to stack, stack pointer decreases with 4
call sumseries ; call the procedure again, stack pointer decreases by 4 again and holds the return address
add esp, 4 ; cleanup stack, as there is no need for the parameter anymore, so stack pointer will point to return address
push ecx; preserve ecx
mov ecx, eax ; store eax (previous result) in ecx register
push ebx; preserve ebx...

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

## Related Homework Solutions

Fibonacci Number Sequence
\$25.00
Computer
Science
Assembly
Language
Programming
Fibonacci
Number
Sequence
Sorter and Binary Search
\$40.00
Computer
Science
Assembly
Language
Programming
Sorter
Binary
Search
Values
Order
x86 Assembly Language Questions about Registers and Flags
\$8.00
X86
Assembly
Register
Flag
Mode
ESP
CPU
Stack
Status
Variable
Unsigned
Signed
Arithmetic
Operation
Bit
Floating
Point
Data
Negative
Positive
Base
Pointer
Carry
EBP
Interrupt
Signal
Error
FP
Overflow
Underflow
Direction
Trap
Assembly & Data Representation Questions
\$18.00
Mantissa
Sign
Bit
Exponent
Infinity
Assembly
Language
Binary
Instruction
Register
Ebx
Ecx
Edx
Memory
Location
Content
C
Statement
Equivalent
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
Binomial Coefficients Program
\$125.00
Assembly Language Programming
Binomial Coefficients
Mathematics
Loops
Conditions
Stack
Eax
Procedures
Integers
Pseudo-Code
Algorithm
Registers
Tests
Results
Live Chats