Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are to write a function in MIPS assembly for use in the SPIM simulator. Your procedure will convert a hexadecimal value in string form

You are to write a function in MIPS assembly for use in the SPIM simulator. Your procedure will convert a hexadecimal value in string form into an integer.

image text in transcribed

image text in transcribed

Requirements Provide a subroutine convert_hex_str that converts a string representation of a hexadecimal number into its numeric (binary) form 1. a. Input Parameters: $a0 contains the address of the first character of a Null-terminated string consisting of only: i. Digit characters ("O'-'9') ii. Hexadecimal letter characters, either upper or lower case ('a'-f, 'A ii. A NUL terminator (ASCII 0) b. Return Values: i. vO: The converted integer value. It must contain an integer that corresponds to the value represented by the string passed to the function. The string is considered a hexadecimal representation of an unsigned integer that fits in 31 bits. ii. $v1: An error status. 0 means no error. 1 means overflow error. If an error is returned, the integer value in SvO is ignored and can be any value. 2. Your function must be called convert_hex_str 3. Your function must accept one input value, a pointer to the string, in register $a0. You must not modify the string during processing. You may assume the input string is formatted properly according to the rules in (1a). Your function will not be tested with improperly formatted strings, and there are no behavioral requirements if the string is not properly formatted. 4. Your function should not invoke any syscalls. You do not need to print output or read keyboard input. That is all done by the test harness. Overflow. You are returning a normal 32b signed twos-complement integer. Even though the value will always be non-negative, vO uses signed form. What is the 5. largest positive value that can be represented? If the input string represents a value larger than this, your function should report an error by returning 1 in $v1. 6. Your function must follow MIPS register conventions: Callee-saved registers ($s regs) must not be altered by your function, or they must be saved to the stack and restored before returning a. b. You must not modify memory outside of your call stack frame. (If you don't know what a call stack frame is, just don't modify memory at all.) You must conclude your subroutine by returning to the return address in register $ra. c. 7. Your code must be well-commented to receive full credit. This means any non- trivial line of code should have an accompanying comment. For examples of appropriate comments, refer to any of the code examples on Canvas. Examples Input String "70" Result SvO-112 v1-0 $v0-175 $v1-0 SvO-2748 $v1-0 vO-anything v1-1 Svo-anything Sv1 -1 Comments 70 hex 112 decimal "0000000abc" "123456789" "80000000" Leading zeros are OK Overflow! Too large (9 digits) Overflow! Larger than max positive int Algorithmic Hints You may use any reasonable approach. The following suggestions will help you devise a complete solution The string exists in memory from first character to last. The first character represents the most significant hex digit. You can process the hex digits one at a time. Start with hex_value 0. For each character in the string, convert the ASCIl code to its hexadecimal value (0 to 15). Since a hexadecimal digit represents four bits, shift hex_value left 4 bits, and add the digit's value: hex value= (hex value

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_2

Step: 3

blur-text-image_3

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

Describe the major elements in and issues with prototyping.

Answered: 1 week ago

Question

What do you like to do in your spare time?

Answered: 1 week ago