For a hypothetical computer (called CRAZY), eachinstruction uses 32 bits (4 byte
ID: 3617274 • Letter: F
Question
For a hypothetical computer (called CRAZY), eachinstruction uses 32 bits (4 bytes). The opcode, which is 8 bitslong, is constructed by concatenating the most significant 4 bitsof the instruction with the least significant 4 bits of theinstruction. As an example, suppose the machine instructionis 8ABCD021 (hex). Notice that the mostsignificant 4 bits are 1000 and the leastsignificant 4 bits are 0001. So, the opcodespecified by the instruction is 10000001(binary),which is 129 in decimal. Write a C functionprint_opcode with the followingheader:
void print_opcode (int instr)
Assume that the int data type is 4-byteslong. The parameter instr to the above functionis an integer that represents a 4-byte instruction for CRAZY. Thefunction must print the opcode specified in the instruction as adecimal integer to stdout.
You need to show only the C code for the abovefunction.
i
Explanation / Answer
please rate - thanks #include #include void print_opcode (int ); int main() {int instr; printf("enter instruction in hex: "); scanf("%x",&instr); print_opcode (instr); getch(); return 0; } void print_opcode (int instr) {int opcode=0,upper=0,lower=0; upper=instr&0xF0000000; lower=instr&0xF; opcode=(upper>>24)&0x000000F0|lower; printf("For the instruction %x, the opcode is%d ",instr,opcode); }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.