AVR gcrt1.S weird call

0

So basically i have decompiled unoptimized simple program and saw that it runs through gcrt1.S, and i dived in to assembly language and tried to understand what exactly it does. here is my code and my assumption of what it does

00000034  CLR R1        Clear Register 
00000035  OUT 0x3F,R1       Out to I/O location 
00000036  SER R28       Set Register        
00000037  LDI R29,0x08      Load immediate      
00000038  OUT 0x3E,R29      Out to I/O location 
00000039  OUT 0x3D,R28      Out to I/O location 
0000003A  CALL 0x00000040       Call subroutine 
0000003C  JMP 0x00000050        Jump 
0000003E  JMP 0x00000000        Jump 


Clear R1
Clear stratus register
Set R28 1111 1111

Here is where my questions start:
Load R29 from 0x08 (PORTC ?)
OUT to SPH <-R29
OUT to SPL <-R28
Call Main

The confuision that i have is why it loads byte from PORTC register, since the default would be 0x00 anyway

Microcontroller is atmega328p link to a datasheet

avr
avr-gcc
asked on Stack Overflow Jan 24, 2020 by Anton Stafeyev

1 Answer

1

Load R29 from 0x08 (PORTC ?)

The instruction is LDI R29,0x08 which loads 8 into R29. LDI is "load immediate to register"; it does not read from memory, see section "31. Instruction Set Summary" in the ATmega328 manual you are using. The code is initializing the frame pointer Y from symbol __stack, see startup code in gcrt1.S.

answered on Stack Overflow Jan 24, 2020 by emacs drives me nuts • edited Jun 20, 2020 by Community

User contributions licensed under CC BY-SA 3.0