---
+ Post New Thread
Results 1 to 10 of 10
  1. #1
    Member level 3
    Points: 1,445, Level: 8

    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

  2. #2
    Full Member level 2
    Points: 5,412, Level: 17

    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



    •   Alt5th September 2006, 22:05

      advertising

        
       

  3. #3
    Member level 2
    Points: 3,931, Level: 14

    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.

  4. #4
    Newbie level 4
    Points: 1,156, Level: 7

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

    hex to bcd assembly

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

    •   Alt5th September 2006, 22:51

      advertising

        
       

  5. #5
    Member level 3
    Points: 1,445, Level: 8

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

    convert binary to bcd

    thank you very much



  6. #6
    Newbie level 6
    Points: 920, Level: 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



  7. #7
    Newbie level 6
    Points: 920, Level: 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 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.



  8. #8
    Newbie level 3
    Points: 360, Level: 4

    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



  9. #9
    Newbie level 1
    Points: 318, Level: 3

    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.



  10. #10
    Junior Member level 1
    Points: 253, Level: 3

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

    Re: convert bcd to decimal

    Quote Originally Posted by Ave_Rapina View Post
    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.



+ Post New Thread
Please login