The 32-bit RISC-V base integer instruction set (rv32i) does not support multiplication and division operations. To deal with this, a compiler may call a function when a multiplication is needed. For example, gcc expects that a function -mulsi3(unsigned int a, unsigned int b) is provided to multiply two integers. A multiplication can be carried out by repeated additions and shifts: unsigned int __mulsi3 (unsigned int a, unsigned int b) { unsigned int r = 0; while (a) { if (a & 1) { r += b; } a >>= 1; b <<= 1; } return r;

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
The 32-bit RISC-V base integer instruction set (rv32i) does not support multiplication and division
operations. To deal with this, a compiler may call a function when a multiplication is needed. For
example, gcc expects that a function - mulsi3(unsigned int a, unsigned int b) is provided to
multiply two integers. A multiplication can be carried out by repeated additions and shifts:
unsigned int -_mulsi3 (unsigned int a, unsigned int b)
{
unsigned int r = 0;
while (a) {
if (a & 1) {
r += b;
}
a >>= 1;
b <<= 1;
}
return r;
}
a) Translate the above C code into equivalent RISC-V rv32i assembler code. Comment the as-
sembler code to explain how the calculation proceeds. Note that the arguments are passed via
the registers a0 (x10) and a1 (x11) and that the result is returned in a0 (x10).
b) Does the function need function call prolog and epilog? Explain why or why not.
You are invited to use emulsiV to develop and test your assembler code.
Transcribed Image Text:The 32-bit RISC-V base integer instruction set (rv32i) does not support multiplication and division operations. To deal with this, a compiler may call a function when a multiplication is needed. For example, gcc expects that a function - mulsi3(unsigned int a, unsigned int b) is provided to multiply two integers. A multiplication can be carried out by repeated additions and shifts: unsigned int -_mulsi3 (unsigned int a, unsigned int b) { unsigned int r = 0; while (a) { if (a & 1) { r += b; } a >>= 1; b <<= 1; } return r; } a) Translate the above C code into equivalent RISC-V rv32i assembler code. Comment the as- sembler code to explain how the calculation proceeds. Note that the arguments are passed via the registers a0 (x10) and a1 (x11) and that the result is returned in a0 (x10). b) Does the function need function call prolog and epilog? Explain why or why not. You are invited to use emulsiV to develop and test your assembler code.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY