# how to convert binary to BCD or decimal in assembly

1. ## binary to bcd assembly code

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

i want a code

thanks

2. ## convert bcd to decimal

Hello

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

Regards

•

3. ## 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

movwf FSR
movlw BCDvalM
movwf FSR
movlw BCDvalH
movwf FSR
goto loop16

movwf Temp
btfsc Temp,3
movwf INDF
movlw 30h
movwf Temp
btfsc Temp,7
movwf INDF
return
end```

1 members found this post helpful.

•

4. ## hex to bcd assembly

Originally Posted by mohamed saleh
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

2 members found this post helpful.

•

5. ## convert binary to bcd

thank you very much

6. ## 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

•

7. ## 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

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.

8. ## Re: how to convert binary to BCD or decimal in assembly

can you help me convert 8bit to decimal in assembly language that can be used in pic16f877

9. ## Re: how to convert binary to BCD or decimal in assembly

Hey, I found this code was exactly what I needed.

Converts 16-Bit (2 Registers) To Unpacked BCD Decimal.
Works on the 18FXXX Series PIC

Integrated this code into my own project as a function call and works like a hot damn. Hope this helps.

10. ## Re: convert bcd to decimal

Originally Posted by Ave_Rapina
Hello

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

Regards
hi rapina,
is that possible to convert decimal to binary or binary to decimal conversion in VHDL / Xilinx.

--[[ ]]--