Answered step by step
Verified Expert Solution
Question
1 Approved Answer
USING PROGRAM C LANGUAGE. C. Programming Problem [50 points) You are to write an LC-3 program that uses subroutines to convert an nonnegative integer to
USING PROGRAM C LANGUAGE.
C. Programming Problem [50 points) You are to write an LC-3 program that uses subroutines to convert an nonnegative integer to its representation as a string of ASCII characters and then prints the string. Your main routine will be very short: .LD RO with the value stored at label X. JSR to a CONVERT subroutine that converts the value in R0 to its equivalent ASCII string and returns a pointer to the string in Ro. PUTS the string and HALT. Note you'll only convert and print the one value stored at X. If you want to convert and print a different value, you'll have to modify the program and reassemble it first. The CONVERT subroutine should contain a buffer large enough to hold the string for the maximum positive 16-bit integer. It should fill the buffer from right-to-left with the characters for the digits of the value in Ro and return with R0 pointing to the string that was built. Eg., for the value 17, CONVERT should set the last three positions in the buffer to '1', '7', and '0' and return with RO = the address of the '1'. (Note there can be be unused buffer positions to the left of the '1'.) Here is some C-like pseudocode for the CONVERT subroutine: Save registers Set pointer p = & (last character of output buffer) *p = 0 ' if RO == 0 else if ROStep 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