org $1000 M rmb 4 ; multiplicand N rmb 4 ; multiplier P rmb 8 ; product org $1500 ldd M+2 ; place ML in D ldy N+2 ; place NL in Y emul ; compute MLNL sty P+4 ; save the upper 16 bits of the partial product MLNL std P+6 ; save the lower 16 bits of the partial product MLNL ldd M ; place MH in D ldy N ; place NH in Y emul ; compute MHNH sty P ; save the upper 16 bits of the partial product MHNH std P+2 ; save the lower 16 bits of the partial product MHNH ldd M ; place MH in D ldy N+2 ; place NL in Y emul ; compute MHNL ; the following 7 instructions add MHNL to memory locations P+2~P+5 addd P+4 ; add the lower half of MHNL to P+4~P+5 std P+4 ; " tfr y,d ; transfer Y to D adcb P+3 stab P+3 adca P+2 staa P+2 ; the following six instructions propagate carry to the most significant byte ldaa P+1 adca #0 ; add C flag to location P+1 staa P+1 ; " ldaa P adca #0 ; add C flag to location P staa P ; the following three instructions compute MLNH ldd M+2 ; place ML in D ldy N ; place NH in Y emul ; compute MLNH ; the following 7 instructions add MLNH to memory locations P+2~P+5 addd P+4 ; add the lower half of MLNH to P+4~P+5 std P+4 ; " tfr y,d ; transfer Y to D adcb P+3 stab P+3 adca P+2 staa P+2 ; the following six instructions propagate carry to the most significant byte ldaa P+1 adca #0 ; add C flag to location P+1 staa P+1 ldaa P adca #0 ; add C flag to location P staa P end