+ Post New Thread

Results 1 to 10 of 10

- 5th September 2006, 21:35 #1

- Join Date
- Aug 2006
- Posts
- 62
- Helped
- 0 / 0
- Points
- 1,445
- Level
- 8

## binary to bcd assembly code

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

i want a code

thanks

- 5th September 2006, 22:05 #2

- Join Date
- Jan 2004
- Location
- Po
- Posts
- 122
- Helped
- 18 / 18
- Points
- 5,412
- Level
- 17

## convert bcd to decimal

Hello

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

Regards

- 5th September 2006, 22:05

- 5th September 2006, 22:17 #3

- Join Date
- Aug 2006
- Posts
- 43
- Helped
- 5 / 5
- Points
- 3,931
- Level
- 14

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

1 members found this post helpful.

- 5th September 2006, 22:17

- 5th September 2006, 22:51 #4

- Join Date
- Sep 2006
- Posts
- 6
- Helped
- 2 / 2
- Points
- 1,156
- Level
- 7

## hex to bcd assembly

Originally Posted by**mohamed saleh**

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.

- 5th September 2006, 22:51

- 5th September 2006, 23:04 #5

- Join Date
- Aug 2006
- Posts
- 62
- Helped
- 0 / 0
- Points
- 1,445
- Level
- 8

## convert binary to bcd

thank you very much

- 30th December 2009, 17:12 #6

- Join Date
- Oct 2009
- Location
- Port-Harcourt,Nigeria
- Posts
- 13
- Helped
- 0 / 0
- Points
- 920
- Level
- 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

- 31st December 2009, 09:04 #7

- Join Date
- Oct 2009
- Location
- Port-Harcourt,Nigeria
- Posts
- 13
- Helped
- 0 / 0
- Points
- 920
- Level
- 6

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

- 6th January 2011, 12:53 #8

- Join Date
- Jan 2011
- Posts
- 3
- Helped
- 0 / 0
- Points
- 360
- Level
- 4

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

- 15th March 2011, 16:18 #9

- Join Date
- Mar 2011
- Posts
- 1
- Helped
- 0 / 0
- Points
- 318
- Level
- 3

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

- 27th September 2013, 11:21 #10

- Join Date
- Sep 2013
- Posts
- 15
- Helped
- 0 / 0
- Points
- 253
- Level
- 3

+ Post New Thread

Please login

#### LinkBacks (?)

- 21st October 2014, 07:57