Question: Write a Pep / 9 assembly language program that uses recursive function calls to convert a series of positive decimal integer input values into octal
Write a Pep assembly language program that uses recursive function calls to convert a series of positive decimal integer input values into octal notation. The program will convert all input values entered by the user one at a time until the user enters a zero or a negative number, at which point the program should stop. The following C program shows how this may be accomplished. Your program should produce exactly the same output as this sample C program:
#include
int num;
void convertint n
int result, remain;
result n;
remain n result;
if result
convertresult;
printfd remain;
end of convert
int main
printf;
scanfd #
while num
printfd decimal num;
convertnum;
printf octal
;
printf;
scanfd #
end while
return ;
end of main
To save you time, I have converted the main function for the C program shown above into Pep Assembly language. You may use this as a starting point for your program if you wish. Note that you will have to replace the comments below with code that pushes and pops various values ontooff the runtime stack.
main: STRO prompt, d
DECI num, d
while: LDWA num,d
CPWA i
BRLE endwh
DECO num, d
STRO msg d
;
insert code that pushes storage for the
parameter onto the runtime stack for
convertnum;
;
;
CALL convert
;
;;
; the stack
;
STRO msg d
;
STRO prompt, d
DECI num, d
BR while
endwh: stackrelSTOPS
;
prompt: ASCII x
msg: ASCII decimal x
msg: ASCII octal
x
END
Copy this code and then paste it into the "Source Code" window of the Pep simulator to get a headstart on this assignment. HINT: be sure to have unique names for parameters and local variables in your functions.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
