Consider the following asm.S
.global main
main:
rjmp main
Compile and dump it with these commands:
avr-gcc -mmcu=atmega32u4 -g -o asm.elf asm.S
avr-objdump -S asm.elf
In initialization code, among other, there is this command:
ae: 1f be out 0x3f, r1 ; 63
Why there is this command?
Best Answer
The full initialiation sequence I see is:
Breaking it down:
Register 0x3f is SREG -- the status register, which contains status bits like N, Z, and C, as well as the interrupt enable bit. This code clears the register. The register should already be cleared at reset, but a bootloader or a partial software reset may have left it in an inconsistent state.
Ports 0x3d and 0x3e are the high and low portions of the stack pointer. This code initializes the stack pointer to 0x0AFF, at the top of RAM. This is, again, identical to the reset state of the processor, so this is more of a precaution than a necessity.
This calls your
main
function, then jumps to_exit
(an infinite loop) in casemain
returns.