We are using ARM200 to learn assembly language. I have a portion of memory with 32 integers filling it. I need to be able to print out these 32 integers to the screen. I can print out numbers 0 – 9 easy enough just by adding the ASCII value of the number 0 to what is in the register, but I’m very confused how you print out numbers greater then 9.
Print LDR r5, [r2] ;load whats in that part of memory to r5.
CMP r5, #9 ;compare if number is greater or less then 9
ADDLE r0, r5, #"0" ;add value in array to ascii value of 0 to print
SWI SWI_WriteC ;Print Value
ADD r6, r6, #1 ;increment counter
ADD r2, r2, #4 ;move portion of memory to the next int.
CMP r6, #32 ;check if you are done printing 32 ints
BNE Print ;if not loop back up to print
MOV pc, r14 ;return
r0 is the register used for printing and r2 points to the location in memory for all the integers. r5 is what i put the value from memory into and r6 is used for a counter.
Yes i do realize that there is 4 bytes of space in between each number in memory, but this does not matter for this project.
Since you’re learning (ie, possible homework), I’ll give general advice only.
Let’s say you have the number 247 and you wanted to print out the three digits of it, one by one.
How can you get the hundreds digit
2from247and leave47for the next iteration?Put that value into a temporary variable and set a counter to zero. Then, while the temp value is greater than 99, subtract 100 from it and add 1 to the counter.
This will give you a counter of
2and a temp value of47. Use the2to output your digit (you state you can already do this).Now move on to tens.
Set the counter back to zero.
Then, while the temp value is greater than 9, subtract 10 from it and add 1 to the counter.
This will give you a counter of
4and a temp value of7. Use the4to output your digit.Finally, units.
Use the final remainder
7to output the last digit.Here’s some assembler-like pseudo-code I used in another answer (slightly modified) to do a similar thing.
And one other thing, all this stuff needs to go into subroutines so that you can re-use them. Having thirty-two copies of that algorithm above converted to assembly would be a very tedious piece of code.