Jak napisac w asemblerze pod '51 procedure ktora zamieni dwubajtowa liczbe na dziesietna i wyswietli na LCD. Jednobajtowa potrafie bo dzieli sie kolejno przez 100, 10. Ale jak to zrobic z dwubajtowa? Prosze o jakies podpowiedzi. Pozdrawiam
jak konwersja z hex (2byte) na dec w asm '51?
Dec 12, 2003
2 Replies
Pewnego piêknego dnia Kuba przemówi³(a) ludzkim g³osem:
Znalezione na stronie microchipa
;==================================================================== ;************************************************************************ ; BIN16BCD ; The following routine converts an unsigned integer value in the ; range of 0 - 9999 to an unpacked Binary Coded Decimal number. No ; range checking is performed. ; ; INPUT: R3 (MSB), R2(LSB) contain the binary number to be ; converted. ; OUTPUT: R7(MSD), R6, R5, R4(LSD) contain the 4 digit, unpacked BCD ; representation of the number. ; Uses: R1,R2,R3,R4,R5,R6,R7,ACC ;************************************************************************ BIN16BCD: MOV R1,#16D ; loop once for each bit (2 bytes worth) MOV R5,#0 ; clear regs. MOV R6,#0 MOV R7,#0 BCD_16LP: MOV A,R2 ADD A,R2 MOV R2,A MOV A,R3 ADDC A,R3 MOV R3,A ;====== MOV A,R5 ADDC A,R5 DA A MOV R5,A MOV A,R6 ADDC A,R6 DA A MOV R6,A DJNZ R1,BCD_16LP ; loop until all 16 bits done ;================= ;unpack the digits ;================= SWAP A ;swap so that digit 4 is rightmost ANL A,#0FH ;mask off digit 3 MOV R7,A ;save digit 4 in R7 MOV A,R6 ;get digits 3,4 again ANL A,#0FH ;mask off digit 4 MOV R6,A ;save digit 3 MOV A,R5 ;get digits 1,2 SWAP A ;swap so that digit 2 is rightmost ANL A,#0FH ;mask off digit 1 XCH A,R5 ;put digit 2 in R5, digit 1 => ACC ANL A,#0FH ;mask off digit 2 MOV R4,A ;save digit 1 in R4 then exit RET ;====================================================================
Pozostaje dodaæ do ka¿dej cyfry kod zera i mo¿na wypluc na LCD.
formatting link
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required