Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,4 @@ test "smult12" 0xa00
#test "omult29" 0x200
#test "omult30" 0x200
#test "omult31" 0xa00
#test "omult32" 0x200
72 changes: 72 additions & 0 deletions tests/omult32.a
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
;-------------------------------------------------------------------------
; _mulint.s - routine for 16x16 -> 16 multiplication (low bytes only)
;
; Copyright (C) 2025, Gabriele Gorla
;
; This library is free software; you can redistribute it and/or modify it
; under the terms of the GNU General Public License as published by the
; Free Software Foundation; either version 2, or (at your option) any
; later version.
;
; This library is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this library; see the file COPYING. If not, write to the
; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
; MA 02110-1301, USA.
;
; As a special exception, if you link this library with other files,
; some of which are compiled with SDCC, to produce an executable,
; this library does not by itself cause the resulting executable to
; be covered by the GNU General Public License. This exception does
; not however invalidate any other reasons why the executable file
; might be covered by the GNU General Public License.
;-------------------------------------------------------------------------

* = $0200

F1 = $02 ; 2 bytes
F2 = $04 ; 2 bytes
res = $06 ; 2 bytes


; On Entry:
; (F1, F1+1): multiplier 2 bytes
; (F2, F2+1): multiplicand 2 bytes
; On Exit:
; (res, res+1): 16 bit product

mult
lda #0
sta res+0
ldy #8
loop1
lsr F2+0
bcc skip1
clc
tax
lda res+0
adc F1+0
sta res+0
txa
adc F1+1
skip1
asl F1+0
rol F1+1
dey
bne loop1

loop2
lsr F2+1
bcc skip2
clc
adc F1+1
skip2
asl F1+1
bne loop2

sta res+1
rts
41 changes: 41 additions & 0 deletions tests/omult32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// omult32.c

// specify range of input values
static const uint64_t INPUT_START = 0UL;
static const uint64_t INPUT_END = 65536UL * 65536UL;

// **************************************************************************************
void test_pre(thread_context_t* threadContext, uint64_t input) {
zuint8* memory = threadContext->machine.context;

memory[2] = input & 255UL;
memory[3] = (input / 256UL) & 255UL;
memory[4] = (input/65536UL) & 255UL;
memory[5] = (input/65536UL) / 256UL;
}

// **************************************************************************************
uint64_t test_post(thread_context_t* threadContext) {
zuint8* memory = threadContext->machine.context;

uint64_t a = memory[6];
uint64_t b = memory[7];

return a + 256UL*b;
}

// **************************************************************************************
int is_correct(thread_context_t* threadContext, uint64_t input, uint64_t actual_result, uint64_t* expected) {
uint64_t x = input & 65535UL;
uint64_t y = input / 65536UL;
uint64_t e = x * y & 65535;
*expected = e;

return actual_result == e;
}


// **************************************************************************************
void test_cleanup()
{
}