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

ARM assembler register read

Note: This was originally posted on 11th September 2010 at http://forums.arm.com

Hello All,

I need a quick example of how to place a value from a hardware register (0x70001234 for example) into a register such as R0
then compare it to a constant such as 0xE0680003 and do a branch based on equality.

So far I have had no luck getting something this simple to work.

Thanks,
Dennis
Parents
  • Note: This was originally posted on 13th September 2010 at http://forums.arm.com

    Thanks for the reply, here in a nutshell is what I am trying to do, just not sure if my approach is correct.

    CSP_BASE_REG_PA_SRC     EQU     (0x73FD0000)
    SBMR     EQU     CSP_BASE_REG_PA_SRC+4

    ; read contents of SMBR register into r1
        ldr     r1, =(SBMR)
    ; load constant value to compare against
    ldr  r2, =0xE0680003
    ; compare and branch if equal
        cmp  r1, r2   
        beq  sd2_wml

    Thanks.

    [font="Courier New"]load_compare_RAM
    ;           ldr     r0, = 0xE0680003            ; constant to be compared with
                ldr     r0, [pc, #0x14]             ; get the constant at [pc + 20d] = 0xE0680003

    ;           ldr     r1, = 0x70001234            ; RAM addr
                ldr     r1, [pc, #0x14]             ; get the constant at [pc + 20d] = 0x70001234. This is the RAM addr

                ldr     r2, [r1, #0]                ; offsset = 0. Read RAM
                CMP     r0, r2                      ;
                BEQ     eq_cmp                      ; jump to next block if Z

    neq_cmp
                B       next_block1
    eq_cmp
                B       next_block2
                DCD     0xE0680003                  ; DCD = .word
                DCD     0x70001234                  ; DCD = .word


    next_block1
                ; next block1 of codes here

    next_block2
                ; next block2 of codes here[/font]


    ; #############################
    ; the 2 commented lines are the pseudo instructions. If you enable them, you do not
    ; need the line below each of them. In this case, you would also not need the 2 DCD lines.
    ;
    ; The active codes above are a manual way of creating a literal pool (of constants). If you use
    ; the pseudo-instr, you let the assembler do all the work for you.
    ;
    ; This web page removes all my nice spaces in the assembly codes and compresses them.   :)
Reply
  • Note: This was originally posted on 13th September 2010 at http://forums.arm.com

    Thanks for the reply, here in a nutshell is what I am trying to do, just not sure if my approach is correct.

    CSP_BASE_REG_PA_SRC     EQU     (0x73FD0000)
    SBMR     EQU     CSP_BASE_REG_PA_SRC+4

    ; read contents of SMBR register into r1
        ldr     r1, =(SBMR)
    ; load constant value to compare against
    ldr  r2, =0xE0680003
    ; compare and branch if equal
        cmp  r1, r2   
        beq  sd2_wml

    Thanks.

    [font="Courier New"]load_compare_RAM
    ;           ldr     r0, = 0xE0680003            ; constant to be compared with
                ldr     r0, [pc, #0x14]             ; get the constant at [pc + 20d] = 0xE0680003

    ;           ldr     r1, = 0x70001234            ; RAM addr
                ldr     r1, [pc, #0x14]             ; get the constant at [pc + 20d] = 0x70001234. This is the RAM addr

                ldr     r2, [r1, #0]                ; offsset = 0. Read RAM
                CMP     r0, r2                      ;
                BEQ     eq_cmp                      ; jump to next block if Z

    neq_cmp
                B       next_block1
    eq_cmp
                B       next_block2
                DCD     0xE0680003                  ; DCD = .word
                DCD     0x70001234                  ; DCD = .word


    next_block1
                ; next block1 of codes here

    next_block2
                ; next block2 of codes here[/font]


    ; #############################
    ; the 2 commented lines are the pseudo instructions. If you enable them, you do not
    ; need the line below each of them. In this case, you would also not need the 2 DCD lines.
    ;
    ; The active codes above are a manual way of creating a literal pool (of constants). If you use
    ; the pseudo-instr, you let the assembler do all the work for you.
    ;
    ; This web page removes all my nice spaces in the assembly codes and compresses them.   :)
Children
No data