Answered step by step
Verified Expert Solution
Question
1 Approved Answer
WRITE THE FUNCTION DESCRIBED IN SECTION 5.7 AND A MAIN ROUTINE TO TEST IT. 5.7 A FUNCTION TO READ IN HEXADECIMAL VALUES To input characters
WRITE THE FUNCTION DESCRIBED IN SECTION 5.7 AND A MAIN ROUTINE TO TEST IT.
5.7 A FUNCTION TO READ IN HEXADECIMAL VALUES To input characters from the keyboard one uses a system service to read a string (syscall sread_string) the specific set of instructions used to read a string appear below: la li syscall $read-string # Place keystrokes into buffe $a0, buffer $a1,9 # load address of input buffer into ao # Length of buffer, n The read string system service will monitor the keyboard and as the keys are pressed, the corresponding ASCII codes will be placed sequentially into the input buffer in memory. When the "Enter" key is pressed or the buffer has n-1 characters, the string is terminated by the nul code (0x00), and control is returned to the user program Notice this particular syscall has two parameters passed to it: The value in register $ao specifies the address of the input buffer in memory, and the value in register $al specifies the length of the buffer. To allocate space in memory for a nine-character buffer, the following assembler directives can be used . data buffer: . space 9 The capability to input values in hexadecimal representation is already present in the sread_int syscall. You can input a hexadecimal integer by prefixing the number with 0x. If you want to restrict the user to entering only in hexadecimal this routine could be used. In gen- eral, this algorithm involves reading in a string of characters from the keyboard into a buffer and then scanning through the string of characters, converting each ASClII code to the corre- sponding 4-bit value. The process is essentially the inverse of the hexadecimal output function, except that lower case characters as well as upper case should be accepted for "a" through "f ch new valid hexadecimal ASCII code is found, we shift our accumulator register left four bits and then insert the new 4-bit code into the accumulator. We can avoid getting more al digits in the input string by setting the buffer size to nine. If any other When ea 5.7 A FUNCTION TO READ IN HEXADECIMAL VALUES To input characters from the keyboard one uses a system service to read a string (syscall sread_string) the specific set of instructions used to read a string appear below: la li syscall $read-string # Place keystrokes into buffe $a0, buffer $a1,9 # load address of input buffer into ao # Length of buffer, n The read string system service will monitor the keyboard and as the keys are pressed, the corresponding ASCII codes will be placed sequentially into the input buffer in memory. When the "Enter" key is pressed or the buffer has n-1 characters, the string is terminated by the nul code (0x00), and control is returned to the user program Notice this particular syscall has two parameters passed to it: The value in register $ao specifies the address of the input buffer in memory, and the value in register $al specifies the length of the buffer. To allocate space in memory for a nine-character buffer, the following assembler directives can be used . data buffer: . space 9 The capability to input values in hexadecimal representation is already present in the sread_int syscall. You can input a hexadecimal integer by prefixing the number with 0x. If you want to restrict the user to entering only in hexadecimal this routine could be used. In gen- eral, this algorithm involves reading in a string of characters from the keyboard into a buffer and then scanning through the string of characters, converting each ASClII code to the corre- sponding 4-bit value. The process is essentially the inverse of the hexadecimal output function, except that lower case characters as well as upper case should be accepted for "a" through "f ch new valid hexadecimal ASCII code is found, we shift our accumulator register left four bits and then insert the new 4-bit code into the accumulator. We can avoid getting more al digits in the input string by setting the buffer size to nine. If any other When eaStep 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