It is currently Mon Dec 11, 2017 8:25 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Thu May 19, 2016 6:46 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19326
Location: NE Indiana, USA (NTSC)
"Store multiple to full-descending stack" means "push", and "load multiple from full-descending stack" means "pull". It's the RISC principle: if they already have "load multiple" and "store multiple", why create new instructions just for the stack?


Top
 Profile  
 
PostPosted: Fri May 20, 2016 1:54 am 
Offline

Joined: Mon Nov 10, 2008 3:09 pm
Posts: 431
nicklausw wrote:
nicklausw wrote:
Um...does anyone have any idea why lr might magically turn into pc in a subroutine? Because I have a problem where my subroutines will randomly turn into a bx lr loop sometimes, and I can't figure things out at all. Not sure what other information to provide.

Update, I figured this one out on my own.

Putting:
Code:
stmfd  sp!, {lr}

at the beginning of subroutines, and:
Code:
ldmfd  sp!, {pc}

at the end prevents recursive lr's. Now to figure out what the crap "stmfd" and "ldmfd" mean.


RISC architectures don't push the return address onto a RAM stack when a subroutine call occurs. They store it in a register instead (the "link register"). If a subroutine is a leaf subroutine it can just leave the return address there, but if it calls other subroutines then it needs to explicitly push the link register onto the stack.


Top
 Profile  
 
PostPosted: Tue May 24, 2016 9:22 am 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2420
Jarhmander wrote:
Bregalad wrote:
In this case
Code:
lda r0, =something


is probably equivalent to something like
Code:
here:
    lda r0, [r15], #something-here-8

The PC is always 2 words (8 bytes) ahead because of the pipeline.

Hell no, not only you fetch the wrong word, you'll corrupt the PC, or it will fault. This is post-indexed addressing, instead of regular offset addressing, which is the only form accepted for base addresses based on PC.
So it's more like:
Code:
    ldr r0, [pc, #off-8]

The -8 thing is true, PC is "ahead" because of pipeline. This is important to consider upon receiving imprecise faults (if I remember correctly!), the old PC points after the faulty instruction.


How do you know the offset anyway?


Top
 Profile  
 
PostPosted: Tue May 24, 2016 9:31 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19326
Location: NE Indiana, USA (NTSC)
Ideally, the assembler computes the offset for you.


Top
 Profile  
 
PostPosted: Wed May 25, 2016 9:21 pm 
Offline
Formerly ~J-@D!~
User avatar

Joined: Sun Mar 12, 2006 12:36 am
Posts: 445
Location: Rive nord de Montréal
psycopathicteen wrote:
How do you know the offset anyway?

tepples wrote:
Ideally, the assembler computes the offset for you.


When using the right instructions, you don't have to compute any offsets, the assembler does that job for you. For example, ldr r0, =const is transformed by the assembler for you to ldr r0, [pc, #magicoffset], like Bregalad said, where the magic offset is computed by the assembler so it loads a word after the subroutine from the so-called literal pool. When using labels, like any other assemblers, it does put the right offset in the instruction, just like in any 6502 assembler when you do things like ex: beq Label.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group