
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 solution
Chapter 2 Solutions
EBK COMPUTER SYSTEMS
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects (9th Edition)
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
Starting Out with Python (4th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Concepts Of Programming Languages
Starting Out with C++ from Control Structures to Objects (9th Edition)
- 42 व 2 = 16 25 32-5 Subnetting = 27 Problem 8 Number of needed subnets 5 Network Address 172.50.0.0/27 Address class B Default subnet mask 255.255.0. . Custom subnet mask 255.255.255.229 Total number of subnets Total number of host addresses Number of usable addresses Number of bits borrowed 3 8122 8120 What is the 4th subnet range? What is the subnet number for the 5th subnet? What is the subnet broadcast address for the 6th subnet? What are the assignable addresses for the 3rd subnet?arrow_forwardProblem 4 Number of needed subnets 750 Network Address 190.35.0.0 joy worl Subnetting Show your work for Problem Address class B Default subnet mask 255.255.0.0 Custom subnet mask 255.255.255.122 Total number of subnets 1024 Total number of host addresses Number of usable addresses Number of bits borrowed What is the 15th subnet range? What is the subnet number for the 13th subnet? What is the subnet broadcast address for the 10th subnet? What are the assignable addresses for the 6th subnet? 64 65,536 62 32,768 8 10 16,384 512 1,024 2,048 4,096 8,192 16,384 32,768 65,536 256 128 64 32 16 8,192 4,096 2048 1024 512 128 256. 32 16 8 4 2 1 0 0 o O O O O 4 91 8 32 64 +9 821 32 16 8 4 Number of Hosts Number of Subnets Binary values 190. 35 Solve with the right pictures 00 99999arrow_forward5. Task 5: Write a function that takes an array and its size as parameters and returns the sum of its elements(Homework)arrow_forward
- 4.13 Extract a 3×3 array from the upper left-hand corner of the magic square you created in 4.11. Is this also a magic square?arrow_forwarda If an M/M/1 queue in a server has task arrivals at a rate of 30 per second and serves at a rate of 50 per second, how many tasks are in the system (waiting and being served) on average? b In part (a), how many tasks are being served, on average? c What is the utilization of an M/M/1 queue in a server that has four tasks waiting on average?arrow_forwardEvaluate the average gate capacitance of, and power dissipated by, a processor with the following properties: • Gate oxide thickness = 1.4 nm• Gate length = 65 nm• Gate area = (65 nm)x(65 nm)• Permittivity of free space = 8.85 x 10e−12 Farads/m • Relative permittivity of SiO2 = 3.9 • Rail-to-rail voltage = 1.1 V• Clock frequency = 3.6 GHz• Switching probability = 1.0• Number of transistors per die = 1.3 x 10e9arrow_forward
- Can you conver the following C code into ARM Assembly. Assume a is X0 and b is X1if ((a !=0) && (b == 0)) {a++} else {b++}arrow_forwardPlease help. Matlab for engineers 6th edition question.arrow_forwardA certain proram takes 26.67 seconds to run on 3 processors and 16 s to run on 7 processors. Find the execution time on one processor, the fraction of the program that can be parallelized, the theoretical execution time on an infinite number of processors, and P1/2arrow_forward
- Can you write the following C code into ARM Assembly. Assume x is X0 and y is X1:switch ( x ) {case 0 : y++; break ;case 1 : y−−; break ;default : break ;}arrow_forwardCan you write the following C code into ARM Assembly? Assume a is in X0 and b is in X1:while ( a < 10){b=b +10;a++;}arrow_forward# Instructions a. 1.00E+09 b. 1.00E+09 Compiler A Compiler B Execution time #Instructions Execution time 1s 1.20E+09 1.4 s 0.8 s 1.20E+09 0.7 s 1.6.1 [5] For the same program, two different compilers are used. The table above shows the execution time of the two different compiled programs. Find the average CPI for each program given that the processor has a clock cycle time of 1 nS. 1.6.2 15] Assume the average CPIs found in 1.6.1, but that the compiled programs run on two difference processors. If the execution times on the two processors are the same, how much faster is the clock of the processor running compiler A's coce versus the clock of the processor running compiler B's code? 1.6.3 [5] A new compiler is developed that uses only 600 million instruc- tions and has an average CPI of 1.1. What is the speed-up of using this new compiler versus using Compiler A or B on the original processor of 1.6.1? Consider two different implementations, P1 and P2, of the same instruction set.…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





