| ??? 01/02/03 12:06 Read: times |
#35399 - Problem with : 16-Bit Division Sub |
Hi All,
Have you got any probelm with "16-Bit Division" Written by Jörg Rockstroh was posted in this site ? http://www.8052.com/div16.phtml I used this Sub in my program, it gave me the wrong result. But after that i find out that have a mistake in that: ;***************************** ..... div3: CPL C ;Invert carry, so it can be directly copied into result MOV A,R4 ;=====Problem is here RLC A ;Shift carry flag into temporary result MOV R4,A MOV A,R5 ;=====Problem is here RLC A MOV R5,A DJNZ B,div2 ;Now count backwards and repeat until "B" is zero ;***************************** At the first time of the loop the value in R4 and R5 is random, if the CPU just powered up it will work fine, but next time it will give you the wrong result. So we have to clear R4 and R5 at the begining of the sub. ;***************************** div16_16: MOV B,#00h ;Clear B since B will count the number of left-shifted bits MOV R4,#00h ;===insert this MOV R5,#00h ;===insert this ;***************************** Now it works fine, thank a lot to Jörg Rockstroh ! Happy New Year ! Cuong Vu. |
| Topic | Author | Date |
| Problem with : 16-Bit Division Sub | 01/01/70 00:00 | |
| RE: Problem with : 16-Bit Division Sub | 01/01/70 00:00 | |
RE: Problem with : 16-Bit Division Sub | 01/01/70 00:00 | |
| RE: Problem with : 16-Bit Division Sub | 01/01/70 00:00 | |
| RE: Problem with : 16-Bit Division Sub | 01/01/70 00:00 | |
| RE: Problem with : 16-Bit Division Sub | 01/01/70 00:00 |



