add general multiplication implementation

This commit is contained in:
hugova 2025-05-16 10:40:55 +02:00
parent bc3e07356e
commit 9a06f770c2
7 changed files with 48 additions and 2 deletions

View file

@ -0,0 +1,4 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;; public args
VAL_A = ARGVEC + 0
VAL_B = ARGVEC + 1

View file

@ -0,0 +1,27 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;I thoughtout russan thing
;;X * %1111001
;;= X + X*%1111000
;;= X + X*%1000 *%11111
;; to remember this for later, for duuqnds papper
.proc mult; user-procedure :clobbers A :clobbers-arguments 2
;; https://en.wikipedia.org/wiki/Ancient_Egyptian_multiplication#Russian_peasant_multiplication
.include "arithmatic.inc"
LDA #$00
loop:
ASL VAL_B
ROR VAL_A; add to awnser if VAL_A is odd
BCC loop
LSR VAL_B
ADC VAL_B; add val_b because val_a was odd.
ASL VAL_B
BNE loop
endloop:
RTS
.endproc

View file

@ -0,0 +1,10 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;Calculates $11 * $0E = $EE
.scope mult_test
.include "arithmatic.inc"
LDA #$0F
STA VAL_A
LDA #$07
STA VAL_B
JSR mult; A = $69 if it works as it should
.endscope

View file

@ -1,3 +1,4 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
.scope pixel_test .scope pixel_test
.include "pixel.inc" .include "pixel.inc"
LDA #$40 LDA #$40

View file

@ -1,4 +1,5 @@
;; public args ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;; public args
X_pos = ARGVEC + 0 X_pos = ARGVEC + 0
Y_pos = ARGVEC + 1 Y_pos = ARGVEC + 1
code = ARGVEC + 2 code = ARGVEC + 2

View file

@ -1,3 +1,4 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
.scope char_draw_test .scope char_draw_test
.include "char.inc" .include "char.inc"
LDA #$10 LDA #$10

View file

@ -8,11 +8,12 @@
.include "STARTUP.s" .include "STARTUP.s"
;.include "dubbel_buffer/raster_irqs.s" ;.include "dubbel_buffer/raster_irqs.s"
.include "routines/arithmatic/mult_test.s"
;.include "routines/line/line_test.s" ;.include "routines/line/line_test.s"
;.include "routines/text/char_draw_test.s" ;.include "routines/text/char_draw_test.s"
;.include "routines/pixel/pixel_test.s" ;.include "routines/pixel/pixel_test.s"
;.include "routines/memory/memcpy_test.s" ;.include "routines/memory/memcpy_test.s"
.include "routines/memory/memset_test.s" ;.include "routines/memory/memset_test.s"
;.include "routines/triangle/triangle_test.s" ;.include "routines/triangle/triangle_test.s"
exit: exit:
JMP exit JMP exit
@ -23,4 +24,5 @@ JMP exit
.include "routines/text/char_draw.s" .include "routines/text/char_draw.s"
.include "routines/memory/memset.s" .include "routines/memory/memset.s"
.include "routines/memory/memcpy.s" .include "routines/memory/memcpy.s"
.include "routines/arithmatic/mult.s"
.include "END.s" .include "END.s"