IN Assembly Language for the HCS12: 2. Write a main program to call a procedure
ID: 1847419 • Letter: I
Question
IN Assembly Language for the HCS12:
2. Write a main program to call a procedure that converts the Fahrenheit temperature value stored in the location labeled TdegF to its Celsius equivalent. The range of temperatures is 32°F to 212°F. The procedure stores the converted temperature in location TdegC.
The following is the algorithm for temperature conversion:
- Subtract 32 from Fahrenheit temperature;
- Multiply the result of subtraction by five; and
- Divide the result of multiplication by nine.
A. Cut and paste the source code.
B. Test your program for three different values and show the result of each one by dumping memory.
2. Edit, assemble, and run the program shown in Example 2 above on the Tower.
A. Check the code for the value, $73. Cut and paste the memory to show the number of zeros for this value.
B. Check the code for the value, $88. Cut and paste the memory to show the number of zeros for this value.
Explanation / Answer
#include
02
using namespace std;
03
int main()
04
{
05
int ftemp;
06
int ctemp;
07
int select = 0;
08
cout << "Please select from the following: " << endl;
09
cout << "1) Fahrenheit-to-Celsius" << endl;
10
cout << "2) Celsius-to-Fahrenheit" << endl << endl;
11
cout << "Enter: ";
12
cin >> select;
13
if (select == 1)
14
{
15
cout << " Enter temperature in Fahrenheit to convert to degrees Celsius: ";
16
cin >> ftemp;
17
ctemp = (ftemp-32) * 5 / 9;
18
cout << "Equivalent in Celsius is: " << ctemp << endl;
19
}
20
else if (select == 2)
21
{
22
cout <<" Enter temperature in Celsius to convert to degrees Fahrenheit: ";
23
cin >> ctemp;
24
ftemp = ctemp*9/5 + 32;
25
cout << "Equivalent in Fahrenheit is: " << ftemp << endl;
26
}
27
else
28
cout << "Valid options 1 or 2." << endl;
29
return 0;
30
}