electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

how to convert binary to BCD or decimal in assembly


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers > how to convert binary to BCD or decimal in assembly
Author Message
mohamed saleh



Joined: 26 Aug 2006
Posts: 67


Post05 Sep 2006 21:35   

binary to bcd assembly code


i want to know how to convert binary to BCD or decimal in assembly

i want a code

thanks
Back to top
Google
AdSense
Google Adsense




Post05 Sep 2006 21:35   

Ads




Back to top
Ave_Rapina



Joined: 06 Jan 2004
Posts: 121
Helped: 14
Location: Po


Post05 Sep 2006 22:05   

convert bcd to decimal


Hello

In assembly you can use an instruction that is DA that means Decimal adjust.


Regards
Back to top
16F676



Joined: 14 Aug 2006
Posts: 44
Helped: 3


Post05 Sep 2006 22:17   

binary to bcd assembly


This is the routine to convert 16bit binary to BCD in assembly
for pic micro.


Code:
          CBLOCK 0X20
 
BCDvalH
BCDvalM
BCDvalL
MCount
NumbHi
NumbLo
           ENDC

;
; Binary to BCD conversion routine
; 16 bit number to convert is in NumbHi, NumbLo
; result is set in BCDval HML
;
HexBCD    movlw d'16'
   movwf MCount
   clrf BCDvalH
   clrf BCDvalM
   clrf BCDvalL
   bcf STATUS,C

loop16    rlf NumbLo,F
   rlf NumbHi,F
   rlf BCDvalL,F
   rlf BCDvalM,F
   rlf BCDvalH,F

   decf MCount,F
   btfsc STATUS,Z
   return

adjDEC    movlw BCDvalL
   movwf FSR
   call adjBCD
   movlw BCDvalM
   movwf FSR
   call adjBCD
   movlw BCDvalH
   movwf FSR
   call adjBCD
   goto loop16

adjBCD   movlw d'3'
   addwf INDF,W
   movwf Temp
   btfsc Temp,3
   movwf INDF
   movlw 30h
   addwf INDF,W
   movwf Temp
   btfsc Temp,7
   movwf INDF
   return
   end
Back to top
khaled_shaheen



Joined: 05 Sep 2006
Posts: 6


Post05 Sep 2006 22:51   

hex to bcd assembly


mohamed saleh wrote:
i want to know how to convert binary to BCD or decimal in assembly

i want a code

thanks

you can use simble method for converting 8 bit binary number into decimal equivelt stored in 3 memory locations
code for 8051 family( let r0 contain the binary number and r1,r2,r3 contain decimal equavelent)

BIN_DEC: MOV A,R0
MOV B,#100
DIV AB
MOV R3,A ; R3 CONTAIN HUNDRED NUMBER
MOV A,B
MOV B,#10
DIV AB
MOV R2,A ; R2 CONTAIN TENTH NUMBER
MOV R1,B ; R1 CONTAIN LEFT DECIMAL NUMBER
RET
Back to top
mohamed saleh



Joined: 26 Aug 2006
Posts: 67


Post05 Sep 2006 23:04   

convert binary to bcd


thank you very much
Back to top
Davechika



Joined: 08 Oct 2009
Posts: 10
Location: Nigeria


Post30 Dec 2009 18:12   

how to convert binary to BCD or decimal in C/C++ code


how can i convert hex values that is read from counter 0 of 89S52 to binary or to Decimal values
Back to top
Davechika



Joined: 08 Oct 2009
Posts: 10
Location: Nigeria


Post31 Dec 2009 10:04   

how to convert binary to BCD or decimal in assembly


pls can can i convert hex values retrived fro counters to ascii decimal values which is sent to the serial buffer of 8952 microcontroller

Added after 30 minutes:

How can can i convert hex values e.g (0x40,0x12,0x0A) retrived from 89S52 counters to ascii decimal values e.g (64,18,10) which is sent to the serial buffer (SBUF) of 8952 microcontroller.
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers > how to convert binary to BCD or decimal in assembly
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
How to convert Hex values to Binary or Decimal using C/C++ (3)
bcd - convert digital to decimal (2)
Whats the easiest way to convert Binary to BCD (8)
Convert 26 bit binary to BCD Routine (1)
how to convert signed decimal to unsigned decimal? (7)
how to convert 8bit binary to milivolt..in PIC16F84 (2)
how can ı design a bcd to decimal decoder usin the (2)
how to convert floating numbers in hex to use in assembly? (3)
A problem with Binary to BCD conversion in C (1)
how to convert image,sound and text into binary in simulink (2)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS