Hello,
This is my first post so please bear with me if I'm missing any information. I've just started learning the ARM language and am using Keil microVision5 currently. At the minute, I'm not too familiar with how to use ASCII codes. I know
LDR r1, = '1' will store the ASCII code for '1', which is 31, into register 1.
R1 0x00000031. But how I do re convert this back to it's numeric value, '1'?
To put it simply, let's say I have a number, 108, and I store each of these integers into three separate registers. I want to store this number, 108, into a single register, r0.
LDR r1, '1' or 0x00000031 LDR r2, '0' or 0x00000030 LDR r3, '8' or 0x00000038
So r0 should be 0x0000006C.
Thank you
If you look at an ASCII table (aka "ASCII chart"), eg
http://www.asciitable.com/
https://www.ascii-code.com/
You will notice that the code for digit 'n' is the value of n plus 0x30
So the conversion between ASCII code and numeric vale is simply a matter of adding or subtracting 0x30 - that is, the ASCII code for '0'.
To convert a multi-digit string to/from its numeric value, just apply the appropriate place value (power of ten) to each digit...
Oh I see. Sounds like I asked a stupid question haha. Thank you very much.
So I tried it myself for awhile and it doesn't seem to work.
For example if I want the number 30,000 - thirty thousand, would this be it?
LDR r1, '3' ;Setting r1 to the ASCII code for '3' LDR r2, =0x30 ;Using r2 as my mask for converting MOV r3, #10000 ;Moving 10000 to r3 to multiply r1 with SUB r1, r1, r2 ;Converting r1 to numeric '3' MUL r0, r1, r3 ;Converting to 30000 and storing that in r0
This doesn't work for me and gives me the error "A1510E: Immediate 0xA6E90000 cannot be represented by 0-255 and a rotation", which, from my understanding is that the the number #10000 is too large to be represented. I then tried using hexadecimals, so
MOV r3, #0x2710 ;Equivalent of 10000
and gives me the exact same error. I'm not too sure where I'm going wrong with this.
Thank you very much
See: www.keil.com/.../
Also: www.scss.tcd.ie/.../03-ARMAssemblyLanguage.pdf - page 14.
Why are you doing this in Assembly language?
As noted above, if you really must do it in Assembly language, then you must spend some time to properly learn tha language.
"I then tried using hexadecimals"
If the number is too big, then it will make no difference how you represent it!
Whether you represent it in decimal, hex, binary, octal, or even Roman Numerals, it remains the same number - so it remains too big!
"Also: www.scss.tcd.ie/.../03-ARMAssemblyLanguage.pdf - page 14"
Hmmm .... it seems that very course has an assignment on this - due in Week 3!
www.scss.tcd.ie/.../3d1.html
www.scss.tcd.ie/.../AsciiConversion.s
good one ..