This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

BCD to binary conversion in Assembly

Hi,

I want to know how the 6 digit bcd is converted into hex value Ex: 123456 to 1E240. Please help me by providing the assembly code for 8051.

Parents Reply Children
  • Hi,macro

    I am not getting what you posted here

    Thanks

    Sharath

  • Why don't you simply ask a question - surely, you have encountered problems trying (have you?) - instead of asking for the whole thing really for shipment?

  • Hi macro

    This is what i have did...

    BCD2BIN:

    ; Input B R0R1 ; (B msd & R1 lsd)

    ; Output R2R3 ; (r2 msb)

    MOV B,#5H

    MOV R0,#10H

    MOV R1,#20H

    clr A

    mov R2,A

    mov R3,A ; release B reg to use in mul intruction

    mov a,b ; speed up if B (ms digits are 0)

    jz bb_230

    mov r4,a

    CALL DO_ONE_DIGIT

    bb_230:

    mov A,R0

    mov R4,A

    call DO_ONE_DIGIT

    mov a,R1

    mov R4,A

    Call DO_ONE_DIGIT

    ret

    DO_ONE_DIGIT:

    call BIN_MUL_10

    jc dod_10

    mov A,R4

    swap A

    anl A,#0fh

    add A,R3

    mov R3,A

    clr A

    addc a,r2

    mov r2,a

    call BIN_MUL_10

    jc dod_10

    mov A,R4

    anl A,#0fh

    add A,R3

    mov R3,A

    clr A

    addc a,r2

    mov r2,a

    dod_10:

    ret

    BIN_MUL_10:

    mov B,#10

    mov A,R3

    mul AB

    mov R3,A

    mov A,B

    xch A,R2

    mov B,#10

    mul AB

    add A,R2

    mov R2,A

    jc BM_10

    mov A,B

    jz BM_10

    cpl C

    BM_10: ret

    END

    If you know how to do for the higher values please let me know....

    Thanks

    Sharath

  • 
    JOHN:   PUSH    IE
            CLR     EA
            LCALL   EMANAL
            MOV     DPH,#JENIFER
            MOV     DPL,#WD2
            MOVX    A,@DPTR
            ANL     A,#06H
            CJNE    A,#06H,NATT1
    
            MOV     A,TNIPPLEL
            MOV     DPH,#JENIFER
            MOV     DPL,#TSADDL
            MOVX    @DPTR,A
            MOV     A,TNIPPLEH
            MOV     DPH,#JENIFER
            MOV     DPL,#TSADDH
            MOVX    @DPTR,A
    
    ANDY1:  MOV     A,TNIPPLEL
            MOV     DPH,#JENIFER
            MOV     DPL,#TEADDL
            MOVX    @DPTR,A
            MOV     DPL,#TEADDH
            MOV     A,TNIPPLEH
            MOVX    @DPTR,A
            POP     IE
    
            MOV     DPH,#JENIFER
            MOV     DPL,#WD2
            MOVX    A,@DPTR
            JB      ACC.1,NITJP
            CLR     IJSTAT
            LJMP    ITER2
    
    ANDY2:  JB      ACC.2,NIJMP3
            JNB     ITJMP,NIJMP1
    
    ERIK1:  SETB    IJSTAT
            MOV     DPH,#JENIFER
            MOV     DPL,#ITJUMP
            MOVX    A,@DPTR
            ANL     A,#0FH
            MOV     R1,A
            JZ      NIJMP1
            MOV     DPH,#JENIFER
            MOV     DPL,#APPTR+1
            MOVX    A,@DPTR
    ERIK2:  CLR     C
            SUBB    A,#4
            DJNZ    R1,DECAP1
            MOVX    @DPTR,A
    
    DEATH:  LCALL   TNBFAV
            LCALL   PANIC
            JNB     FULANAL,ONL58
    
            MOV     DPH,#JENIFER
            MOV     DPL,#QNIPPLEL
            MOVX    A,@DPTR
            MOV     DPL,#TSADDL
            MOVX    @DPTR,A
            MOV     DPL,#TEADDL
            MOVX    @DPTR,A
            MOV     TNIPPLEL,A
            MOV     DPL,#QNIPPLEH
            MOVX    A,@DPTR
            MOV     DPL,#TSADDH
            MOVX    @DPTR,A
            MOV     DPL,#TEADDH
            MOVX    @DPTR,A
            MOV     TNIPPLEH,A
            LCALL   MANALMT
            JB      NODATA,NOWEM2
            LJMP    OL458
    
    NOWEM2: CLR     FULANAL
            LJMP    OL458A
    
    ONL58:  POP     IE
    
    NIJMP2: LJMP    TURD
    
    NIJMP3: SETB    TRANST
            SJMP    NIJMP6
    
    NIJMP5: JB      LOWCH,NIJMP8
            SETB    DAT2TX
            POP     IE
            LJMP    SUPERV
    
    NIJMP6: MOV     DPL,TNIPPLEL
            MOV     DPH,TNIPPLEH
            MOV     DCRAP0,DPL
            MOV     DCRAP1,DPH
            MOV     A,#ATTDEL
            MOVX    @DPTR,A
            LCALL   PTRINC
            MOV     TNIPPLEL,DPL
            MOV     TNIPPLEH,DPH
            MOV     DPH,#JENIFER
            MOV     DPL,#QNIPPLEL
            MOV     A,TNIPPLEL
            MOVX    @DPTR,A
            MOV     DPL,#TSADDL
            MOVX    @DPTR,A
            MOV     DPL,#QNIPPLEH
            MOV     A,TNIPPLEH
            MOVX    @DPTR,A
            MOV     DPL,#TSADDH
            MOVX    @DPTR,A
    
            LCALL   ANALFUL
            LCALL   PANIC
            JNB     FULANAL,NIJMPC
    
    LIPGLOSS:
    
            MOV     DPH,DCRAP1
            MOV     DPL,DCRAP0
            MOV     A,#DELIMT
            MOVX    @DPTR,A
            CLR     TRANST
            LJMP    OL458
    
    
    
    

  • @macro micro,

    Why isn't my name labelled?!

  • hi macro,

    I am not getting any thing in what you have posted.. and I think this is not a code for bcd to hex conversion...

    Sharath

  • You didn't follow the instructions for posting source code, did you?

    Look at the picture - it tells you clearly what to do: www.danlhenry.com/.../keil_code.png

    Your code is also devoid of any meaningful comments.

    Your first step to understanding what that code does should be to comment what it is doing.

    Again, if you understand what your code is doing, you should easily be able to extend it to extra digits...

    BTW: Are you sure you are dealing with BCD here...?

  • @Tamir Michael,

    Sorry. I didn't mean to offend with my omission.

    TAMIR:  LCALL  DO_TAMIR_TYPE_THINGS
            LCALL  IS_DUMB_OP_QUESTION_PENDING
            JZ     TAMIR
            LCALL  ANSWER_DUMB_OP_QUESTION
            SJMP   TAMIR