0

I'm carefully following Baking Pi with my model B, making sure I fully understand everything going on. I am now at lesson 5, to flash the SOS Morse code. It works fine, but I am curious why it needs two ldr instructions to load the pattern. (Link to the site)

The data section defines:

.align 2
pattern:
    .int 0b11111111101010100010001000101010

And this pattern is loaded into register r4 (.req ptrn) by:

ptrn .req r4
ldr ptrn,=pattern
ldr ptrn,[ptrn]

So why the double ldr?

I tried without the second one, but that screws up the pattern. Does it have to do with the alignment? I thought the first Load Register would be enough to load the value.

Thanks :)

2

Okay, I figured it out myself...

The first ldr actually loads the address of the variable. And so to have the value of pattern in the register (rather than the address), I still have to load the value at the address into the register.

Also check here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.