Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Total Price Calculation: Write an MIPS assembly language code to calculate the total price of fruit shopping. The prices are defined by the user at
Total Price Calculation: Write an MIPS assembly language code to calculate the total price of fruit shopping. The prices are defined by the user at the data segment as float, sequentially. The price of the each fruit is stored at the FruitPriceArray. The user will enter the amount of the chosen fruit in kg, respectively. The total price is calculated after having all types of fruit. The calculated bill value is displayed at the I/O console. Fruit Name Price Apple 4.45 Orange 2.85 Strawberry 8.25 Banana 10.50 Hints: Don't forget to define .data and .text segments. Don't forget the exit system call. Store the prices in the FruitArray; FruitPriceArray: .float 4.45, 2.85, 8.25, 10.50 lwcl $f1,0 ($t2) #load word into coprocessor 1 # Note that the memory address is held in a CPU register, not in a float register. mov.s $1,$f0 # move $f0 to $f1 A floating point can be defined at the .data segment as number: float 10.5 the defined floating point can be loaded as lwc1 $f1,number For example: How many kilos of fruit did you take: 1.25 How many kilos of fruit did you take: 1.5 How many kilos of fruit did you take: 2 How many kilos of fruit did you take: 1.75 Total price is: 44.7125 -- program is finished running -- Clear The MIPS has a floating point coprocessor (numbered 1) that operates on single precision (32-bit) and double precision (64-bit) floating point numbers. This coprocessor has its own registers, which are numbered $f0-$f31. Because these registers are only 32-bits wide, two of them are required to hold doubles. To simplify matters, floating point operations only use even-numbered registers--including instructions that operate on single floats. Values are moved in or out of these registers a word (32-bits) at a time by lwc1, swc1, mtc1, and mfc1 instructions or by the I.s, l.d, s.s, and s.d pseudoinstructions. The flag set by floating point comparison operations is read by the CPU with its bc1t and bc1f instructions. Special syscalls; addi $v0, $zero, 6 syscall to enter floating points mov.s $$12, $f0 addi $v0, $zero, 2 syscall printing out the result to the I/O terminal Some useful floating point instructions; c.lt.s FRsrc1, FRsrc2 Compare Less Than Single Compare the floating point single in register FRsrc1 against the one in FRsrc2 and set the condition flag true if the first is less than the second. lwcl FRdest, address Load Floating Point Load the floating float single at address into register FRdest. swcl FRdest, ddress Store Floating Point Store the floating float single in register FRdest at address. mov.s $0, $f1 Move Floating Point Single Move the floating float double (single) from register FRsrc to register Frdest. bolt L1 Branch to L1 if the flag is set bclf L1 Branch to L1 if the flag is not set cvt.s.w FRdest, FRsrc Convert Single to Integer Convert the double or single precision floating point number in register FRsrc to an integer and put it in register FRdest
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started