Implement and test LC-3 assembly language subroutines GETDEC, GETBIN and GETHEX
ID: 3690451 • Letter: I
Question
Implement and test LC-3 assembly language subroutines GETDEC, GETBIN and GETHEX to input an unsigned integer value entered in either Decimal, Binary or Hexadecimal format respectively. These three subroutines can each be implemented via a common helper subroutine that performs a repeated multiplication process using the input digits.
Algorithms
Repeated Multiplication
Initialize: Value ß 0
loop
Enter the next ASCII_Digit
exit if the ASCII_Digit is CR (x0A)
Convert ASCII_Digit to its Numeric_Digit
Update: Value ß Value * Base + Numeric_Digit
endloop
Converting ASCII to Numeric
Find the index of the given ASCII_digit in “0123456789ABCDEF”
The index is the Numeric_Digit equivalent of the given ASCII_Digit
Specification
A partially completed program is provided on the class web-page. It includes a stub for each of two subroutines required to complete the program:
CHAR_TO_INT converts an ASCII digit in R0 to its equivalent numeric digit
GET_INT interprets a sequence of keystrokes, ending with CR, to construct an unsigned integer value returned in R0. The number base (2, 10 or 16) is provided in R0 when the subroutine is called.
The subroutines GETDEC, GETBIN and GETHEX are complete, but depend on a correct implementation of the GETINT subroutine. The main/driver is also complete.
1. Complete the CHAR_TO_INT subroutine. You must implement the algorithm described above.
2. Complete and test the GETINT subroutine. You must implement the algorithm described above.
3. The CHAR_TO_INT and GETINT subroutines must each save/restore their working registers, including R7, in their own individual save areas.
4. Do not modify the other given subroutines or the main/driver.
Link to incomplete code: http://users.cis.fiu.edu/~pestaina/assign2.asm
Explanation / Answer
the above code to be used along with the code mentioned in the question
the equivalent c code is also given below:
//#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
// #include <conio.h>
void CHAR_TO_INT() {
// convert ascii to numeric
}
void GETINT() {
}
void GETBIN() {
}
void GETHEX() {
}
void GETASCII() {
// 65 = A, 66 = B, 67 = C, ........, 90 = Z, 97 = a, 99 = c, 100 = d, ......, 122 = z
// nl = new line != CR != X0A != 10 in decimal
// If CR = Carriage Return, then its ascii is 0xod = 13 in decimal
// possible typo in the question?
// we will assume hex A will stop the inputs
int intVal1;
char c;
while(c != 10) {
printf(" Enter the next ASCII _ Digit");
scanf("%c", &c);
intVal1 = (int)c;
if ( c == 10 ) { break; }
} // end while
} // end func Get Ascii
int main()
{
GETASCII();
return 0; // exit
} // end of main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.