Question: Programming in C, Assembly Language, Computer Systems. Hello Chegg Experts, I am aware that i should only submit one question but as I thought these
Programming in C, Assembly Language, Computer Systems.
Hello Chegg Experts,
I am aware that i should only submit one question but as I thought these are more like short answers I'd really appreciate it if you could solve all the questions below.
In answering the first five problems, your code should follow these rules:
Assume integers are represented in twos complement.
Assume data type int is w bits long. Unless w is given a specific value, your code should work as long as w is a multiple of 8. You can use the expression sizeof(int)
Your code should be straight-line with no conditionals, loops, or function calls.
You are not allowed to use division, modulus, multiplication, or relative comparison operators (, =).
You are allowed to use all bit-level and logic operations, left and right shifts (but only with shift amounts between 0 and w 1), addition and subtraction, and integer constants INT MIN and INT MAX.
You are allowed to use casting between data types int and unsigned, either explicitly or implicitly. Note: C allows so-called type casting to convert between unsigned and signed. This means that you can interpret the same bit pattern according to a magnitude-only convention or twos complement.
Here are the questions:



Thank you in advance!
1. Suppose we number the bytes in a w-bit word from 0 (least significant) to w/8 1 (most significant). Write code for the following C function, which will return an unsigned value in which byte i of argument x has been replaced by byte b: unsigned replace_byte (unsigned x, int i, unsigned char b); Here are some examples showing how the function should work: replace_byte(0x12345678, 2, OxAB) --0x12AB5678 replace_byte(0x12345678, 0, OxAB) -> 0x123456AB You may use constants but no larger than 255 (i.e., OxFF) they are false. Assume x is of type int. 2. Write C expressions that evaluate to 1 when the following conditions are true, and to 0 when A. Any bit of x equals 1 B. Any bit of x equals 0 C. Any bit in the least significant byte of x equals 1 D. Any bit in the most significant byte of x equals 0. In this problem, you may not use equality) or inequality () tests. You may use constants but no larger than 255 3. Write C code to implement the following function: Return 1 when any odd bit of x equals 1; 0 otherwise. Assume w-32 */ int any_odd_one (unsigned x) In this problem, you may assume that data type int has w- 32 bits. You may also use 32-bit constants. Note that the least significant bit is numbered 0, and 0 is even
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
