debug tool for STM32F042F6P6
check_2_bit.s
- Committer:
- bieleluk
- Date:
- 2019-04-15
- Revision:
- 0:98789a3f7363
- Child:
- 24:bc7c4e8f3fe0
File content as of revision 0:98789a3f7363:
USART_ISR_Offset EQU 0x1C USART_TDR_Offset EQU 0x28 USART2 EQU 0x40004400 AREA asm_func, CODE, READONLY ; Export my_asm function location so that C compiler can find it and link EXPORT check_2_bit check_2_bit PUSH {LR} ;R0 = GPIOx ;R1 = offset ;r2 = pin_number LDR R3, [R0, R1] LDR R0, =30 SUBS R0,R2 SUBS R0,R2 LSLS R3,R3,R0 LSRS R3,#30 ;MOVS R1,R3 ;BL PRINT_HEXA MOVS R0,R3 POP {PC} ;******************************************** ;* Function: UART_PUTCHAR ;* Brief: ;* Input: R0 ;* Output: ;******************************************** UART_PUTCHAR PROC PUSH {R0,R1,R2,R3,LR} LDR R2,=USART2 UT_WAIT_FOR_UART LDR R1,[R2,#USART_ISR_Offset]; load status register MOVS R3, #(1 :SHL: 7) ;check TXE (bit 7) TST R1,R3 BEQ UT_WAIT_FOR_UART ;loop here until ready STRH R0,[R2,#USART_TDR_Offset] ;transmit buffer is ready, fill it with new value POP {R0,R1,R2,R3,PC} ENDP ;******************************************** ;******************************************** ;* Function: PRINT_DECIMAL ;* Brief: ;* Input: R1 ;* Output: ;******************************************** PRINT_DECIMAL PROC PUSH {R0,R2,LR} CMP R1, #0 BNE CONTINUE LDR R0, =48 BL UART_PUTCHAR B EXIT CONTINUE LDR R2,=1000000; delitel DIVIDE CMP R1,R2 BHS ONE_SIGN BL DIVIDE_BY_TEN B DIVIDE ONE_SIGN LDR R0,=0 CMP R1,R2 BLT PLOT SUBSTRACT SUBS R1,R2 ADDS R0,#1 CMP R1,R2 BHS SUBSTRACT PLOT ADDS R0,#48 BL UART_PUTCHAR BL DIVIDE_BY_TEN CMP R2,#0 BNE ONE_SIGN EXIT POP {R0,R2,PC} ENDP ;******************************************** ;******************************************** ;* Function: DIVIDE_BY_TEN ;* Brief: ;* Input: R2 ;* Output: R2 ;******************************************** DIVIDE_BY_TEN PROC PUSH {R1,R3,R4, LR} ;R1 10X R4 = 10 R3 LDR R3,=0 LDR R4,=1 CMP R2,R4;AK JE CISLO 1, VYNULUJ HO BEQ FINITO LDR R1,=10;10X VACSIE AKO R3 LDR R4,=10;KONSTANTA LDR R3,=1 DIVISION_LOOP CMP R2,R1; BEQ FINITO MULS R1,R4,R1 MULS R3,R4,R3 B DIVISION_LOOP FINITO MOVS R2,R3 POP {R1,R3,R4,PC} ENDP ;******************************************** ;******************************************** ;* Function: PRINT_HEXA ;* Brief: ;* Input: R1 ;* Output: ;******************************************** PRINT_HEXA PROC ;R0 je uz ten znak ;r1 je input ;r2 je pocek o ktory posuvame doprava ;r3 je pocet o ktory posuvame dolava ;r4 je vydelene cislo ;R5 JE CISLO OD 1 DO 8 PUSH {R0,R1,R2,R3,R4,R5,LR} LDR R0, ='0' BL UART_PUTCHAR LDR R0, ='x' BL UART_PUTCHAR CMP R1,#0 BNE NONZERO LDR R0, ='0' BL UART_PUTCHAR B END_OF_FUNCTION NONZERO LDR R2, =0;PRVE NENULOVE CISLO HO ZMENI LDR R3, =0 LDR R5, =8 AGAIN LDR R0, =0 SUBS R5, #1 MOVS R4, R1 LSLS R4, R4,R3 LSRS R4, R4, #28 CMP R4,#0 BEQ NOT_YET_PRINTING LDR R2, =1 NOT_YET_PRINTING CMP R4,#10 BLT NUMBER ;SIGN ADDS R0, #7 NUMBER ADDS R0, #48 ADDS R0,R4 CMP R2,#0 BEQ SKIP_PRINTING BL UART_PUTCHAR SKIP_PRINTING ADDS R3, #4 CMP R5,#0 BNE AGAIN END_OF_FUNCTION POP {R0,R1,R2,R3,R4,R5,PC} ENDP ;******************************************** ALIGN END