This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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

Parents
  • 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

Reply
  • 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

Children