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.
- The program reads an integer, that must be changed to read a floating point.
- You will need to move that number into a floating point register and then that number must be copied into an integer register.
- You will need to extract the exponent from the integer register and stored in another register.
- 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.
- 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)
- 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 DO NOT USE CONVERSION INSTRUCTIONS.
Extracted text: .data .asciiz prompt: result: bye: .asciiz .asciiz In **** Adios Amigo - Have a good day -globl "In Please Input a value for N = " The sum of the integers from 1 to N is " main .text main: Svo, 4 Sa0, prompt # system call code for Print String # load address of prompt into Sa0 # print the prompt message li la syscall li Sv0, 5 # system call code for Read Integer # reads the value of N into $v0 syscall blez li Svo, end St0, 0 # branch to end if Sv0 <= 0 # clear register $t0 to zero loop: st0, st0, sv0 sv0, sv0, -1 svo, loop add # sum of integers in register st0 # summing integers in reverse order # branch to loop if $v0 is != zero addi bnez $v0, 4 sa0, result # system call code for print string # load address of message into sa0 # print the string li la syscall sv0, 1 sa0, sto li # system call code for print integer # move value to be printed to $a0 # print sum of integers # branch to main move syscall main svo, 4 sa0, bye # system call code for print string # load address of msg. into sa0 # print the string end: li la syscall sv0, 10 # terminate program run and # return control to system li syscall 0="" #="" clear="" register="" $t0="" to="" zero="" loop:="" st0,="" st0,="" sv0="" sv0,="" sv0,="" -1="" svo,="" loop="" add="" #="" sum="" of="" integers="" in="" register="" st0="" #="" summing="" integers="" in="" reverse="" order="" #="" branch="" to="" loop="" if="" $v0="" is="" !="zero" addi="" bnez="" $v0,="" 4="" sa0,="" result="" #="" system="" call="" code="" for="" print="" string="" #="" load="" address="" of="" message="" into="" sa0="" #="" print="" the="" string="" li="" la="" syscall="" sv0,="" 1="" sa0,="" sto="" li="" #="" system="" call="" code="" for="" print="" integer="" #="" move="" value="" to="" be="" printed="" to="" $a0="" #="" print="" sum="" of="" integers="" #="" branch="" to="" main="" move="" syscall="" main="" svo,="" 4="" sa0,="" bye="" #="" system="" call="" code="" for="" print="" string="" #="" load="" address="" of="" msg.="" into="" sa0="" #="" print="" the="" string="" end:="" li="" la="" syscall="" sv0,="" 10="" #="" terminate="" program="" run="" and="" #="" return="" control="" to="" system="" li="">= 0 # clear register $t0 to zero loop: st0, st0, sv0 sv0, sv0, -1 svo, loop add # sum of integers in register st0 # summing integers in reverse order # branch to loop if $v0 is != zero addi bnez $v0, 4 sa0, result # system call code for print string # load address of message into sa0 # print the string li la syscall sv0, 1 sa0, sto li # system call code for print integer # move value to be printed to $a0 # print sum of integers # branch to main move syscall main svo, 4 sa0, bye # system call code for print string # load address of msg. into sa0 # print the string end: li la syscall sv0, 10 # terminate program run and # return control to system li syscall>