Question: Computer Assignment Program 9 : ITOA We need a reuseable assembly code segment that will print integer numbers to the terminal screen, or the stdout

Computer Assignment
Program 9: ITOA
We need a reuseable assembly code segment that will print integer numbers to the terminal screen, or the stdout file. We need to come up with a way to convert those numbers into an ASCII representation, and print the numerical characters from left to right. For now, we will focus on the unsigned numbers. The task is to write a program that loads the number 209867295 and writes it to stdout.
Brute Force Algorithm
Start with the largest possible exponential, x, of base-10 for representing a 32-bit unsigned integer in decimal notation.
Set the output string buffer's memory address and save a copy of the address in a second register.
Outer loop:
Calculate using the pow macro, 10x, and save it to be used as the incrementer, m.Load m into the compare variable p. Reset counter, c, to zeroInner loop:
Compare given number, n, with variable p.On less than, exit inner loop.On greater than, increment counter c, and increment variable p with m or equivalently 10^x.Loop back to start of inner loop.
Take counter c and add ASCII '0'(the zero character is used as the base ASCIEE value).Filter out any leading zeros.Place new ASCII character into the output string buffer, and increase address to next character space.Decrement x, and test x for zero. On zero, exit outer loop.Loop back to the start of the outer loop.
Append newline and null characters to string.
Use the Null Write macro to print string to stdout.
Exit program back to kernel.
Coding Template
main.s
// Program 9: ITOA //// description: Convert a given unsigned integer number into an // ASCII string representation and write it to stdout. //// Load the integer number 209867295 and writes it ASCII string. // input: .equ basenum, 209867295// macro: pow //// description: Calculate the exponential answer for a base value raised // to the exponential value. Process of iterative multiplications. // Important examples: a^0=1, a^1= a, a^2= a * a //// register usage: // base: // exp: // total: //// labels used: //1: //2: //// output register: // result: .macro pow 1: 2: .endm // main program //// description: Identify the largest unsigned base-10 number for 32-bit word. // register usage: // output address: // number to process: // current 10^x: // current power (x from above): // loop counter: .global _start // initialize process _start: // find first power of ten to use (remember to go left to right) findstart: // determine the digit associated for the given power of ten finddigit: // if successfully identified digit, // subtract this left most digit from remaining number // convert digit to ASCII // write ASCII character to next character space in string buffer write: // compare exponential to zero and loop back for next digit if not zero // add newline character and null character to the end of the string // print string to stdout // exit back to kernel exit: .data outstr: .fill 'y+2'// the max output size is 'y' digits characters // plus terminating characters // end of program
Expected Output
username@test1:~/cs1337/lab_6/prog_1$ as -o main.o main.s username@test1:~/cs1337/lab_6/prog_1$ ld -o main main.o username@test1:~/cs1337/lab_6/prog_1$ ./main 209867295 username@test1:~/cs1337/lab_5/prog_7$ echo $?0 username@test1:~/cs1337/lab_5/prog_7$ _

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!