Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

ARM Processor Help

  • 23-10-2011 11:50am
    #1
    Closed Accounts Posts: 1,930 ✭✭✭


    I have to write a program where you convert from ascii to hex. I have 2034 stored in the registry but I am not sure how to convert it to its hex 7f2 value? Any pointers?


Comments

  • Registered Users, Registered Users 2 Posts: 1,306 ✭✭✭carveone


    That's a pretty confusing question. Are you saying you have an ascii string: 2034 and want to convert it to a hex string, "7f2" or the value 7f2?

    Like '2' is 50 decimal. and '0' is 48 decimal. So if you subtract '0' (48) from each number you get the decimal equivalent. Note the huge difference between the ascii character '2' and the number 2.

    '2' - 48 = 2
    '0' - 48 = 0
    '3' - 48 = 3
    '4' - 48 = 4

    So, from left to right you take the register (initially 0), multiply by 10, then take the next ascii number, subtract 48 and add to register.

    register is 0, then 2, then 20, then 203, then 2034.

    That a start??


  • Registered Users, Registered Users 2 Posts: 1,306 ✭✭✭carveone


    Also ARM assembly tends to wreck my head a bit but here's a silly attempt. Some bits might be wrong and multiplying by 10 could be done by *8 then add twice...
    ....
    adr   r4, mystring
    mov   r1, #0
    mov   r2, #10
    
    loop
        ldrb  r0, [r4], #1   ; I'm pretty sure that's right...
        cmp   r0, #0
        beq   nextthing
    
        sub   r0, r0, #48
    
        mul   r1, r1, r2      ; this could be done better
        add   r1, r1, r0
    
        ; stuff
        b loop
    
    nextthing
    
        ; r1 contains value
        ....
    
    
    mystring
        DCB    "2034",0
    
    


  • Closed Accounts Posts: 1,930 ✭✭✭galwayjohn89


    Don't think I explained it very well! Heres what I have to do
    A sequence of four ASCII symbols, each in the range ‘0’ . . . ‘9’, can represent an unsigned
    value in the range 0 . . . 9999 in text form. Design and write an ARM assembly language
    program that will convert such a sequence to the value represented by the symbols. Assume
    that the four byte-size ASCII symbols will be stored in R1 to R4, with the most significant digit
    stored in R4. Store the result of the conversion in R0.
    For example, given the following sequence of ASCII symbols ...
    ‘2’, ‘0’, ‘3’, ‘4’
    . . . your program should store the value 203410 (0x00007F2) in R0.

    At the moment I have 2034 stored in R0 but don't know how to proceed.


  • Registered Users, Registered Users 2 Posts: 1,306 ✭✭✭carveone


    My example was harder then given that I had r4 pointing to a list of the symbols ending in 0.

    But the same thing applies but is way easier.
    Subtract 48 to get the digits and then add them up. Ooh, I forgot to multiply by 10 in my example... Better fix that...

    This is your homework isn't it ;)


  • Registered Users, Registered Users 2 Posts: 1,306 ✭✭✭carveone


    BTW multiplying by 10 in arm assembly is commonly done by *2 and then *5. IE:
    mov  r0, r0, lsl #1         ; ro = ro << 1
    add  r0, r0, r0, lsl #2     ; ro = ro + ro << 2
    

    This kind of this is terribly efficient give that the ARM has a barrel shifter on the register input thingy.

    Done the whole thing for you now :p


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,306 ✭✭✭carveone


    Vuzuggu wrote: »
    At the moment I have 2034 stored in R0 but don't know how to proceed.

    Hang on a mo. You've done that bit? Ok! Sorry, I was showing off !

    What now then. Convert 2034 to hex digits? Divide by 16 and get the remainder. Look up the remainder in a table 0 to F to get the ascii value. Repeat...

    (This is a bit of a hard one. In C you just go val % 16. In ARM you'll have to think about it!)


  • Closed Accounts Posts: 1,930 ✭✭✭galwayjohn89


    Of course, divide by 16. Its so obvious once someone tells you it! Just need to know how to look up the remainder in a table. My last project was add a few registries together and a bit of multiplying so its getting harder. And yup its my homework!


  • Registered Users, Registered Users 2 Posts: 1,306 ✭✭✭carveone


    It's the same as converting binary. The tricky bit is the lookups. Plus I haven't the foggiest how to do mod in assembly*. You could do it by bitmasks though - taking 4 bits at a time and shifting and anding and stuff.
    adr    r4, hextable
    
    ....
    
    ; r1 contains number
    
    ldrb   r1, [r4, r1]   ; lookup address r4 + r1 and put in r1.
    
    ....
    
    
    hextable DCB  "0123456789ABCDEF"
    

    I didn't know you could do that with ldrb actually. Looked it up! It's essentially r1 = r4[r1].

    * Edit: Oh wait - it's just the low 4 bits. So and the number with 0x0F to get r1. Then shift your number right by 4. Then check if it's 0. Or something


  • Registered Users, Registered Users 2 Posts: 2 Jan90


    hey, people! hope u will read this message.. i have the same problem in here. VUZUGGU, how did u do this question?
    thanks in advance!


  • Registered Users, Registered Users 2 Posts: 7,501 ✭✭✭BrokenArrows


    Exactly one year later the same question needs to be answered.

    A lecturer is giving out the same homework again!!


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2 Jan90


    that's right, he didn't renew his assignment questions :P


Advertisement