Question
Your task is to complete the implementation of the three incomplete functions, namely, plus, minus and mul. In doing so, you must satisfy the requirements
Your task is to complete the implementation of the three incomplete functions, namely, plus, minus and mul. In doing so, you must satisfy the requirements found in each of the functions of calculator.s. You must also satisfy the requirements below.
You will also need to figure out what the function XX does and once you have done so, you will need to change its name to something more descriptive in main.c and in calculator.s as well as adding its description in the indicated place in calculator.s.
Your code must be commented. About comments: Here is an example of a useful comment: cmpl %edx, %r8d # if j (%r8d) < N (%edx), continue looping
Also, describe the algorithm you used to perform the multiplication in a comment at the top of the mul function.
Add a header comment block to your calculator.s, which must include the filename, the purpose/description of your program, your name and the date.
Remember that the function call protocol of x86-64 says that the register %edi contains the parameter (or argument) x, the register %esi contains the parameter (or argument) y and that the register %eax carries the return value. Make sure the code of all your four functions abides to this protocol.
You may use registers %rax, %rcx, %rdx, %rsi, %rdi, %r8, %r9, %r10 and %r11 in your code.
You must not modify the values of registers %rbx, %rbp, %rsp, %r12, %r13, %r14 and %r15.
calculator.s : --------------------------
# add a header comment block
.globl XX # Make sure you change the name of this function - see XX function below .globl plus .globl minus .globl mul
XX: # Description: # Change the name of this function to something more descriptive and add a description above xorl %eax, %eax cmpl %esi, %edi setl %al # See Section 3.6.2 of our textbook for a ret # description of the set* instruction family
plus: # Description: Performs integer addition # Requirement: # - you cannot use add* instruction # - you cannot use a loop
# Put your code here
minus: # Description: Performs integer subtraction # Requirement: # - you cannot use sub* instruction # - you cannot use a loop
# Put your code here
mul: # Description: Performs integer multiplication - when both operands are non-negative! # You can assume that both operands are non-negative. # Requirements: # - you cannot use imul* instruction # (or any kind of instruction that multiplies such as mul) # - you must use a loop
# algorithm: # # # #
# Put your code here
---------------------------------------------------------------------
main.c : ---------------------------
/* * Filename: main.c * * Purpose: Test driver for our calculator * * * * */
#include
int XX(int x, int y); // Make sure you change the name of this function - see calculator.s int plus(int x, int y); int minus(int x, int y); int mul(int x, int y);
int main(int argc, char *argv[]) { int x = 0; int y = 0; int result = 0;
if (argc == 3) { x = atoi(argv[1]); y = atoi(argv[2]);
result = XX(x, y); // Make sure you change the name of this function - see calculator.s printf("%d ??? %d -> %d ", x, y, result); // Make sure you change ??? to the appropriate symbol
result = plus(x, y); printf("%d + %d = %d ", x, y, result);
result = minus(x, y); printf("%d - %d = %d ", x, y, result);
result = mul(x, y); printf("%d * %d = %d ", x, y, result);
} else { printf("Must supply 2 integers arguments. "); return 1; }
return 0; } -----------------------------------------------------------
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