/* Write a subroutine to multiply a 16-bit unsigned number * in the r25:r24 register pair by an 8-bit number in r26. * return the answer in r4:r3:r2 * Remember that when you multiply two numbers the result is in the * the r1:r0 register pair. * Study the following multiplication example to see how it is done. * * Multiply * r25:r24 * x r26 * ---------- * 0:r3:r2 = r16*r18 first byte * + r1:r0 = r17*r18 second byte * -------- * r4:r3:r2 = (r1 + c):(r3 + r0):r2 * * For additional help read "Binary hardware multiplication in AVR Assembler" * at http://www.avr-asm-tutorial.net/avr_en/calc/HARDMULT.html * * Test your hardware multiplication 16-by-8-bit subroutine * by running the following test code. */ .INCLUDE muls16x8_24_test: ldi r25,HIGH(10000) ; upper 8 bits of multiplicand ldi r24,LOW(10000) ; lower 8 bits of multiplicand ldi r26,250 ; 8-bit constant multiplier muls16x8_24: push r15 ; save contents of registers modified by this subroutine in r15, SREG push r24 push r1 push r0 clr r4 mul r24,r26 ; multiply LSB movw r3:r2,r1:r0 ; copy result to result register mul r25,r26 ; multiply MSB add r3,r0 adc r4,r1 pop r0 pop r1 pop r24 out SREG, r15 pop r15 ret