diff --git a/host/src/routines/arithmatic/mult.s b/host/src/routines/arithmatic/mult.s index f22f76f..fe064b6 100644 --- a/host/src/routines/arithmatic/mult.s +++ b/host/src/routines/arithmatic/mult.s @@ -11,8 +11,13 @@ .include "arithmatic.inc" - LDA #$00 - JMP start + LDA #$00 ;; A = value to return. + + ;; 0 * 0 will never terminate so we need to fix this. + LDX VAL_A + BNE start + ;; Now we have 0 * something. Instead of handeling [something = 0] we are more general and always return 0. + RTS ;; returning A = 0. loop: ASL VAL_B start: diff --git a/host/src/routines/arithmatic/mult_test.s b/host/src/routines/arithmatic/mult_test.s index 2095ef2..252a9a7 100644 --- a/host/src/routines/arithmatic/mult_test.s +++ b/host/src/routines/arithmatic/mult_test.s @@ -1,10 +1,34 @@ ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- ;;Calculates $11 * $0E = $EE .scope mult_test + A_temp = $4043 + B_temp = $4046 .include "arithmatic.inc" - LDA #$0F - STA VAL_A - LDA #$07 - STA VAL_B - JSR mult; A = $69 if it works as it should + .repeat $0F, i ;; $15 = floor(sqrt($255)) + ;; now i * j_max = $FF --> j_max = $FF/i + .repeat $0F, j + INC $400D ;; print number of iterations on screen. + LDX #i + STX VAL_A + STX A_temp + LDY #j + STY VAL_B + STY B_temp + JSR mult; A = VAL_A * VAL_B, clobers X. + + CMP #i*j + BEQ :+ + jmp error + : + .endrepeat + .endrepeat + jmp end +error: + ;; Error make screen read + ;; X * Y has the result in A that is wrong. + LDX #$02 + STX $D020 +end: + LDX A_temp + LDY B_temp .endscope