;--------------------------------------------------------
; File Created by SDCC : free open source ISO C Compiler
; Version 4.5.0 #15242 (Linux)
;--------------------------------------------------------
	.module main
	
;--------------------------------------------------------
; Public variables in this module
;--------------------------------------------------------
	.globl _main
	.globl _USART_Cmd
	.globl _USART_Init
	.globl _GPIO_ResetBits
	.globl _GPIO_SetBits
	.globl _GPIO_Init
	.globl _CLK_PeripheralClockConfig
	.globl _CLK_SYSCLKSourceSwitchCmd
	.globl _CLK_SYSCLKDivConfig
	.globl _CLK_GetSYSCLKSource
	.globl _CLK_SYSCLKSourceConfig
;--------------------------------------------------------
; ram data
;--------------------------------------------------------
	.area DATA
;--------------------------------------------------------
; ram data
;--------------------------------------------------------
	.area INITIALIZED
;--------------------------------------------------------
; Stack segment in internal ram
;--------------------------------------------------------
	.area SSEG
__start__stack:
	.ds	1

;--------------------------------------------------------
; absolute external ram data
;--------------------------------------------------------
	.area DABS (ABS)

; default segment ordering for linker
	.area HOME
	.area GSINIT
	.area GSFINAL
	.area CONST
	.area INITIALIZER
	.area CODE

;--------------------------------------------------------
; interrupt vector
;--------------------------------------------------------
	.area HOME
__interrupt_vect:
	int s_GSINIT ; reset
	int _TRAP_IRQHandler ; trap
	int 0x000000 ; int0
	int _FLASH_IRQHandler ; int1
	int _DMA1_CHANNEL0_1_IRQHandler ; int2
	int _DMA1_CHANNEL2_3_IRQHandler ; int3
	int _RTC_CSSLSE_IRQHandler ; int4
	int _EXTIE_F_PVD_IRQHandler ; int5
	int _EXTIB_G_IRQHandler ; int6
	int _EXTID_H_IRQHandler ; int7
	int _EXTI0_IRQHandler ; int8
	int _EXTI1_IRQHandler ; int9
	int _EXTI2_IRQHandler ; int10
	int _EXTI3_IRQHandler ; int11
	int _EXTI4_IRQHandler ; int12
	int _EXTI5_IRQHandler ; int13
	int _EXTI6_IRQHandler ; int14
	int _EXTI7_IRQHandler ; int15
	int _LCD_AES_IRQHandler ; int16
	int _SWITCH_CSS_BREAK_DAC_IRQHandler ; int17
	int _ADC1_COMP_IRQHandler ; int18
	int _TIM2_UPD_OVF_TRG_BRK_USART2_TX_IRQHandler ; int19
	int _TIM2_CC_USART2_RX_IRQHandler ; int20
	int _TIM3_UPD_OVF_TRG_BRK_USART3_TX_IRQHandler ; int21
	int _TIM3_CC_USART3_RX_IRQHandler ; int22
	int _TIM1_UPD_OVF_TRG_COM_IRQHandler ; int23
	int _TIM1_CC_IRQHandler ; int24
	int _TIM4_UPD_OVF_TRG_IRQHandler ; int25
	int _SPI1_IRQHandler ; int26
	int _USART1_TX_TIM5_UPD_OVF_TRG_BRK_IRQHandler ; int27
	int _USART1_RX_TIM5_CC_IRQHandler ; int28
	int _I2C1_SPI2_IRQHandler ; int29
;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
	.area HOME
	.area GSINIT
	.area GSFINAL
	.area GSINIT
	call	___sdcc_external_startup
	tnz	a
	jreq	__sdcc_init_data
	jp	__sdcc_program_startup
__sdcc_init_data:
; stm8_genXINIT() start
	ldw x, #l_DATA
	jreq	00002$
00001$:
	clr (s_DATA - 1, x)
	decw x
	jrne	00001$
00002$:
	ldw	x, #l_INITIALIZER
	jreq	00004$
00003$:
	ld	a, (s_INITIALIZER - 1, x)
	ld	(s_INITIALIZED - 1, x), a
	decw	x
	jrne	00003$
00004$:
; stm8_genXINIT() end
	.area GSFINAL
	jp	__sdcc_program_startup
;--------------------------------------------------------
; Home
;--------------------------------------------------------
	.area HOME
	.area HOME
__sdcc_program_startup:
	jp	_main
;	return from main will return to caller
;--------------------------------------------------------
; code
;--------------------------------------------------------
	.area CODE
;	../src/main.c: 24: void main(void)
;	-----------------------------------------
;	 function main
;	-----------------------------------------
_main:
;	../src/main.c: 27: Led_Init;
	push	#0xc0
	ld	a, #0x10
	ldw	x, #0x500a
	call	_GPIO_Init
;	../src/main.c: 28: blink(1);
	clrw	x
	incw	x
	call	_blink
;	../src/main.c: 29: USART_Config();
	call	_USART_Config
;	../src/main.c: 30: println("Hello");
	ldw	x, #(___str_0+0)
	call	_println
;	../src/main.c: 31: while (1);
00102$:
	jra	00102$
;	../src/main.c: 32: }
	ret
;	../src/main.c: 34: static void CLK_Config(void)
;	-----------------------------------------
;	 function CLK_Config
;	-----------------------------------------
_CLK_Config:
;	../src/main.c: 37: CLK_SYSCLKSourceSwitchCmd(ENABLE);
	ld	a, #0x01
	call	_CLK_SYSCLKSourceSwitchCmd
;	../src/main.c: 38: CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSE);
	ld	a, #0x08
	call	_CLK_SYSCLKSourceConfig
;	../src/main.c: 40: CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
	clr	a
	call	_CLK_SYSCLKDivConfig
;	../src/main.c: 41: while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_LSE);
00101$:
	call	_CLK_GetSYSCLKSource
	cp	a, #0x08
	jrne	00101$
	ret
	jra	00101$
;	../src/main.c: 42: }
	ret
;	../src/main.c: 44: static void blink(uint16_t repeats) {
;	-----------------------------------------
;	 function blink
;	-----------------------------------------
_blink:
	sub	sp, #4
	ldw	(0x01, sp), x
;	../src/main.c: 45: for (uint16_t i = 0; i <= repeats; i++) {
	clrw	x
	ldw	(0x03, sp), x
00111$:
	ldw	x, (0x03, sp)
	cpw	x, (0x01, sp)
	jrugt	00113$
;	../src/main.c: 46: Led_ON;
	ld	a, #0x10
	ldw	x, #0x500a
	call	_GPIO_SetBits
;	../src/main.c: 47: for (uint16_t j = 0; j <= 4000; j++) {nop();}
	clrw	x
00105$:
	ldw	y, x
	cpw	y, #0x0fa0
	jrugt	00101$
	nop
	incw	x
	jra	00105$
00101$:
;	../src/main.c: 48: Led_OFF;
	ld	a, #0x10
	ldw	x, #0x500a
	call	_GPIO_ResetBits
;	../src/main.c: 49: for (uint16_t j = 0; j <= 4000; j++) {nop();}
	clrw	x
00108$:
	ldw	y, x
	cpw	y, #0x0fa0
	jrugt	00112$
	nop
	incw	x
	jra	00108$
00112$:
;	../src/main.c: 45: for (uint16_t i = 0; i <= repeats; i++) {
	ldw	x, (0x03, sp)
	incw	x
	ldw	(0x03, sp), x
	jra	00111$
00113$:
;	../src/main.c: 51: }
	addw	sp, #4
	ret
;	../src/main.c: 53: static void putchar(uint8_t Data) {
;	-----------------------------------------
;	 function putchar
;	-----------------------------------------
_putchar:
;	../src/main.c: 54: while (!(USART1->SR & USART_FLAG_TXE));
00101$:
	ldw	x, #0x5230
	push	a
	ld	a, (x)
	ld	xh, a
	pop	a
	tnzw	x
	jrpl	00101$
;	../src/main.c: 55: USART1->DR = Data;
	ld	0x5231, a
;	../src/main.c: 56: }
	ret
;	../src/main.c: 58: static void print(const char* s){
;	-----------------------------------------
;	 function print
;	-----------------------------------------
_print:
;	../src/main.c: 59: while (*s) {
00101$:
	ld	a, (x)
	jrne	00121$
	ret
00121$:
;	../src/main.c: 60: putchar(*s++);
	incw	x
	pushw	x
	call	_putchar
	popw	x
	jra	00101$
;	../src/main.c: 62: }
	ret
;	../src/main.c: 64: static void println(const char* s){
;	-----------------------------------------
;	 function println
;	-----------------------------------------
_println:
;	../src/main.c: 65: print(s);
	call	_print
;	../src/main.c: 66: putchar('\n');
	ld	a, #0x0a
;	../src/main.c: 67: }
	jp	_putchar
;	../src/main.c: 69: static void USART_Config(void)
;	-----------------------------------------
;	 function USART_Config
;	-----------------------------------------
_USART_Config:
;	../src/main.c: 72: SYSCFG->RMPCR1 &= ~(0b11 << 4);
	ld	a, 0x509e
	and	a, #0xcf
	ld	0x509e, a
;	../src/main.c: 73: SYSCFG->RMPCR1 |= (0b01 << 4);
	bset	0x509e, #4
;	../src/main.c: 75: GPIO_Init(GPIOA, GPIO_Pin_2, GPIO_Mode_Out_PP_High_Fast);
	push	#0xf0
	ld	a, #0x04
	ldw	x, #0x5000
	call	_GPIO_Init
;	../src/main.c: 76: GPIO_Init(GPIOA, GPIO_Pin_3, GPIO_Mode_In_FL_No_IT);
	push	#0x00
	ld	a, #0x08
	ldw	x, #0x5000
	call	_GPIO_Init
;	../src/main.c: 78: CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);
	push	#0x01
	ld	a, #0x05
	call	_CLK_PeripheralClockConfig
;	../src/main.c: 80: USART_Init(USART1, (uint32_t)9600,
	push	#0x08
	push	#0x00
	push	#0x00
	push	#0x00
	push	#0x80
	push	#0x25
	clrw	x
	pushw	x
	ldw	x, #0x5230
	call	_USART_Init
;	../src/main.c: 83: USART_Cmd(USART1, ENABLE);
	ld	a, #0x01
	ldw	x, #0x5230
;	../src/main.c: 84: }
	jp	_USART_Cmd
	.area CODE
	.area CONST
	.area CONST
___str_0:
	.ascii "Hello"
	.db 0x00
	.area CODE
	.area INITIALIZER
	.area CABS (ABS)
