Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to convert binary to BCD or decimal in assembly

Status
Not open for further replies.

mohamed saleh

Member level 3
Joined
Aug 26, 2006
Messages
62
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,768
binary to bcd assembly code

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

i want a code

thanks
 

convert bcd to decimal

Hello

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


Regards
 

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
 
hex to bcd assembly

mohamed saleh said:
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
 
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
 

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.
 

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

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.
 

Re: convert bcd to decimal

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.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top