Microchip provides the following code as a 16 x 16 unsigned multiply in several 18F datasheets (I got it from the 18F1220/1320 datasheet): ; RES1:RES0 = ARG1L * ARG2L MOVF ARG1L, W MULWF ARG2L MOVFF PRODH, RES1 MOVFF PRODL, RES0 ; RES3:RES2 = ARG1H * ARG2H MOVF ARG1H, W MULWF ARG2H MOVFF PRODH, RES3 MOVFF PRODL, RES2 ; RES3:RES2:RES1 += ARG1L * ARG2H MOVF ARG1L, W MULWF ARG2H MOVF PRODL, W ADDWF RES1, F MOVF PRODH, W ADDWFC RES2, F CLRF WREG ADDWFC RES3, F ; RES2:RES2:RES1 += ARG1H * ARG2L MOVF ARG1H, W MULWF ARG2L MOVF PRODL, W ADDWF RES1, F MOVF PRODH, W ADDWFC RES2, F CLRF WREG ADDWFC RES3, F This code takes 28 code words and 28 cycles (contrary to the timing in the datasheet which claims 24 code words/24 cycles (I think they counted the MOVFFs as 1/1 instread of 2/2). I figured that this could be improved upon and this is what I came up with: ; RES1:RES0 = ARG1L * ARG2L movf ARG1L,F mulwf ARG2L movff PRODL,RES0 movff PRODH,res1 ; RES2:RES1 += ARG1L * ARG2H mulwf ARG2H movf PRODL,W addwf RES1,F clrf WREG addwfc PRODH,W movwf RES2 ; NOTE: It is OK not to carry into RES3 here ; because the maximum value in RES2:RES1:RES0 ; would be: FEFF01, which doesn't carry into ; RES3 ; RES3:RES2 += ARG1H * ARG2H movf ARG1H,W mulwf ARG2H movf PRODL,W addwf RES2,F clrf WREG addwfc PRODH,W movwf RES3 ; RES3:RES2:RES1 += ARG1H * ARG2L movf ARG1H,W mulwf ARG2L,W movf PRODL,W addwf RES1,F clrf WREG addwfc RES2,F addwfc RES3,F This is 26 code words / 26 cycles, or 2/2 better than the datasheet routine. Can anybody improve on this?? There is a similar situation with the 16 x 16 signed multiplication routine. Bob Ammerman RAm Systems -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body