DCD instruction and IRQ stack

Salvatore picture Salvatore · Oct 6, 2012 · Viewed 8.7k times · Source

I'm studying the topic of setting up a stack for different modes of an ARM processor (IRQ, Supervisor, User, ...). Since setting up different stacks requires the same sequence of instructions (basically only stack address change) I will ask my question resorting to the problem of setting up the IRQ stack. Provided that I have the following defines:

IRQ_Stack EQU 0x8000
NoInt     EQU 0xC0
IRQ32md   EQU 0x12

The following code is used to setup the stack (I add line numbers to enable comments):

1. MOV r2, #NoInt|IRQ32md
2. MSR CPSR_c, r2
3. LDR r13_irq, =IRQ_NewStack
4. ...
5. ...
6. IRQ_NewStack:
7. DCD IRQ_Stack

Line 1 just loads r2 for the purpose of disabling interrupts and entering IRQ mode in line 2, by loading the value into CPSR_c. Then, on line 3, LDR is used to load the (32 bit) address of the IRQ_NewStack label into the stack pointer banked in IRQ mode.

Could you please explain me what's the purpose of instruction on line 7?

I read on the ARM manual that DCD is used to "reserve a 32 bit word". When I read "reserve a 32 bit word", I think it's like reserving space for a single 32 bit variable, which means DCD acts as EQU (may be EQU is just a macro for DCD...). But, if this is the case, why should I reserve just a 32 bit word for the whole stack which can grow bigger than just one 32 bit word?

Thanks.

Answer

Pete Fordham picture Pete Fordham · Oct 6, 2012

The DCD reserves 1 32-bit word which points to the stack, it is not the stack itself.