Answered step by step
Verified Expert Solution
Question
1 Approved Answer
int16 t core_add (int16_t first, int16 t second); // return first + second int16 core_sub(int16 t first, int16 t second); // return first - second
int16 t core_add (int16_t first, int16 t second); // return first + second int16 core_sub(int16 t first, int16 t second); // return first - second int16_t core_mult(int16 t first, int16 t second); // return first * second int16_t core_div(int16_t first, int16_E second); // return first / second Kaiyuan is fed up with calling the functions by their names, so he creates a so-called function dispatch table. In particular, since function pointers can be used to call functions, we can create an array of function pointers, and then call a specific function based on its array index instead of using the actual function name. Kaiyuan's function dispatch table (array) in LC-3 assembly has the format: FDT ; function dispatch table , FILL core_add . FILL core_sub . FILL core_mult . FILL core_div To make use of the function dispatch table, Kaiyuan writes a "dispatcher" function: int16_t dispatcher (int16_t arg1, int16_t arg2, int16_t cnd) ; The dispatcher uses and argument to select the desired "Core Function", and the arguments arg1 and arg2 are passed to the selected function. For example, calling dispatcher (2,3,0) invokes core_add with arguments 2 and 3 (i.e., returning 5). The function dispatcher follows LC-3 calling conventions, but it jumps directly to the selected "Core Function," so we DO NOT need to set up the stack frame again. In other words, arguments to the "Core Function" do not need to be pushed onto the stack, and R7 should not be changed by di spatcher. Assuming the above description, answer the following three questions: A.1 (4) Keyi contemplates to change the order of arguments (arg1, arg2, cmd) to (cmd, arg1,arg2 ) to call dispatcher function. USING 40 OR FEWER WORDS, explain whether it is a good idea or not. A.2 (2. 1.s) Assume that main function calls the function di spatcher (5,7,3). Which "Core Function" is invoked? What does this "Core Function" return? Fill in the blanks below. dispatcher (5,7,3) invokes , which returns A.3 When the "Core Function" in question A. 2 executes RET, to which function does it return to? CIRCLE THE CORRECT ANSWER. int16 t core_add (int16_t first, int16 t second); // return first + second int16 core_sub(int16 t first, int16 t second); // return first - second int16_t core_mult(int16 t first, int16 t second); // return first * second int16_t core_div(int16_t first, int16_E second); // return first / second Kaiyuan is fed up with calling the functions by their names, so he creates a so-called function dispatch table. In particular, since function pointers can be used to call functions, we can create an array of function pointers, and then call a specific function based on its array index instead of using the actual function name. Kaiyuan's function dispatch table (array) in LC-3 assembly has the format: FDT ; function dispatch table , FILL core_add . FILL core_sub . FILL core_mult . FILL core_div To make use of the function dispatch table, Kaiyuan writes a "dispatcher" function: int16_t dispatcher (int16_t arg1, int16_t arg2, int16_t cnd) ; The dispatcher uses and argument to select the desired "Core Function", and the arguments arg1 and arg2 are passed to the selected function. For example, calling dispatcher (2,3,0) invokes core_add with arguments 2 and 3 (i.e., returning 5). The function dispatcher follows LC-3 calling conventions, but it jumps directly to the selected "Core Function," so we DO NOT need to set up the stack frame again. In other words, arguments to the "Core Function" do not need to be pushed onto the stack, and R7 should not be changed by di spatcher. Assuming the above description, answer the following three questions: A.1 (4) Keyi contemplates to change the order of arguments (arg1, arg2, cmd) to (cmd, arg1,arg2 ) to call dispatcher function. USING 40 OR FEWER WORDS, explain whether it is a good idea or not. A.2 (2. 1.s) Assume that main function calls the function di spatcher (5,7,3). Which "Core Function" is invoked? What does this "Core Function" return? Fill in the blanks below. dispatcher (5,7,3) invokes , which returns A.3 When the "Core Function" in question A. 2 executes RET, to which function does it return to? CIRCLE THE CORRECT
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started