In: Accounting
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.
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
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;
}
}
}