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 : 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 and writes it to stdout.
Brute Force Algorithm
Start with the largest possible exponential, x of base for representing a 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, x and save it to be used as the incrementer, mLoad m into the compare variable p Reset counter, c to zeroInner loop:
Compare given number, n with variable pOn less than, exit inner loop.On greater than, increment counter c and increment variable p with m or equivalently xLoop back to start of inner loop.
Take counter c and add ASCII the zero character is used as the base ASCIEE valueFilter 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 : ITOA description: Convert a given unsigned integer number into an ASCII string representation and write it to stdout. Load the integer number and writes it ASCII string. input: equ basenum, macro: pow description: Calculate the exponential answer for a base value raised to the exponential value. Process of iterative multiplications. Important examples: a a a a a a register usage: base: exp: total: labels used: : : output register: result: macro pow : : endm main program description: Identify the largest unsigned base number for bit word. register usage: output address: number to process: current 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 the max output size is y digits characters plus terminating characters end of program
Expected Output
username@test:~cslabprog$ as o main.o main.s username@test:~cslabprog$ ld o main main.o username@test:~cslabprog$ main username@test:~cslabprog$ echo $ username@test:~cslabprog$
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
