| Author |
Message |
mohamed saleh
Joined: 26 Aug 2006 Posts: 64
|
05 Sep 2006 21:35 binary to bcd assembly code |
|
|
|
|
i want to know how to convert binary to BCD or decimal in assembly
i want a code
thanks
|
|
| Back to top |
|
 |
Ave_Rapina
Joined: 06 Jan 2004 Posts: 121 Helped: 14 Location: Po
|
05 Sep 2006 22:05 convert bcd to decimal |
|
|
|
|
Hello
In assembly you can use an instruction that is DA that means Decimal adjust.
Regards
|
|
| Back to top |
|
 |
16F676
Joined: 14 Aug 2006 Posts: 44 Helped: 3
|
05 Sep 2006 22:17 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 |
|
|
| Back to top |
|
 |
Google AdSense

|
05 Sep 2006 22:17 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
khaled_shaheen
Joined: 05 Sep 2006 Posts: 6
|
05 Sep 2006 22:51 hex to bcd assembly |
|
|
|
|
| mohamed saleh wrote: |
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
|
|
| Back to top |
|
 |
mohamed saleh
Joined: 26 Aug 2006 Posts: 64
|
05 Sep 2006 23:04 convert binary to bcd |
|
|
|
|
| thank you very much
|
|
| Back to top |
|
 |