объём текста больше, не спорю, но не на много для примера : avr asm вычисление давления и температуры высотомера MS5607-02BA03 от ТЕ
типы: _w - слово(16), _d - двойное(32), _q - (64). muls/mul , divs/div signed/unsigned умножение , деление
имхо наглядность/читаемость вполне. на чистом асме писать - безумие, а макросы творят чудеса.
;********************************************************************
// dT = D2 - C5*2**8
;********************************************************************
........................................
clr_w E1
lds_w E0 , const_C5
lsl_n_d dE , 8 // R(32) <- 0 shift left, n- number shift
........................................
lds_d dF , adc_D2
sub_d dF , dE
........................................
sts_d data_dT , dF
........................................
;********************************************************************
// TEMP = 2000 + dT * C6 / 2**23
;********************************************************************
........................................
clr_w G1
lds_w G0 , const_C6
muls_d // qC = dH : dG = dG * dF
div2s_q qC , 23 // R(64) , n | R(64) = R(64) / 2^n signed
ldi_d dE , 2000
add_d dE , dG
........................................
sts_w data_TEMP , E0
........................................
;********************************************************************
// OFF = C2 * 2**17 + (C4 * dT) / 2**6
;********************************************************************
........................................
clr_q qA
lds_w C0 , const_C2
mul2_q qA , 17 // R(64) , n | R(64) = R(64) * 2^n signed/unsigned
........................................
lds_d dG , data_dT
clr_w F1
lds_w F0 , const_C4
muls_d // qC = dH : dG = dG * dF
div2s_q qC , 6 // R(64) , n | R(64) = R(64) / 2^n signed
........................................
add_q qA , qC
........................................
sts_q data_OFF , qA
........................................
;********************************************************************
// SENS = C1 * 2**16 + (C3 * dT) / 2**7
;********************************************************************
........................................
clr_q qA
lds_w C0 , const_C3
lds_d dE , data_dT
sig_dq dF , dE // (R32)h , (R32)l = signed quad (R32)h : (R32)l
muls_q // qC : qB = qB * qA
div2s_q qB , 7 // R(64) , n | R(64) = R(64) / 2^n signed
........................................
clr_q qA
lds_w C0 , const_C1
mul2_q qA , 16 // R(64) , n | R(64) = R(64) * 2^n signed/unsigned
........................................
add_q qB , qA
........................................
sts_q data_SENS , qB
........................................
;********************************************************************
// Pmbar = (D1 * SENS / 2**21 - OFF) / 2**15
;********************************************************************
........................................
clr_d dD
lds_D dC , adc_D1
muls_q // qC : qB = qB * qA
div2s_q qB , 21 // R(64) , n | R(64) = R(64) / 2^n signed
........................................
lds_q qA , data_OFF
........................................
sub_q qB , qA
........................................
div2s_q qB , 15 // R(64) , n | R(64) = R(64) / 2^n signed
........................................
sts_d data_PRESS_mbar , dE
........................................
;********************************************************************
// Pmmhg = (Pmbar * 7501)/100 000
;********************************************************************
mov_d dG , dE
muli_d 7501 // qC = dH : dG = dG * (K32)
........................................
divi_d 100000 // dG = dG / K(32)
........................................
sts_w data_PRESS_mmhg , G0
;********************************************************************