Implementing C function call in LC-3
assembly language
Convert the following C program to LC-3 assembly language. You can assume the activation record has been properly set up for main as shown in the provided LC3 assembly file. Make sure to have the correct subroutines implemented (foo1 and foo2) including correct use of the run-time stack. Main function is already fully implemented for you you should not modify it.
On exit from foo1, its return value must be properly stored on top of the run-time stack. At the end of your LC-3 program execution, R6 should be pointing at address x4001 and R5 should be pointing at x4000. Correct functionality includes having the correct values on the stack.
You may assume all integers in the C code can be treated as 16-bit signed values.
int main() {
int x, y, z;
scanf(%d %d, &x, &y);
z = foo1(&x, &y);
printf(z = %d
, z);
return 0; }
int foo1(int *x, int *y) {
int total=0;
for (; *x > 0; *x = *x 1) {
total = foo2(total, *y);
}
return total; }
int foo2(int currentTotal, int y)
{
return currentTotal + y;
}
The Pieces
Run svn update in your ece220su17 folder and check mp4 sub-folder for the supplied code. You will find the following files:
mp4.c This file contains the above code. You do not need to modify it, you can compile and run the program to see what the expected output should be.
mp4.asm This is the assembly language code that you must complete. Some parts are already implemented for you, just implement whats missing.
Grading and Testing
To test, assemble your code with lc3as and run it with lc3sim. The final answer should be stored in memory pointed by Z_VAL.
Functionality (90%)
The program should have the correct output value of z stored in
memory.
The program must correctly call the two subroutines using the
run-time stack convention presented in the textbook.
R6 and R5 must contain correct values.
Style, Comments, Write-up (10%)
Strict adherence to the run-time stack convention 5%
Comments, Formatting, Intro Paragraph 5%
You will get 0 if your code does not assemble or does not follow the function calling convention taught in class.
Programming
[SOLVED] LC-3: Implementing C function call in LC-3 assembly language
$25
File Name: LC-3:_Implementing_C_function_call_in_LC-3_assembly_language.zip
File Size: 565.2 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.