Question
1: Consider the following C function: unsigned long mystery(unsigned long x) { long temp = (long) x; temp = temp ^ (temp >> 1); return
1:
Consider the following C function:
unsigned long mystery(unsigned long x) { long temp = (long) x; temp = temp ^ (temp >> 1); return (unsigned long) temp; }
Assuming longs are 64 bits and use arithmetic right shifts, what is a value of x will make this function return 0x7000000000000004? Write your answer as a hexadecimal number. If no such vaue is possible, write "none" and explain briefly in the comment.
_______________
The following incomplete function should take a 32-bit unsigned integer and
swap its most significant two bits and least significant two bit; and
clear its second least significnat byte
Incomplete parts of the function are represented with ___.
unsigned int swapLSBandMSBandClear(unsigned int x) { unsigned int LSB_MASK = 0x3; unsigned int MSB_MASK = 0xC0000000; unsigned int FINAL_MASK = ___; unsigned int SHIFT_AMOUNT = ___; unsigned int lsbits = (x & LSB_MASK) << SHIFT_AMOUNT; unsigned int msbits = (x & MSB_MASK) >> SHIFT_AMOUNT; return (lsbits | msbits | (x & FINAL_MASK)); }
Question 2 (4 points) (see above)
To complete the function above, what should the value of SHIFT_AMOUNT be? Write your answer as a constant that could appear in C code.
Answer:
______________
Question 3 (4 points) (see above)
To complete the function above, what should the value of FINAL_MASK be? Write your answer as a hexadecimal constant that could appear in C code.
Answer:
___________
Consider the following Y86-64 machine code:
30 f8 00 60 00 70 00 61 00 00 80 10 00 00 00 00 00 00 00 60 89
(The above machine code is written as a sequence of bytes, starting with the byte which would have the lowest address in mmeory.)
Question 4 (see above)
The second instruction in the machine code above has what mnemonic when written in assembly?
a. addq
b. call
c. irmovq
d. jmp
e. mrmovq
f. nop
g. rrmovq
h. rmmovq
i. pushq
j. popq
k. subq
l. none of the above _______________________________
Question 5:
Which of the following is consistent with the RISC instruction set design philosophy? Select all that apply.
a. allowing all instructions to specify locations in memory to make the instruction set more uniform
b. including an instruction that performs a logical right shift
c. including an instruction that scans a block of memory for 0s
d. making variants of a call instruction that save some caller-saved registers on the stack to shorten program machine code
e. requiring popping a value from the stack to use two instructions, one to change the stack pointer, and another to read a value in memory
Step 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