Write a program to display its negative in binary

Write a program in object code that reads a single digit decimal number and displays its negative in binary.  To do this, you must first read the number as a character and then convert it to its numeric value, as discussed in class.  Then, you're going to change this to a negative number in two ways:

   1. First take its 1's compliment by inverting all its bits (changing all 0's to 1 and 1's to 0) using the "bitwise invert r" instruction.  This instruction will at once invert all the bits.  After taking its 1's compliment, take its 2's compliment by adding a 1 to it.  The accumulator will now contain the negative of the number.  To display it, you must get each bit, one by one, and store it as a character so that you can then display the bits as characters.   To do that, take the modulus of the number by 2 (And with 1, as discussed in class).  If the least significant bit is 1, the modulus will produce a 1, if it's 0, it'll give you a 0.  Convert it to character and store.  But, note that taking the modulus will overwrite the number in accumulator with the remainder that gets produced.  So, before doing the modulus, you must first save the value that's in the accumulator.  After saving the first bit, load the number you had saved back into the accumulator.  Then, to get the second bit, we must make it the least significant bit in the accumulator.  There is an easy way to do that:  just shift the number to right once.  The second bit will be positioned at the first bit location.  Save the number again and do the modulus again, convert the remainder to a character and save it.  Do this for three more bits for a total of 5 bits.  Why 5?  Because to represent the negative of a 0-9 we need 5 bits unlike the unsigned value which requires only 4.  Now, you have the five bits saved as characters which you can display.

   2. The second way to do this is the same as 1 above with one small difference:  instead of first taking the 1's compliment of the number and then its 2's compliment, you can take its 2's compliment directly by using the "Negate r" instruction.  This is only slightly shorter as you won't have to add 1.  The rest will be the same.  When you display the result after doing it this way, you should, of course, get the same result as in 1.

Finally, to check your answer, load the original positive number that you had saved back into the accumulator, add to it the negative number which you had also saved, convert the sum to a character and display the resulting character.  It must be a 0.

Load the pepo file and submit.

The following is a sample run of the program:

Input:   8

 

Output:

-8=11000                    (from conversion using bitwise invert instruction)

-8=11000                    (from conversion using Negate instruction)

8-8=0                         

To print a new line, just display the ASCII value of newline.

   Related Questions in Programming Languages

  • Q : Define Finally clause Finally clause :

    Finally clause: This is a part of try statement which is always executed, either subsequent the handling of caught exception, and normal termination of the protected statements.

  • Q : Why is Java pure object oriented

    Explain the reasons that Java is pure object oriented programming language.

  • Q : Define Hexadecimal Hexadecimal : Number

    Hexadecimal: Number representation in hexadecimal is base 16. In base 16, the digits 0-9 and the letters A to F are utilized. A symbolizes 10 (base 10), B symbolizes 11 (base 10), and so forth. Digit positions symbolize successive pow

  • Q : Define Out of scope Out of scope : It

    Out of scope: It is a variable is in scope as long as the program's flow of control is in the variable's defining block. Or else, this is out of scope.

  • Q : Maintaining audit trail of product

    The accuracy of product table data is crucial and the Brwebean’s. owner prefers to have an audit file which contains information regarding all DML activity on the BB_PRODUCT table. This information must point out the user id of the user running a DML statement,

  • Q : What is an Instantiation What is an

    What is an Instantiation: It is a creation of an instance of a class, i.e., an object.

  • Q : State Non-modal Non-modal : In this a

    Non-modal: In this a dialog is non-modal when its parent application is not blocked from additional activity whereas the dialog is being revealed.

  • Q : "Const" qualifier for pointers and

    In C++ an arguments to a function can be declared as constant as shown below:

    Q : Define BOOP Toolkit BOOP Toolkit : The

    BOOP Toolkit: The BOOP Toolkit has been developed at the Institute for Software Technology at Graz University of Technology. It is based on the SLAM project and uses the same main concept of verification by abstraction and refinement to determin

  • Q : Distinct features of Object oriented

    Q. What are the distinct features of Object oriented programming language?  

    Discover Q & A

    Leading Solution Library
    Avail More Than 1453140 Solved problems, classrooms assignments, textbook's solutions, for quick Downloads
    No hassle, Instant Access
    Start Discovering

    18,76,764

    1950370
    Asked

    3,689

    Active Tutors

    1453140

    Questions
    Answered

    Start Excelling in your courses, Ask an Expert and get answers for your homework and assignments!!

    Submit Assignment

    ©TutorsGlobe All rights reserved 2022-2023.