.syntax unified
.equ L152,1
.include "../Core/src/regs.s"
.global mainasm
mainasm:


.equ Op1plus,Bit4	//GPIOB
.equ Op1minus,Bit3	//GPIOB
.equ Op2plus,Bit0	//GPIOB
.equ Op2minus,Bit1	//GPIOA
.equ Auswahl,Bit6	//GPIOA
.equ rechne,Bit10	//GPIOA
main:
		bl	startLCD
	    bl 	LCD_i2c_clear
	    mov	R1,#0	//1. Zahl
	    mov	R2,#0	//2. Zahl
	    mov	R3,#0	//Operation: 0='+', 1='-', 2='x', 3=':'
	    mov	R4,#0	//Ergebnis
	    ldr	R5,=GPIOA
	    ldr R6,=GPIOB
schleife:
//Ausgabe:
		mov R0,#100
		bl	wait_ms
		bl	LCD_i2c_clear
		mov	R0,#0
		bl	LCD_i2c_cursorpos
		mov	R0,R1
		bl	LCD_i2c_dezaus
		cmp	R3,#0
		beq	zplus
		cmp	R3,#1
		beq zminus
		cmp R3,#2
		beq	zmal
		mov R0,#'/'
		b	zweiter
zmal:	mov	R0,#'*'
		b	zweiter
zminus: mov	R0,#'-'
		b	zweiter
zplus:	mov	R0,#'+'
zweiter:
		bl LCD_i2c_asciaus
		mov	R0,R2
		bl	LCD_i2c_dezaus
		mov	R0,#0x40
		bl	LCD_i2c_cursorpos
		mov	R0,R4
		bl	LCD_i2c_dezaus
	    ldr R0,[R6,IDR]
	    tst	R0,Op1plus
	    bne	_1
	    tst	R0,Op1minus
	    bne	_2
	    tst R0,Op2plus
	    bne	_3
	    ldr	R0,[R5,IDR]
	    tst R0,Op2minus
	    bne	_4
	    tst R0,Auswahl
	    bne _5
	    tst R0,rechne
	    bne _6
		b	schleife
_1:		add	R1,#1
_1w:	ldr R0,[R6,IDR]
	    tst	R0,Op1plus
	    bne	_1w
	    b 	schleife

_2:		sub	R1,#1
_2w:	ldr R0,[R6,IDR]
	    tst	R0,Op1minus
	    bne	_2w
	    b 	schleife

_3:		add	R2,#1
_3w:	ldr R0,[R6,IDR]
	    tst	R0,Op2plus
	    bne	_3w
	    b 	schleife

_4:		sub	R2,#1
_4w:	ldr R0,[R5,IDR]
	    tst	R0,Op2minus
	    bne	_4w
	    b 	schleife

_5:		add	R3,#1
		cmp	R3,#4
		bne	_5w
		mov	R3,#0
_5w:	ldr R0,[R5,IDR]
	    tst	R0,Auswahl
	    bne	_5w
	    b 	schleife

_6:		cmp	R3,#0
		beq	plus
		cmp R3,#1
		beq minus
		cmp R3,#2
		beq mal
geteilt:
		udiv R4,R1,R2
		b _6w
mal:	mul  R4,R1,R2
		b _6w
minus:	sub	R4,R1,R2
		b _6w
plus:   add R4,R1,R2
_6w:
	    ldr	R0,[R5,IDR]
	    tst R0,rechne
	    bne _6w
	    b 	schleife

.end
