Question

In: Accounting

The code on pages 20-21 of the Text book asks you to input a number, and...

The code on pages 20-21 of the Text book asks you to input a number, and it will then sum the numbers from 1 to that number. The Prompt asks you to input a number, not necessarily an integer. The program will abort if a floating point number is entered.

Your project, is to “fix” the program and allow for a floating point number to be entered. The program will NOT run, so your task is to convert the floating point number to an integer.

If a floating point number is entered, truncate the number and use that integer to run the program. Also, you must inform the user that they entered a floating point and it was truncated, output to the user, the floating point they entered and the integer you used.

Note: You must only use Shift, Rotate to manipulate the bits, no conversion instructions.

The following are some pointers as to what needs to be done.

  1. The program reads an integer, that must be changed to read a floating point.
  2. You will need to move that number into a floating point register and then that number must be copied into an integer register.
  3. You will need to extract the exponent from the integer register and stored in another register.
  4. You will need to insert the Implied bit. I would suggest, zero out the exponent part by shifting left 9 then shifting right 9. Then add 8388608 (2^23) to the number.
  5. You will need to extract the fractional portion of the of the number. You will need the exponent to determine the shift. You only need to test to see that this is NOT EQUAL to 0 (if it is we have an integer)
  6. Extract the Integer. You may want to “Rotate” the bits to the left.

You may want to use the following Assembler instructions in your code:

srl, add, sll, rol, sub, srlv and sllv

Please need an answer in Assembly language not in C/C++

Need to modify code below for floating point

# A program to find the sum of the integers from 1 to N, Where N is a value, which is read from the keyboard
# vo is: N;
# t0 is sum:

         .data
Prompt: .asciiz    "\n Please Input a value for N= "
Result: .asciiz    "The sum of the integers from 1 to N is"
Bye:    .asciiz    "\n **** Adios Amigos -Plz Have a Good Day****"
         .globl     main
         .text
main:
         li         $v0, 4        #system call for print
         la         $a0, Prompt   #load adress of prompt to $a0
         syscall                  #plz print the prompt message
         li         $v0, 5       #call code to read integer
         syscall                  # value of N into $v0
         blez       $v0, End      #to end if v0 <=0
         li         $t0, 0        #clear register $t0 to 0
Loop:
         add        $t0, $t0, $v0 #sum of integers in t0
         addi       $v0, $v0, -1 #summ all integers in reverse orders
         bnez       $v0, Loop     #loop if $v0 is !=0
         li         $v0, 4        #call code to print string
         la         $a0, Result   #load adress of message into $a0
         syscall                  #plz print the string
       
         li         $v0, 1        # call code for the print integer
         move       $a0, $t0      #move value to be printed to $a0
         syscall                  #print sum of integers
         b          main          #Plz branch to main
       
End:
         li         $v0, 4        #Call code for print string
         la         $v0, Bye      #load adress of msg. into $a0
         syscall                  #print string
         li         $v0, 10       #terminate program and run
         syscall                  #return control to syste
# t0 is sum:

         .data
Prompt: .asciiz    "\n Please Input a value for N= "
Result: .asciiz    "The sum of the integers from 1 to N is"
Bye:    .asciiz    "\n **** Adios Amigos -Plz Have a Good Day****"
         .globl     main
         .text
main:
         li         $v0, 4        #system call for print
         la         $a0, Prompt   #load adress of prompt to $a0
         syscall                  #plz print the prompt message
         li         $v0, 5       #call code to read integer
         syscall                  # value of N into $v0
         blez       $v0, End      #to end if v0 <=0
         li         $t0, 0        #clear register $t0 to 0
Loop:
         add        $t0, $t0, $v0 #sum of integers in t0
         addi       $v0, $v0, -1 #summ all integers in reverse orders
         bnez       $v0, Loop     #loop if $v0 is !=0
         li         $v0, 4        #call code to print string
         la         $a0, Result   #load adress of message into $a0
         syscall                  #plz print the string
       
         li         $v0, 1        # call code for the print integer
         move       $a0, $t0      #move value to be printed to $a0
         syscall                  #print sum of integers
         b          main          #Plz branch to main
       
End:
         li         $v0, 4        #Call code for print string
         la         $v0, Bye      #load adress of msg. into $a0
         syscall                  #print string
         li         $v0, 10       #terminate program and run
         syscall                  #return control to syste

Solutions

Expert Solution

Solution:-

int ftoi(float flt)

{

   int i;

   _asm

   {

         mov eax,flt;   //Loaded mem to acc

        rcl eax,1;     //left shift acc to removethe sign

        mov ebx,eax;   //save the acc

       mov edx,8388608; //clear reg edx

       and eax,edx;         //and acc to retrieve the exponent

       shr eax,24;   

       sub eax,7fh;       //subtract 7fh to get actual power

       mov edx,eax;     //save acc val power

       mov eax,ebx;     //retrieve from ebx

      rcl eax,8;          //trim the 8 left bits

      mov ebx,eax;   //store

      mov ecx,1fh;    //subtrat 17 h

     sub ecx,edx;

     mov edx,00000000h;

     cmp ecx,0;

     je loop2;

     shr eax,1;

     or eax,B0000000h;

loop1:

     shr eax,1;     //shift(total bits - power bits)

     sub ecx,1;

     add edx,1;

     cmp ecx,0;

     ja   loop1;

loop2:

     mov i,eax;

//check sign +/-

sign:

      mov eax,flt;

      and eax,80000000h;

      cmp eax,80000000h;

      je      putsign;

}

return i;

putsign:

return -i;

}

   }

}


Related Solutions

I. Read Chapters 20 and 21 from your Text Book.   II. NCLEX Review Questions Chapters 20...
I. Read Chapters 20 and 21 from your Text Book.   II. NCLEX Review Questions Chapters 20 and 21 from Evolve Resources III. Case Study:  Age-Related Macular Degeneration Patient Profile P.J. is a 74-year-old female who has been seen multiple times in the past with a complex medical history. Most recently, she was discharged one month ago after a 14-day stay for gangrenous open cholecystectomy. The gangrene extended into the common bile duct and she suffered a bile leak postoperatively. On this...
Write a program named StringWorks.java that asks the user to input a line of text from...
Write a program named StringWorks.java that asks the user to input a line of text from the keyboard.   Ask the user if they want their answers case sensitive or not. You output should be the list of words in the sentence including duplicates A sorted list of the words (alphabetically) A sorted list of words listed backwards (where z comes before a) A randomly shuffled list of works the list of words in the sentence alphabetically removing duplicates. You need...
21. What is the output of the following segment of code if 7 is input by...
21. What is the output of the following segment of code if 7 is input by the user when asked to enter a number?____________ int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 7: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout...
On pages 15-21 and 22, the text notes that individuals who incur an alternative minimum tax...
On pages 15-21 and 22, the text notes that individuals who incur an alternative minimum tax liability attributable to timing differences are entitled to a credit against their regular tax liabilities incurred in future years, and gives a brief conceptual description of how the credit is computed. What form is used to compute the amount of the credit earned by an individual for a taxable year? What is the formula used on that form to compute the amount of the...
Shell script program that asks a number between 5 to 9. If the input is not...
Shell script program that asks a number between 5 to 9. If the input is not between 5 and 9, display an error message and ask again.                                     Output                                         1                                        22                                       333                                      4444                                     55555                                    666666                                 7777777                                  88888888                            999999999
in C please! Write a code that asks user for input N and calculates the sum...
in C please! Write a code that asks user for input N and calculates the sum of the first N odd integers. There should be a "pure" method that calculates the sum separately that Main method should call when printing the output.
Write a python programme in a Jupyter notebook which asks the user to input the number...
Write a python programme in a Jupyter notebook which asks the user to input the number of radioactive nuclei in a sample, the number at a later time, and the elapsed time. The programme should calculate and display the decay constant and the half-life. The decay is described by the equations: ? = ? ?−?? ?0 ?1/2 = ln (2) . Test your programme a sample that contains 4.00x108 nuclei initially and 1.57x107 nuclei after 150 seconds. SO THEREFORE A...
C++ programming Complete the code to input and store all the information in the structure Book:...
C++ programming Complete the code to input and store all the information in the structure Book: title, author, year and pages. Complete the function print() with arguments and code to print a Book variable in the following format: Book title: <title> Book author: <name> Published in <year> Number of pages: <pages> #include <iostream> using namespace std; struct Book { string title; string author; string year; int pages; }; void print(/*arguments*/) { //Complete function } int main() { //Declare structure variable...
Python. Write a code that asks the user to enter a string. Count the number of...
Python. Write a code that asks the user to enter a string. Count the number of different vowels ( a, e, i, o, u) that are in the string and print out the total. You may need to write 5 different if statements, one for each vowel. Enter a string: mouse mouse has 3 different vowels
CODE IN PYTHON 1. Write a program that asks the user for the number of slices...
CODE IN PYTHON 1. Write a program that asks the user for the number of slices of pizza they want to order and displays the total number of dollar bills they owe given pizza costs 3 dollars a slice.  Note: You may print the value an integer value. 2. Assume that y, a and b have already been defined, display the value of x: x =   ya+b    3. The variable start_tees refers to the number of UD T-shirts at the start...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT