This assignment must be submitted to the Moodle submission page for Assignment A14 by 10:00 AM on Monday, 5 December.
You can use whatever format you wish for answering Questions 1 to 3, but you must submit it as an ASCII text file. MS Word 2007 or Open Office will save in this format. Question 4 should be submitted as a C program that is included within the text file.
Use the rules discussed in the handouts on Translating C to LC-3: Variables, Translating C to LC-3: Functions, Translating C to LC-3: Control structures, and Translating C to LC-3: Expressions to perform the tasks of this assignment.
In this question you are going to use the following function.
int gcd(int m, int n) {
int t ;
while (m != n) {
if (m < n) {
t = m ;
m = n ;
n = t ;
} else {
m = m - n ;
}
}
return(m) ;
}
Write a simple table appropriate for the function
gcd that follows the calling conventions used in class.
Suppose the gcd function is called using the following
statement:
x = gcd(ferd, arie) ;
Assuming that ferd is at offset 5 from R5 and
arie is at offset 7 from R5 and
write appropriate function invocation and function return code sequences
in LC-3 assembler
for this call. This question involves little more than a cut-and-paste
from the functions handout
followed by a few substitutions.
Write appropriate function prologue and epilogue code sequences
in LC-3 assembler
for this call. This is the code that will be included in the
compilation of gcd.
Again, this question involves little more than a cut-and-paste from the functions handout.
gcd function into simplified C
in which (1) at most one operator appears on the right hand side
of an assignment statement and (2) the only "control" structures are
one of the following three:
goto label ;if (variable == 0) goto label ;if (variable != 0) goto label ;Your program should be in legal ANSI C format.