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...
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...
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.
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...
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...
Write a C program to find out the number of words in an input text file...
Write a C program to find out the number of words in an input text file (in.txt). Also, make a copy of the input file. Solve in C programming.
C++. Write a program that generates a random number between 5 and 20 and asks the...
C++. Write a program that generates a random number between 5 and 20 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display Too high. Try again. If the user’s guess is lower than the random number, the program should display Too low, Try again. The program should use a loop that repeats while keeping a count of the number of guesses the user makes until...
Convert the following text into a code format: The program reads an unspecified number of integers...
Convert the following text into a code format: The program reads an unspecified number of integers until a zero is entered. While the program reads each number it counts the number of positive numbers and the number of negative numbers that have been entered and sum up the values of the numbers entered. After the user enters zero, the program computes the average of the input values, not counting the zero. At the end, the program displays the average, and...
1. A brief summary of Chapters 15 and 20 of The Code Book by Charles Petzold...
1. A brief summary of Chapters 15 and 20 of The Code Book by Charles Petzold 2. A brief summary on Hexadecimal and ASCII (No Screenshots please) P.S. If you can't do the first one, that's fine.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT