# Program: mlQuadratic.asm # Author: ********** # Date: mm/dd/yy # Purpose: Practice floating point calculations #---------------------------------------------------------------- # Create assembler...

1 answer below »
This works in MARS assembler. MIPS programming language. Instruction in program which is outlined. See attached file/ comments in program


# Program: mlQuadratic.asm # Author: ********** # Date: mm/dd/yy # Purpose: Practice floating point calculations #---------------------------------------------------------------- # Create assembler for the Quadratic solving # #include # #include # using namespace std; # # 2x^2 -8x - 24 = 0 # # -b +- SQR( b^2 - 4ac) # x = --------------------- # 2a # # x = 6.0, -2.0 # # #void main() #{ #float a = 2.0, b = -8.0, c = -24.0; # float sqroot = sqr( b*b - 4*a*c ); #float root1 = (-b + sqroot)/2*a; # float root2 = (-b - sqroot)/2*a; #cout < "root1:\t"="">< root1="">< endl;="" #="" cout="">< "root2:\t"="">< root2="">< endl; #} # output: #root1:6 #root2:-2 .data .eqvsys_print_float 2#float .eqvsys_print_text 4#text (zero terminated) .eqvsys_exit 10#terminate endl:.asciiz"\n" lblroot1:.asciiz"root1:\t" lblroot2:.asciiz"root2:\t" a:.float2.0 b:.float-8.0 c:.float-24.0 mytwo:.float2.0 myfour:.float4.0 .text .globlmain main: # get determinate: b^2 - 4ac into $f0 #get square root jalsqrt#f0 input; f1 output # plus root in $f0 #-b + sqrt(b^2 - 4ac) # /2a # minus root in $f1 #-b - sqrt(b^2 - 4ac) # /2a # print root1 in $f0 li$v0, sys_print_text la$a0, lblroot1#label syscall li$v0, sys_print_float#print mov.s$f12, $f0 syscall li$v0, sys_print_text la$a0, endl#endl syscall # print root2 in f1 li$v0, sys_print_text la$a0, lblroot2#label syscall li$v0, sys_print_float#print mov.s$f12, $f1 syscall li$v0, sys_print_text la$a0, endl#endl syscall #------------------------ # terminate program. li$v0, sys_exit# call code for terminate syscall# system call #.end main ## =============================================================================================== ## david krawchuk ## 11/18/2013 ## squareroots ## function name : sqrt ## this function calculates square roots. the function takes one parameter in register $f0 ## and returns the calculated value in register $f1 when finished. if given a negative ##value then the function will print an error message and then return a value 0 in register $f1. .data zero: .float 0.0 # constant value zero one:.float 1.0 # constant value one two: .float 2.0 # constant value two error_statement: .asciiz "\ninput value is negative!\n" # used when input value is negative. .globl sqrt .text sqrt: ## negative condition test block ## ## used registers : ## $f0 = function input ## $f31 = zero (const.) l.s $f31, zero# load register $f31 with value zero constant for comparison to input. c.lt.s $f0, $f31# compare input paragmeter with zero constant; if negative set flag to 1 (1 = false). bc1t error # break to error block of function if flag value is 1; else continue to base calculation block. ## end n.c.t.b.## ## base calculation block ## # used registers : # $f30 = one (const.) # $f29 = two (const.) # $f2 = calculated result # $f0 = input parameter l.s $f30, one# set register $f30 to the float value 1.0. l.s $f29, two# set register $f29 to the float value 2.0. add.s $f2, $f0, $f30# represents (input + 1) div.s $f2, $f2, $f29# represents (input + 1) / 2 ## end b.c.b.## ## approximation block ## # used registers : # $t0 = loop counter # $f3 = result of xsub(i - 1) / 2 # $f2 = xsub(i-1) # $f29 = 2 # $f4 = 2 * xsub(i - 1) # $f5 = input / ($f4) li $t0, 1# set counter register $t0 to the value one; used for loop constraint. approximation_loop: beq $t0, 10, end_approximation_loop# break to end of loop after nine itterations of loop. # note: first itteration performed in base calculation block. div.s $f3, $f2, $f29# calculates xsub(i - 1) / 2; places results in $f3. mul.s $f4, $f29, $f2# calculates 2 * xsub(i - 1) div.s $f5, $f0, $f4# calculates input / $f4 add.s $f2, $f3, $f5# calculates $f3 + $f5; xsub(i-1) / 2 + (2 * xsub(i - 1) addi $t0, $t0, 1# add one to the loop counter. j approximation_loop# return to the begenning of the approximation_loop. end_approximation_loop: ## end approximation block ## mov.s $f1, $f2# move calculated contents from appoximation loop from $f2 to return register $f1. jr $ra# return to caller address. sqrt_end: ## end function body ## ## error block ## error: l.s $f0, zero# set return register $f0 to value 0. li $v0, 4# load instruction 4 into $v0; value 4 : print string instruction. la $a0, error_statement# load address of string statement. syscall# perform system call. jr $ra# return to caller address. error_end: ## end error block ## endl;="" #="" }="" #="" output:="" #="" root1:="" 6="" #="" root2:="" -2="" .data="" .eqv="" sys_print_float="" 2="" #float="" .eqv="" sys_print_text="" 4="" #text="" (zero="" terminated)="" .eqv="" sys_exit="" 10="" #terminate="" endl:="" .asciiz="" "\n"="" lblroot1:="" .asciiz="" "root1:\t"="" lblroot2:="" .asciiz="" "root2:\t"="" a:="" .float="" 2.0="" b:="" .float="" -8.0="" c:="" .float="" -24.0="" mytwo:="" .float="" 2.0="" myfour:="" .float="" 4.0="" .text="" .globl="" main="" main:="" #="" get="" determinate:="" b^2="" -="" 4ac="" into="" $f0="" #get="" square="" root="" jal="" sqrt="" #f0="" input;="" f1="" output="" #="" plus="" root="" in="" $f0="" #-b="" +="" sqrt(b^2="" -="" 4ac)="" #="" 2a="" #="" minus="" root="" in="" $f1="" #-b="" -="" sqrt(b^2="" -="" 4ac)="" #="" 2a="" #="" print="" root1="" in="" $f0="" li="" $v0,="" sys_print_text="" la="" $a0,="" lblroot1="" #label="" syscall="" li="" $v0,="" sys_print_float="" #print="" mov.s="" $f12,="" $f0="" syscall="" li="" $v0,="" sys_print_text="" la="" $a0,="" endl="" #endl="" syscall="" #="" print="" root2="" in="" f1="" li="" $v0,="" sys_print_text="" la="" $a0,="" lblroot2="" #label="" syscall="" li="" $v0,="" sys_print_float="" #print="" mov.s="" $f12,="" $f1="" syscall="" li="" $v0,="" sys_print_text="" la="" $a0,="" endl="" #endl="" syscall="" #------------------------="" #="" terminate="" program.="" li="" $v0,="" sys_exit="" #="" call="" code="" for="" terminate="" syscall="" #="" system="" call="" #.end="" main="" ##="==============================================================================================" ##="" david="" krawchuk="" ##="" 11/18/2013="" ##="" squareroots="" ##="" function="" name="" :="" sqrt="" ##="" this="" function="" calculates="" square="" roots.="" the="" function="" takes="" one="" parameter="" in="" register="" $f0="" ##="" and="" returns="" the="" calculated="" value="" in="" register="" $f1="" when="" finished.="" if="" given="" a="" negative="" ##="" value="" then="" the="" function="" will="" print="" an="" error="" message="" and="" then="" return="" a="" value="" 0="" in="" register="" $f1.="" .data="" zero:="" .float="" 0.0="" #="" constant="" value="" zero="" one:="" .float="" 1.0="" #="" constant="" value="" one="" two:="" .float="" 2.0="" #="" constant="" value="" two="" error_statement:="" .asciiz="" "\ninput="" value="" is="" negative!\n"="" #="" used="" when="" input="" value="" is="" negative.="" .globl="" sqrt="" .text="" sqrt:="" ##="" negative="" condition="" test="" block="" ##="" ##="" used="" registers="" :="" ##="" $f0="function" input="" ##="" $f31="zero" (const.)="" l.s="" $f31,="" zero="" #="" load="" register="" $f31="" with="" value="" zero="" constant="" for="" comparison="" to="" input.="" c.lt.s="" $f0,="" $f31="" #="" compare="" input="" paragmeter="" with="" zero="" constant;="" if="" negative="" set="" flag="" to="" 1="" (1="False)." bc1t="" error="" #="" break="" to="" error="" block="" of="" function="" if="" flag="" value="" is="" 1;="" else="" continue="" to="" base="" calculation="" block.="" ##="" end="" n.c.t.b.##="" ##="" base="" calculation="" block="" ##="" #="" used="" registers="" :="" #="" $f30="one" (const.)="" #="" $f29="two" (const.)="" #="" $f2="calculated" result="" #="" $f0="input" parameter="" l.s="" $f30,="" one="" #="" set="" register="" $f30="" to="" the="" float="" value="" 1.0.="" l.s="" $f29,="" two="" #="" set="" register="" $f29="" to="" the="" float="" value="" 2.0.="" add.s="" $f2,="" $f0,="" $f30="" #="" represents="" (input="" +="" 1)="" div.s="" $f2,="" $f2,="" $f29="" #="" represents="" (input="" +="" 1)="" 2="" ##="" end="" b.c.b.##="" ##="" approximation="" block="" ##="" #="" used="" registers="" :="" #="" $t0="loop" counter="" #="" $f3="result" of="" xsub(i="" -="" 1)="" 2="" #="" $f2="Xsub(i-1)" #="" $f29="2" #="" $f4="2" *="" xsub(i="" -="" 1)="" #="" $f5="input" ($f4)="" li="" $t0,="" 1="" #="" set="" counter="" register="" $t0="" to="" the="" value="" one;="" used="" for="" loop="" constraint.="" approximation_loop:="" beq="" $t0,="" 10,="" end_approximation_loop="" #="" break="" to="" end="" of="" loop="" after="" nine="" itterations="" of="" loop.="" #="" note:="" first="" itteration="" performed="" in="" base="" calculation="" block.="" div.s="" $f3,="" $f2,="" $f29="" #="" calculates="" xsub(i="" -="" 1)="" 2;="" places="" results="" in="" $f3.="" mul.s="" $f4,="" $f29,="" $f2="" #="" calculates="" 2="" *="" xsub(i="" -="" 1)="" div.s="" $f5,="" $f0,="" $f4="" #="" calculates="" input="" $f4="" add.s="" $f2,="" $f3,="" $f5="" #="" calculates="" $f3="" +="" $f5;="" xsub(i-1)="" 2="" +="" (2="" *="" xsub(i="" -="" 1)="" addi="" $t0,="" $t0,="" 1="" #="" add="" one="" to="" the="" loop="" counter.="" j="" approximation_loop="" #="" return="" to="" the="" begenning="" of="" the="" approximation_loop.="" end_approximation_loop:="" ##="" end="" approximation="" block="" ##="" mov.s="" $f1,="" $f2="" #="" move="" calculated="" contents="" from="" appoximation="" loop="" from="" $f2="" to="" return="" register="" $f1.="" jr="" $ra="" #="" return="" to="" caller="" address.="" sqrt_end:="" ##="" end="" function="" body="" ##="" ##="" error="" block="" ##="" error:="" l.s="" $f0,="" zero="" #="" set="" return="" register="" $f0="" to="" value="" 0.="" li="" $v0,="" 4="" #="" load="" instruction="" 4="" into="" $v0;="" value="" 4="" :="" print="" string="" instruction.="" la="" $a0,="" error_statement="" #="" load="" address="" of="" string="" statement.="" syscall="" #="" perform="" system="" call.="" jr="" $ra="" #="" return="" to="" caller="" address.="" error_end:="" ##="" end="" error="" block="">
Answered Same DayOct 28, 2021

Answer To: # Program: mlQuadratic.asm # Author: ********** # Date: mm/dd/yy # Purpose: Practice floating point...

Gaurav answered on Nov 01 2021
142 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here