How Can Our Assembly Language Homework Help You Convert CAssembly language is often used in conjunction with C code as it is closer to the metal than Java or other byte code languages. Parameters are passed using the stack (and possibly registers depending on the platform and calling convention). Th...
For this lab, we will write the LC-3 assembly code to convert temperatures given in Celsius to Fahrenheit. We need to give relevant messages to the user to guide him in using the program, for this, we make use of the TRAP x22, which displays a string on the console. Also, we require reading input from the user one character at a time, we make this by using the TRAP x23, which reads on the character from the keyboard and saves it in R0. The characters given by the user are represented in ASCII, so we must convert them to numbers before we can use them, since we know that the character for zero ‘0’ in ASCII has a value of 48, we only need to subtract this value to the read character to get the actual value. On the other hand, if we wish to display a number between 0 and 9, we need to add the 48 before we can use the TRAP x21 to display it in the console. We have a main loop that prompts the user for a selection and reads a character, then we compare the read number with 1, 2, or 3 to see which option was selected, we use simple subtraction to make the comparison, if the subtraction is zero, then that was the option selected and we branch to the part that handles the option. We have three parts to handle the input from the user; the first one is called Conv, which is executed when the user selection is 1. In this option, we prompt the user again to input another number, which will be the value to convert to Fahrenheit. In our approach, we decided to use a table to get the conversions from Celsius to Fahrenheit. The table that provides the conversion from the values 0 to 9 to the corresponding Fahrenheit temperatures is the following: