; Multiplication of unsigned integers using Algorithm 5.1 ; Register usage: ; R2: Q (multiplier) ; R3: A (accumulator) ; R5: M (multiplicand) ; R6: Count ; Constants: MostSigBit = ^X80000000 ; Selects highest-order bit ClearCarry = 1 ; Selects carry bit ; Variables: Multiplier: .LONG 25 ; (Value can be changed) Multiplicand: .LONG 1000 ; (Value can be changed) Product: .BLKQ 1 ; Reserve room for result .ENTRY Mult, 0 ; 1. Initialize: Init: CLRL R3 ; Clear A MOVL Multiplicand, R5 ; M <-- Multiplicand MOVL Multiplier, R2 ; Q <-- Multiplier ; 2. Loop: MOVL #32, R6 ; Count <-- 32 Repeat: BICPSW #ClearCarry ; Make sure carry is clear BLBC R2, CheckCarry ; If lsb. of Q = 1 then ADDL2 R5, R3 ; A <-- A + M CheckCarry: BCS CarrySet ; If C = 0 then ASHQ #-1, R2, R2 ; Shift AQ right BICL2 #MostSigBit, R3 ; and put 0 in left bit BRB Decrement CarrySet: ASHQ #-1, R2, R2 ; Else shift AQ right BISL2 #MostSigBit, R3 ; and put 1 in left bit Decrement: DECL R6 ; Decrement Count BGTR Repeat ; Repeat if needed ; 3. Store product: Store: MOVQ R2, Product ; Product <-- AC $EXIT_S .END Mult