shift left/right: Shifting means exactly that, shift all the bits in the first operand either left or right the number of time indicated in the second. The second operand should be an integer value....


 shift left/right:
  Shifting means exactly that, shift all the bits in the first operand either left or right the number of time indicated in the second. The second operand should be an integer value. If it is not, then truncate it (pretend the fractional part does not exist). If a shift left would push a bit off of the 'front', it is lost and causes an overflow. Report the overflow and print the bits left over after the shift. If a shift right would push a bit off of the 'back', it is lost and causes an underflow. Report the underflow and print the bits left over after the shift.
  e.g.
    (shift 2 to the left 1 time .. in essence multiply by 2)
    $ ./compu "000101000010"
    $ OKAY 1000


    (shift 2 to the left 1.5 times .. not an int)
    $ ./compu "000101000011"
    $ NINT 1000


    (shift 2 to the left 2 times .. in essence multiply by 4, but we can't represent 8)
    $ ./compu "000101000100"
    $ AOVR 0000


    (shift 1.0 to the left 1 time .. in essence divide by 2)
    $ ./compu "001000100010"
    $ OKAY 0001

    (shift 1.0 to the left 2 times.. in essence divide by 4, but we can't represent 1/4)
    $ ./compu "001000100100"
    $ AUDR 0000

  Note! If you have more than one flag on an operation, output all that apply in the order they are listed above. Only if there are no errors and no other flags should you print "OKAY". Shift is the only operation that may result in a "NINT" flag and a "AOVR" or "AUDR" flag.


Part 0. compu: Binary time!<br>Write a program named 'compu' that interprets various binary commands and prints results.<br>Your program will take a single argument and examine the text to determine if the command is correct and if so, compute it.<br>Implementation<br>You will receive a single instruction from the Digitally Encoded Reduced Predicate Set of 12-bit instructions (i.e. DERPS-12) in<br>text via argv[1]. DERPS-12 is a statically-sized instruction set. Every operator and operand is 4 bits long and every instruction<br>consists of an operator followed by two operands. Operands are binary values with 3 bits of magnitude and 1 bit of precision with<br>the least significant bit on the right.<br>Your operators are:<br>Your operands are:<br>Your status codes are:<br>addition:<br>0000<br>0:<br>0000<br>UNDF:<br>undefined operator<br>(fatal error)<br>shift left:<br>0001<br>0.5:<br>0001<br>BSRT: too few bits<br>(fatal error)<br>shift right:<br>0010<br>1:<br>0010<br>BLNG: too many bits<br>(fatal error)<br>compare:<br>0011<br>1.5:<br>0011<br>AOVR: overflow<br>(FLAG)<br>-UNDEF-<br>0100<br>2:<br>0100<br>AUDR: underflow<br>(FLAG)<br>-UNDEF-<br>0101<br>2.5:<br>0101<br>CPEQ: compare equal<br>(FLAG)<br>-UNDEF-<br>0110<br>3:<br>0110<br>CPNQ: compare not equal (FLAG)<br>-UNDEF-<br>0111<br>3.5:<br>0111<br>NINT: non-integer operand (FLAG)<br>-UNDEF-<br>1000<br>4:<br>1000<br>OKAY: no issues<br>(FLAG)<br>-UNDEF-<br>1001<br>4.5<br>1001<br>-UNDEF-<br>1010<br>5.0<br>1010<br>-UNDEF-<br>1011<br>5.5<br>1011<br>-UNDEF-<br>1100<br>6.0<br>1100<br>-UNDEF-<br>1101<br>6.5:<br>1101<br>-UNDEF-<br>1110<br>7.0:<br>1110<br>-UNDEF-<br>1111<br>7.5:<br>1111<br>

Extracted text: Part 0. compu: Binary time! Write a program named 'compu' that interprets various binary commands and prints results. Your program will take a single argument and examine the text to determine if the command is correct and if so, compute it. Implementation You will receive a single instruction from the Digitally Encoded Reduced Predicate Set of 12-bit instructions (i.e. DERPS-12) in text via argv[1]. DERPS-12 is a statically-sized instruction set. Every operator and operand is 4 bits long and every instruction consists of an operator followed by two operands. Operands are binary values with 3 bits of magnitude and 1 bit of precision with the least significant bit on the right. Your operators are: Your operands are: Your status codes are: addition: 0000 0: 0000 UNDF: undefined operator (fatal error) shift left: 0001 0.5: 0001 BSRT: too few bits (fatal error) shift right: 0010 1: 0010 BLNG: too many bits (fatal error) compare: 0011 1.5: 0011 AOVR: overflow (FLAG) -UNDEF- 0100 2: 0100 AUDR: underflow (FLAG) -UNDEF- 0101 2.5: 0101 CPEQ: compare equal (FLAG) -UNDEF- 0110 3: 0110 CPNQ: compare not equal (FLAG) -UNDEF- 0111 3.5: 0111 NINT: non-integer operand (FLAG) -UNDEF- 1000 4: 1000 OKAY: no issues (FLAG) -UNDEF- 1001 4.5 1001 -UNDEF- 1010 5.0 1010 -UNDEF- 1011 5.5 1011 -UNDEF- 1100 6.0 1100 -UNDEF- 1101 6.5: 1101 -UNDEF- 1110 7.0: 1110 -UNDEF- 1111 7.5: 1111
Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here