??? 12/27/99 19:55 Read: times |
#1096 - RE: 32bit maths on 8052 |
Hi Steve,
There are some ways here to optimize your DIV_16. 1) You can delete the following fragment MOV TMP_0,#0 MOV TMP_1,#0 MOV TMP_2,#0 MOV TMP_3,#0 because you make 32 shifts and so you lose the old contents of TMP all the same. It takes 8 cycles. OK? 2) You can insert the bodies of subroutines SHIFT_D and SHIFT_Q instead of CALL SHIFT_D and CALL SHIFT_Q respectively. It takes 2*3*32=192 cycles. 3) You can save the contents of TMP in the OP adding 1 in bit 0 of the OP via INC OP_0 instruction. Besides, after the end of DIV_LOOP you don't need to rewrite TMP into OP. It takes 3+21*32+12-1=686 cycles. The subroutine will be like this. ;This divides the 32 bit OP register by the value supplied DIV_16: MOV R7,#0 ;R0 div_16 msb, R1 div_16 lsb MOV R6,#0 ;zero out partial remainder ; MOV R1,?Div_16?byte ;load divisor ; MOV R0,?Div_16?byte+1 MOV R5,#32 ;loop count ;This begins the loop DIV_LOOP: CLR C MOV A,OP_0 RLC A MOV OP_0,A MOV A,OP_1 RLC A MOV OP_1,A MOV A,OP_2 RLC A MOV OP_2,A MOV A, OP_3 RLC A MOV OP_3,A MOV A,R6 ;shift carry into LSB of partial remainder RLC A MOV R6,A MOV A,R7 RLC A MOV R7,A ;now test to see if R7:R6 >= R1:R0 CLR C MOV A,R7 ;subtract R1 from R7 to see if R1 < R7 SUBB A,R1 ;A=R7-R1, carry set if R7<R1 JC QUOT ;at this point R7>R1 or R7=R1 JNZ CAN_SUB ;jump if R7>R1 ;if R7=R1, test for R6>=R0 CLR C MOV A,R6 SUBB A,R0 ;A=R6-R0, carry set if R6<R0 JC QUOT ;Subtract the divisor from the partial remainder CAN_SUB: CLR C MOV A,R6 SUBB A,R0 ;A= R6-R0 MOV R6,A MOV A,R7 SUBB A,R1 ;A =R7-R1-BORROW MOV R7,A INC OP_0 ;Add 1 into bit0 QUOT: DJNZ R5,DIV_LOOP ;Now we're all done RET What do you think about it? How time takes it now? Can you test it and tell me? Well, I hadn't finished but I am falling asleep. Have a nice day, Igor |
Topic | Author | Date |
32bit maths on 8052 | 01/01/70 00:00 | |
RE: 32bit maths on 8052 | 01/01/70 00:00 | |
RE: 32bit maths on 8052 | 01/01/70 00:00 | |
RE: 32bit maths on 8052 | 01/01/70 00:00 | |
RE: 32bit maths on 8052 | 01/01/70 00:00 | |
RE: 32bit maths on 8052 | 01/01/70 00:00 | |
RE: 32bit maths on 8052![]() | 01/01/70 00:00 |