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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 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!
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
Transcribed Image 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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education