60.8k views
5 votes
Writing a nested function: BMI calculation Write a nested function Calculate the BMI that assigns bmlValue given a user's weight and height. Use the following equations to calcuate

BMI = weight in lbs. 703/height in inches?
Function Reset MATLAB Documentation
function BMI = ReportBMI(userweight, userHeight)
% userweight: user weight in kg X
userHeight: user height in centimeters
kgroPounds - 2.20462;
antoinches = 0.393701; X 1 kg 2.20462 pounds % 1 cm = 0.393701 in * Calls function with parameters weight (kg) and heigth (cm)
% calls function with parameters weight (kg) and heigth (cm)
BHI.CalculateBHI (userieight, user Height);
function BMiValue = calculateBMI (userweight, userHeight)
% Define a nested function calculateBHI
% Function inputs: userweight (kg),
userHeight (cm) userweight = userweight kgToPounds;
userHeight- userHeight* cmtoinches;
% Function output: brivalue
brivalue = (userweight*703)/(userHeigh-2);
end
end

User Aaron Bush
by
8.0k points

1 Answer

0 votes

Final answer:

Lines 1-4 initialize the program by setting the start address, loading initial values into registers R1 and R2, and clearing register R3 for future calculations.

Step-by-step explanation:

The purpose of lines 1-4 in the given program is to set up initial conditions and load initial data into registers for the rest of the program to utilize. Line 1 sets the origin of the program to memory address x3050. Line 2 loads the value from the label 'THREE', which is later defined as x0003, into register R1. Line 3 loads the value from the label 'NUMBER', which points to a memory block reserved by 'BLKW', into register R2. Line 4 clears register R3 by performing an AND operation with itself and zero, which effectively zeroes out the register for future use. These lines provide necessary initialization for the subsequent program logic that follows in the loop.

The purpose of lines 1-4 in the given program is to initialize the registers and memory locations that will be used in the subsequent code. In line 1, the program starts at memory location x3050. Line 2 loads the value from the memory location THREE into register R1. Line 3 loads the value from the memory location NUMBER into register R2. Line 4 sets register R3 to zero using the AND operation. These initializations prepare the registers and memory for the execution of the program.

User Robin McCorkell
by
7.5k points