Learn to pass parameters and write a simple recursive subroutine. Consider the f
ID: 3670877 • Letter: L
Question
Learn to pass parameters and write a simple recursive subroutine. Consider the following function: Y(M, N) = Y(M) + Y(N) This problem can be solved recursively. To do that, let's define this function Y(P) as follows: Y(1) = 1. This is the base case. Y(P) = P +Y(P-l) Notice that Y(P) is defined in terms of a simpler version of itself. For example, let's say we wish to compute Y(4). The steps would then be: Write a 68000 assembly language program to accept positive integer values M and N from the keyboard, compute Y using a recursive subroutine, and print the result on the screen. The computation of Y must take place in a recursive subroutine. The input and output must occur in the main program. Since your function is recursive, you may find it necessary to begin the subroutine by saving certain registers onto the stack. Just before you return from the subroutine, you should restore those registers to their original values. You may find the MOVEM instruction useful for this.Explanation / Answer
Answer:
******************
ideal
model tiny
p286
codeseg
org 0100h
begin:
mov bx, ; n = 4
push bx ; parameter n
xor ax,ax ; Asign ax = 0
call Y ; add 1 + 2 + 3 + 4 + 5 .. + n
;the result queda en ax
int 20h
; /// perform sum of n to 1 ///
; ex : function procSumaN1 (n:word):word;
Y:
push bp
mov bp,sp
add bp,4
cmp [word ptr bp],0h
je ed
add ax,[bp]
mov bx,[bp]
dec bx
push bx
call Y
ed: pop bx
ret 2
end begin
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.