From f647c68edf7a2b93b0cae1e2a62eaf69f9add80d Mon Sep 17 00:00:00 2001 From: hugova Date: Fri, 1 Aug 2025 00:17:12 +0200 Subject: [PATCH] fix testing for divition and add doc.. for mult.. --- host/src/routines/arithmatic/div_test.s | 39 +++++++++++++++++--- host/src/routines/arithmatic/div_test_zero.s | 18 +++++++++ host/src/routines/arithmatic/mult_test.s | 10 +++-- 3 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 host/src/routines/arithmatic/div_test_zero.s diff --git a/host/src/routines/arithmatic/div_test.s b/host/src/routines/arithmatic/div_test.s index 8787132..2cd0a32 100644 --- a/host/src/routines/arithmatic/div_test.s +++ b/host/src/routines/arithmatic/div_test.s @@ -1,10 +1,37 @@ ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- -;;Calculates $EE /$05 = $33 + +;; Note that the compile dont understand if its out of mem. +;; Please run without linking other stuff. thats also why some code is commented out. +;; Add it back in for debugging! .scope div_test + A_temp = $4043 .include "arithmatic.inc" - LDA #$05 - STA VAL_A - LDA #$02 - STA VAL_B - JSR div; X = $02 if it works as it should + .repeat $16, i + .repeat $16, j + ;INC $400D ;; print number of iterations on screen. + LDX #i + STX VAL_A + STX A_temp + LDY #(j+1) + STY VAL_B + JSR div ; A = VAL_A / VAL_B, clobers X. + CPX #i/(j+1) + BEQ :+ + jmp error + : + .endrepeat + .endrepeat + TXA + jmp end +error: + TXA + ;; Error make screen read + ;; X * Y has the result in A that is wrong. + LDX #$02 + STX $D020 +end: + LDX A_temp + ; X = VAL_A + ; Y = VAL_B + ; A = awnser. .endscope diff --git a/host/src/routines/arithmatic/div_test_zero.s b/host/src/routines/arithmatic/div_test_zero.s new file mode 100644 index 0000000..6e2509a --- /dev/null +++ b/host/src/routines/arithmatic/div_test_zero.s @@ -0,0 +1,18 @@ +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- + +;; Test if division with 0 is not stuck in infinate loop. +.scope div_test_zero + .include "arithmatic.inc" + .repeat $FF, i + INC $400D ;; print number of iterations on screen. + LDX #i + STX VAL_A + LDA #$00 + STA VAL_B + JSR div ; A = VAL_A / VAL_B, clobers X. + .endrepeat +paint: + ;; Donw make screen green + LDA #$13 + STA $D020 +.endscope diff --git a/host/src/routines/arithmatic/mult_test.s b/host/src/routines/arithmatic/mult_test.s index 252a9a7..8c4d682 100644 --- a/host/src/routines/arithmatic/mult_test.s +++ b/host/src/routines/arithmatic/mult_test.s @@ -1,11 +1,12 @@ ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- -;;Calculates $11 * $0E = $EE + +;; Note that the compile dont understand if its out of mem. +;; Please run without linking other stuff. thats also why some code is commented out. .scope mult_test A_temp = $4043 B_temp = $4046 .include "arithmatic.inc" - .repeat $0F, i ;; $15 = floor(sqrt($255)) - ;; now i * j_max = $FF --> j_max = $FF/i + .repeat $0F, i .repeat $0F, j INC $400D ;; print number of iterations on screen. LDX #i @@ -31,4 +32,7 @@ error: end: LDX A_temp LDY B_temp + ; X = VAL_A + ; Y = VAL_B + ; A = awnser. .endscope