MyTetra Share
Делитесь знаниями!
math.asm
Время создания: 08.12.2017 21:41
Раздел: Electronics - Microcontrollers - AVR8 - AVR ASM - ASM_PROJ - DS18B20 - DS18B20 v.4

#ifndef MATH_ASM

#define MATH_ASM


convert_HEX_to_DEC:

; IN:

; R16 - source HEX nuber

; OUT:

; R23 - hundreds

; R24 - decimals

; R25 - units

//PUSH R16

PUSH R17

PUSH R18

PUSH R19


//LDS R16, var_temperature ; source (dividend)

LDI R17, 100 ; divisor

CLR R18

CLR R19

CALL devide

MOV R23, R18 ; save result of division as hundreds

MOV R16, R19 ; copy remainder as next dividend

LDI R17, 10 ; new divisor

CLR R18

CLR R19

CALL devide

MOV R24, R18 ; save result (decimals)

MOV R25, R19 ; save remainder (units)


POP R19

POP R18

POP R17

//POP R16

RET


devide:

;R16 - dividend

;R17 - divisor

;R18 - result

;R19 - remainder

devide_loop:

SUB R16, R17 ; dividend - divisor

BRMI devide_neg_result ; goto if result is negative

INC R18 ; if not - incr main result

RJMP devide_loop

devide_neg_result:

ADD R16, R17 ; back dividend + divisor

MOV R19, R16 ; save dividend as remainder

RET


#endif


Так же в этом разделе:
 
MyTetra Share v.0.53
Яндекс индекс цитирования