Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will be writing one assembly function. The function calculates both the product and sum of an array of 32-bit integers. The sum is returned.

You will be writing one assembly function. The function calculates both the product and sum of an array of 32-bit integers. The sum is returned. The product is put into a by-reference parameter

int32_t sum_prod (const int32_t *values, uint64_t num_values, int32_t &product) { uint64_t i; int32_t sum; sum = 0 product = 1; for (i = 0;i

You must use numeric labels for your for loop. Use the ABI names for registers ABI names: t0, a0, s0, etc. Index names: x10, x15, x20, etc. 6 Requirements

Compile using the following command. Replace lab with the name of your lab file. CTRL-D ends the integers, which can be done by holding the control key and pressing the d key. This is called the EOF (end of file) character. 7 Testing ~> riscv64-unknown-linux-gnu-g++ -o lab lab.cpp lab.S ~> ./lab

~> ./lab Enter values as integers (CTRL-D to stop): 10 20 30 40 50 Sum = 150 Product = 12000000 8 Example #1

~> ./lab Enter values as integers (CTRL-D to stop): -5 -1 -3 -1 Sum = -10 Product = 15 9image text in transcribed

\#include \#include \#include > \#include using namespace std; // Import sum_prod from your .S file. This file will not compile unless I/ you at least have the label sum_prod exported as a .global symbol. extern "C" \{ int sum_prod(const int *values, uint64_t num_values, int \&product); \} int main() \{ vector values; int product; int sum; I/ v will be the integer values from the user int v; // CTRL-D is the EOF key, meaning hold the control key and press d. cout "Enter values as integers (CTRL-D to stop): \ "l; ; while ( cin >v){ \} values.push_back(v); I/ There is nothing to be done if there were no values entered. if (values. size ()==0 ) \{ cout "No values entered. "; return -1; \} // This is where your sum_prod is invoked. You can change this around 1/ to debug, but remember you only submit your .S file. You are graded I/ on how your. S file interacts with this pristine template. sum = sum_prod(\&values [0], values.size () , product ); cout "Sum =" sum ' '; cout "Product = " product ' ; return 0 ; \}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Does it exceed two pages in length?

Answered: 1 week ago