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

switching to User mode in keil assembly

Hi all,

Whenever I am running a new ARM assembly program in Keil uVision3 ,i find my program getting executed in a mode named current mode.

what is meant by current mode?
I have read that the default mode is USER mode.Also the supervisor mode is geeting enabled everytime.

Is Supervisior mode default in Keil uVision3?
I would like to know how I can switch to USER mode?

t.senthil

  • An ARM device starts always in supervisor mode.

    Take a look to the code in a STARTUP.S file. You will find the following code section.

    eset_Handler:
    // ---- NOTE ----
    // You may need device specific initilization code here.
    // For example: memory configuration or CPU clock setup.
    // --------------
    
    // Setup Stack for each mode
                    LDR     R0, =Top_Stack
    
    // Enter Undefined Instruction Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_UND|I_Bit|F_Bit
                    MOV     SP, R0
                    SUB     R0, R0, #UND_Stack_Size
    
    // Enter Abort Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_ABT|I_Bit|F_Bit
                    MOV     SP, R0
                    SUB     R0, R0, #ABT_Stack_Size
    
    // Enter FIQ Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_FIQ|I_Bit|F_Bit
                    MOV     SP, R0
                    SUB     R0, R0, #FIQ_Stack_Size
    
    // Enter IRQ Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_IRQ|I_Bit|F_Bit
                    MOV     SP, R0
                    SUB     R0, R0, #IRQ_Stack_Size
    
    // Enter Supervisor Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_SVC|I_Bit|F_Bit
                    MOV     SP, R0
                    SUB     R0, R0, #SVC_Stack_Size
    
    // Enter User Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_USR
                    MOV     SP, R0
    

    Reinhard