-1

this Keil uVision program should load a positive whole ASCII number (e.g 1234). The Program should convert it into BCD coded number in Register R1 , and the HEX number in Register 2... can someone explain me what it does below? especially :

MOV     R4,#10

and

AND     R1,R3,#0xF
MLA     R2,R4,R2,R3

??? here is the program:

LDR R0, =Wert ; Pointer laden
    LDR R1,[R0]
    BL KONVERT ; Unterprogramm KONVERT aufrufen
endlos         B        endlos


KONVERT
    LDRB    R3,[R0],#1 ; Byte laden
    AND     R1,R3,#0xF ; ASCII-HEX-Wandlung
    MOV     R2,R1 ; HEX-Zahl
    MOV     R4,#10

    LDRB    R3,[R0],#1 ; nächstes laden
    AND     R3,R3,#0xF ; ASCII-Hex-Wandlung
    ORR     R1,R3,R1,LSL #4 ; BCD-Wert bilden
    MLA     R2,R4,R2,R3 ; HEX-Zahl

    LDRB    R3,[R0],#1 ; nächstes laden
    AND     R3,R3,#0xF ; ASCII-Hex-Wandlung
    ORR     R1,R3,R1,LSL #4 ; BCD-Wert bilden
    MLA     R2,R4,R2,R3 ; HEX-Zahl

    LDRB    R3,[R0],#1 ; nächstes laden
    AND     R3,R3,#0xF ; ASCII-Hex-Wandlung
    ORR     R1,R3,R1,LSL #4 ; BCD-Wert bilden
    MLA     R2,R4,R2,R3 ; HEX-Zahl

    BX      LR ; Rücksprung
MMMM
  • 3,320
  • 8
  • 43
  • 80

1 Answers1

1
MOV     R4,#10
; loads constant 10 decimal into R4

AND     R1,R3,#0xF
; 0x0F & R3 are stored in R1 (AND operation). This is used to remove the 0x30 offset of the numbers 0-9 in ASCII

MLA     R2,R4,R2,R3
; (R2 * R4) + R3 are stored in R2 (Multiply-Accumulate operation)

The ARM Infocenter is a good starting point for such questions.

Manu3l0us
  • 466
  • 3
  • 7
  • what use has it to load constant 10 into R4? – MMMM Jan 07 '14 at 22:56
  • it's used to build the hex number (HEX-Zahl) in r2. E.g. you have a string like 1234 which is "one-thousand-two-hundred-thirty-four". You begin reading at the most significant digit, multiply it by 10 and add the next digit, multiply it by 10, and so on. – Manu3l0us Jan 08 '14 at 19:24
  • (((((1*10)+2)*10)+3)*10)+4=1234 – Manu3l0us Jan 08 '14 at 19:31