CDA3101 Program 2 Solved

85.00 $

Category: Tags: ,

Description

5/5 - (1 vote)

Write an ARM program that takes takes an input string and uses recursion to print the string and the reverse of the string

Here is sample output

#include <stdio.h>

void revstr()
{
int c=getchar();
if (c==0)
{
printf(“\n”);
return;
}
else
{
printf(“%c”,c);
revstr();
printf(“%c”,c);
return;
}

}

int main()
{
printf(“Please enter a string: “);

revstr();
printf(“\n”);
return 0;
}

Requirements and Specifications

Your input cannot be stored as a global variable at any point. This means you cannot store it at a data section address, even when accepting them from scanf; they must be returned from scanf on the stack.

X19-X27 are global variables. You may not use X19-X27 in your recursive function. If you want, you may use X19-X27 in your main function.  You can use any registers you want to in your main function.

A recursion procedure requires:

  • Allocate stack space
  • Save the return address and argument on the stack
  • Recursively call procedure with BL
  • Unwind the stack by restoring the return address and arguments and deallocating stack memory
 

Hints and Warnings

You must put the argument and return address on the stack before any bl call, and restore the argument and the return address after the bl call.   This includes every printf call and every recursive call.

Skeleton code is under pa2.txt

  • pa2-d9wgah.txt