ARM assembly language

Discussion in 'Embedded Systems and Microcontrollers' started by udin senid, Sep 17, 2013.

  1. udin senid

    Thread Starter New Member

    Sep 17, 2013
    1
    0
    guys im new to this stuff, and this is really confusing me



    .section .rodata
    label1:
    .asciz "Hello World"
    .text
    .global main

    main:

    sub sp, sp, #4
    str lr, [sp, #0]

    ldr r0, = label1
    bl puts

    ldr lr, [sp, #0]
    add sp, sp, #4

    mov r0, #0
    mov pc, lr



    why do we have to store 'lr'??????
    why cant we load the string directly to the register and print it?????????
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,136
    1,786
    lr is the link register and the syntax for the operations is:
    destination, source.

    mov pc,lr is the return instruction from main. It does this by putting the contents of lr into the pc (program counter)

    puts is the subroutine that prints the string!!
     
  3. embpic

    Member

    May 29, 2013
    187
    3
    yes he is right lr is link register when execution flow goto any function then pc loaded with next instruction and stack pointer loaded with data or register and link register is loaded with RETURN ADDRESS that is where to come after completing that function.
     
Loading...