Keil Logo

Using ASCII codes

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Author
Edmond Cheng
Posted
30-Sep-2018 20:42 GMT
Toolset
None
New! Using ASCII codes

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

Author
Andrew Neil
Posted
1-Oct-2018 08:46 GMT
Toolset
None
New! RE: Using ASCII codes

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...

Author
Edmond Cheng
Posted
1-Oct-2018 08:56 GMT
Toolset
None
New! RE: Using ASCII codes

Oh I see. Sounds like I asked a stupid question haha. Thank you very much.

Author
Edmond Cheng
Posted
2-Oct-2018 22:06 GMT
Toolset
None
New! RE: Using ASCII codes

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

Author
Andrew Neil
Posted
3-Oct-2018 08:14 GMT
Toolset
None
New! RE: A1510E: Immediate cannot be represented by 0-255 and a rotation

See: http://www.keil.com/forum/59313/how-can-i-worjk-around-the-a15101e-error/

Also: http://www.scss.tcd.ie/John.Waldron/3d1/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!

Author
Andrew Neil
Posted
3-Oct-2018 09:23 GMT
Toolset
None
New! RE: Why are you doing this in Assembly language?

"Also: http://www.scss.tcd.ie/John.Waldron/3d1/03-ARMAssemblyLanguage.pdf - page 14"

Hmmm .... it seems that very course has an assignment on this - due in Week 3!

http://www.scss.tcd.ie/John.Waldron/3d1/3d1.html

http://www.scss.tcd.ie/John.Waldron/3d1/AsciiConversion.s

Author
Robert Pique
Posted
9-Oct-2018 10:17 GMT
Toolset
None
New! RE: Using ASCII codes

good one ..

Next Thread | Thread List | Previous Thread Start a Thread | Settings

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.