This program should be written in LC-3 assembly.
For this project, you will again act as the compiler and translate the following C++ subroutines into assembly language. The functionality of your code must be identical to that of the C++ code. In other words, if the C++ code contains a for loop, you should emulate a for loop, and if the C++ code contains a function call, your code should also contain a function call.
You must also write a "main" function that calls each of these functions with proper inputs and verifies their functionality.
This time however, you are required to implement a stack and pass all parameters and return values on the stack. All local variables should also have memory locations stored on the stack.
When implementing your stack you should create two subroutines for pushing and popping that check for overflow and underflow. You will need to make your stack large enough so that all necessary activation records can be stored.
The C code you will have to compile is:
int gcd(int x, int y)
{
while (x != y)
{
if (x >y )
{
x = x - y ;
}
else
{
y = y - x ;
}
}
return x ;
}
int main()
{
int primes[10] ;
int i = 0 ;
int j = 1 ;
int k ;
int currentResult ;
while(i < 10)
{
currentResult = 0 ;
for (int k = 1; k < j; ++k)
{
if (gcd(j, k) != 1)
{
currentResult = 1 ;
}
}
if (currentResult == 0)
{
primes[i] = j ;
++i ;
}
++ j ;
}
return 0 ;
}
Turn in your source code (the .asm file) making sure that your name, id, and all relevant information is located in a block of comments at the top of the file.