# PICMicrocontollerMathMethod

## 24x24 multiplication

```        cblock
Product:6
Multipland:3
BitCount:1
endc

Multiplier EQU Product+3  ;3 bytes shared with Product's
;less significant bytes (+3..5)

MULTIPLY_24x24
; preload values to test
MOVLW   0xAB
MOVWF   Multipland
MOVLW   0xCD
MOVWF   Multipland+1
MOVLW   0xEF
MOVWF   Multipland+2

MOVLW   0x98
MOVWF   Multiplier
MOVLW   0x76
MOVWF   Multiplier+1
MOVLW   0x54
MOVWF   Multiplier+2

; these values should generate the reply = 0x6651AF33BC6C

;24 x 24 Multiplication
;Input:
; Multiplier - 3 bytes (shared with Product)
; Multiplicand - 3 bytes (not modified)
;Temporary:
; Bitcount
;Output:
; Product - 6 bytes

CLRF    Product         ; clear destination
CLRF    Product+1
CLRF    Product+2

MOVLW   D'24'
MOVWF   BitCount        ; number of bits

RRF     Product+3,F     ; shift out to carry
RRF     Product+4,F     ; next multiplier bit
RRF     Product+5,F

BTFSS   STATUS,C        ; if carry is set we must add multipland
; to the product
GOTO  SKIP_LOOP_24x24 ; nope, skip this bit

MOVF    Multipland+2,W  ; get LSB of multiplicand
ADDWF   Product+2,F     ; add it to the lsb of the product

MOVF    Multipland+1,W  ; middle byte
BTFSC   STATUS,C        ; check carry for overflow
INCFSZ  Multipland+1,W  ; if carry set we add one to the source
ADDWF   Product+1,F     ; and add it  (if not zero, in
; that case mulitpland = 0xff->0x00 )

MOVF    Multipland,W    ; MSB byte
BTFSC   STATUS,C        ; check carry
INCFSZ  Multipland,W
ADDWF   Product,F       ; handle overflow

SKIP_LOOP_24x24
; note carry contains most significant bit of

; shift in carry and shift out
; next multiplier bit, starting from less
; significant bit

RRF     Product,F
RRF     Product+1,F
RRF     Product+2,F
RRF     Product+3,F
RRF     Product+4,F
RRF     Product+5,F

DECFSZ  BitCount,F
RETURN

```

Questions:

• jasonzspam at issproinc.com asks:
Nikolai Golovchenko's 24 x 24 multiplication function does not work as listed and appears is in-complete !!! Multipler is define but never used as well as Product is not define but goes potluck. zeroes.

James Newton replies: Product is defined in the cblock at the beginning and Multiplier is used because it is actually part of Product. Works fine as far as I can tell.+

+

 file: /Techref/microchip/math/mul/24x24b-tk.htm, 3KB, , updated: 2010/3/30 08:18, local time: 2018/10/19 22:38, TOP NEW HELP FIND:  54.224.118.247:LOG IN

 ©2018 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?Please DO link to this page! Digg it! / MAKE! /  PIC Microcontoller Math Method - 24x24 multiplication

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here:
if you want a response, please enter your email address:
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
 Did you find what you needed? "No. I'm looking for: " "No. Take me to the search page." "No. Take me to the top so I can drill down by catagory" "No. I'm willing to pay for help, please refer me to a qualified consultant" "No. But I'm interested. me at when this page is expanded."

 PICList 2018 contributors: o List host: MIT, Site host massmind.org, Top posters @20181019 RussellMc, Van Horn, David, Sean Breheny, David C Brown, Isaac M. Bavaresco, Neil, Bob Blick, Harold Hallikainen, John Gardner, AB Pearce - UKRI STFC, * Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr.

.