avr: add 8 bit multiplication.

This commit is contained in:
Martin Preuss
2026-05-05 17:25:50 +02:00
parent 43c69ca22e
commit c059b6aad3
2 changed files with 56 additions and 0 deletions

View File

@@ -21,6 +21,7 @@
m_ringbuffer.asm
m_ringbuffer_y.asm
multiply.asm
multiply8.asm
random.asm
ressource.asm
ringbuffer.asm

55
avr/common/multiply8.asm Normal file
View File

@@ -0,0 +1,55 @@
; ***************************************************************************
; copyright : (C) 2026 by Martin Preuss
; email : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome". *
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
#ifndef COMMON_MULTIPLY8_H
#define COMMON_MULTIPLY8_H
; ---------------------------------------------------------------------------
; @routine Utils_Mulu8x8_16
;
; Multiplies two unsigned 8 bit values resulting in one 16 bit value.
; This is a rather simple but reasonable fast routine working just like you would
; when doing multiplications with pen and paper.
;
; R17:R16 = R18 * R19
;
; TODO: adapt for signed values
;
; @param R18 8 bit value A
; @param R19 8 bit value B
; @return R17:R16 16 bit result
; @clobbers R19, R20, R21
Utils_Mulu8x8_16:
clr r17
clr r16
clr r20
ldi r21, 8 ; 8 bit multiplicator
Utils_Mulu8x8_16_loop:
lsr r19
brcc Utils_Mulu8x8_16_noadd ; current digit in B is 0, don't add shifted A to result
add r16, r18
adc r17, r20
Utils_Mulu8x8_16_noadd:
dec r21
breq Utils_Mulu8x8_16_done
lsl r18
rjmp Utils_Mulu8x8_16_loop
Utils_Mulu8x8_16_done:
clc
ret
; @end
#endif ; COMMON_MULTIPLY8_H