Taking a stack and printing it in reverse order in UART
So basically I have a class where the teachers designed the program that we use, and they basically said "Do these labs with no background information".
Right now I have to make a RPN calculator using assembly and I have gotten all of it coded except i have to print it in reverse order (the stack).
It would be easy, except we are using 2 digit numbers in each stack sl开发者_运维百科ot.
My simple question is how can I take a 2 digit number and split it into each bit.
An example would be having the number 52 and splitting the bits into 5 (then sends through 5 in UART) and 2 (then sends 2 through UART) so the output would be 52.
To get the digits of a number, divide by the base (in this case base 10 I assume). The remainder is the least significant digit; the quotient is the remaining digits. Repeat for more digits.
With no divide instruction, and only two digits, here's a cheesy approach:
quotient = 0;
while (number >= 10)
{
number = number - 10;
quotient = quotient + 1;
}
print msdigit;
print number;
Make sure number
is positive first!
精彩评论