; The quarter square multiply, against numbers whose products are known. ; ; a * b = qs[a+b] - qs[|a-b|], and the table of quarter squares is built by adding, so nothing ; in the whole arrangement needs a multiply to exist. What this checks is that the arrangement ; actually multiplies: the cases below cover nought, one, the commutation, a square, and the ; largest product two bytes can hold. ; ; Written by Anachronaut #Include print.asm #Include math.asm #Program start: CALL mulReady ; The table, once, before anything asks for a product. RSTA CALL times ; 0 x 0 INIA 0d7 SETD.0 MulA STA.0 RSTA SETD.0 MulB STA.0 CALL show ; 7 x 0, which is the other way round from the last one. INIA 0d1 CALL both CALL show ; 1 x 1 INIA 0d12 CALL both CALL show ; 12 x 12, a square, which is the case the identity leans on: ; the difference term is nought and the whole answer is one entry. INIA 0d3 SETD.0 MulA STA.0 INIA 0d200 SETD.0 MulB STA.0 CALL show ; 3 x 200 INIA 0d200 SETD.0 MulA STA.0 INIA 0d3 SETD.0 MulB STA.0 CALL show ; and 200 x 3, which had better agree. INIA 0xFF CALL both CALL show ; 255 x 255, the largest a byte times a byte can be. HALT ; A in both operands, for the square cases. both: SETD.0 MulA STA.0 SETD.0 MulB STA.0 RET ; A in both, then show it. The nought case wants this and nothing else does. times: CALL both CALL show RET ; The product, high byte then low, which is how a sixteen bit number reads. show: CALL mul8 SETD.0 MulHigh LDA.0 CALL printByteHex SETD.0 MulLow LDA.0 CALL printByteHex CALL lineFeed RET