You just started working for a company that is implementing a set of procedures to operate on a data structure where 4 signed bytes are packed into a 32-bit unsigned. Bytes within the word are numbered from 0 (least significant) to 3
(most significant). You have been assigned the task of implementing a function for a machine using two’s-complement arithmetic and arithmetic right shifts with the following prototype:
/* Declaration of data type where 4 bytes are packed
into an unsigned */
typedef unsigned packed_t;
/* Extract byte from word. Return as signed integer */
int xbyte (packed_t word, int bytenum);
That is, the function will extract the designated byte and sign extend it to be a 32-bit int.
Your predecessor (who was fired for incompetence) wrote the following code:
/* Failed attempt at xbyte */
int xbyte (packed_t word, int bytenum)
{
return (word >>(bytenum <<3)) & 0xFF;
}
- A. What is wrong with this code?
- B. Give a correct implementation of the function that uses only left and right shifts, along with one subtraction.
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
Additional Engineering Textbook Solutions
Experiencing MIS
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Concepts of Programming Languages (11th Edition)
Introduction to Programming Using Visual Basic (10th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
- Write a MIPS program that will handle calculating minifloat addition for two numbers using the rules discussed in class and storing each of the parts as a binary integer. To do this, each ‘minifloat’ number will need to be represented (I suggest hard coded) as one register for the sign, one for the exponent part, one for the ‘significand’ (which you then convert to the fraction part). Hard coding means here that you don’t need to read in the 6 parts as user input, just have something like li $s0, 0 li $s1, 12 li $s2, 5 which is equivalent to a minifloat of 0 1101 101 = 1.101 * 2^(12-7) = 1.101*2^5 This means your program will be work with at least 6 registers as variables. For testing, show that your program can correctly calculate the Lab 5 X+Y and A+B and then one other example of your choosing. Don’t worry about special cases of 0 0000 000 or 1 1111 111 or similar, but your program should detect overflow. This will involve a lot of (in your head) jumping back and forth between…arrow_forwardthis is COmputer machine architecture ! Help me fix the following code as theres an error. what were trying to accoplish; The assignment is to create a MIPS program that corrects bad data using Hamming codes. The program is to request the user to enter a 12-bit Hamming code and determine if it is correct or not. If correct, it is to display a message to that effect. If incorrect, it is to display a message saying it was incorrect and what the correct data is (the 12-bit Hamming code) again in hex. I will be testing only with single bit errors, so the program should be able to correct my tests just fine. You do not need to worry about multiple bit errors. # This program corrects bad data using Hamming codes # It requests the user to enter a 12-bit Hamming code and determines if it is correct or not # If correct, it displays a message to that effect. If incorrect, it displays a message # saying it was incorrect and what the correct data is (the 12-bit Hamming code) again in hex. # This…arrow_forwardin c++ pleasearrow_forward
- Write a code in sim8085 for the following problem: The pressure of two boilers is monitored and controlled by a microcomputer works based on microprocessor programming. A set of 6 readings of first boiler, recorded by six pressure sensors, which are stored in the memory location starting from 2050H. A corresponding set of 6 reading from the second boiler is stored at the memory location starting from 2060H. Each reading from the first set is expected to be higher than the corresponding position in the second set of readings. Write an 8085 sequence to check whether the first set of reading is higher than the second one or not. If all the readings of first set is higher than the second set, store 00 in the ‘D’ register. If any one of the readings is lower than the corresponding reading of second set, stop the process and store FF in the register ‘D’. Data (H): First set: 78, 89, 6A, 80, 90, 85 Second Set:71, 78, 65, 89, 56, 75arrow_forwardPlease help me write a MIPS program that actually worksarrow_forwardWrite C code that contains a function called triangle_generator that outputs a triangle wave at a specified frequency (in hertz) using a specified sample rate (in hertz), and for a specified time duration (in seconds). These parameters are float type. The output you generate are floating point numbers between -1 and 1, one number per output line. The math trig functions in C use radians while all the specifications here are in hertz (cycles per second). One hertz is 2*Pi radians.arrow_forward
- Using C++, write a program that converts an integer to 32-bit two's complement. Add a space between every 8 bits. Do not use external libraries that provide the calculations automatically.Example outputThis program converts an integer to 32-bit two's complement.Enter an integer: 1999Two's complement: 00000000 00000000 00000111 11001111Enter an integer: -65535Two's complement: 11111111 11111111 00000000 00000001arrow_forwardLanguage is assembly. You need this to implement a subroutine (function) that performs individual multiplications of two 4-bit numbers. Numbers A and B are passed to the function, adding A to itself by B times by the given pseudo code. Insert the program for “multiplication” and the output of the programarrow_forwardWrite the Mnemonics of the code and show the output in SIM8085arrow_forward
- 2. Constrained by the size of the register in your old personal computer at home, youdecide to build a computer with a larger floating point register called R. Five octitscan be represented in R. You decide on the following format for the representation offloating point numbers:R: sign characteristic mantissaYou have available a 1 octit characteristic and a 3 octit mantissa.(b) Write the following decimal numbers as they would be represented in R: (i) 9.25 (ii) -3.5arrow_forwardWrite a program in MIPS assembly that allows replacing a substring with another substring. Use any function and variable of your choice. For example: Input: - Initial text: XXabXXcd - Word to replace : XX - Replacement word: YY Output: YYabYYcdarrow_forwardIm having trouble with this problem in writing a masm code for assembly language.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education