Page 1 of 2
Small assembler test programms...
Posted: Mon Jun 30, 2014 5:17 pm
by jedie
For the 6809 emulator in Python i need some small test programs... I hope that helps debugging
I have successfully adapt the crc16 assembler program with:
https://github.com/jedie/DragonPy/commi ... 42bee55f1b
It works and the crc16 was calculated successfully
Next i will try to adapt crc32:
https://github.com/jedie/sbc09/blob/mas ... /crc32.asm
I have take a look on the "6809 32/16 divison" program:
https://github.com/jedie/sbc09/blob/usl ... uslash.asm
But i need help here.
The current listing:
Code: Select all
0100 .ORG $100
0100 ; sample parameters on stack ...
0100 CC 00 00 LDD #$0000 ; dividend low word
0103 36 06 PSHU d
0105 CC 58 00 LDD #$5800 ; dividend high word
0108 36 06 PSHU d
010A CC 30 00 LDD #$3000 ; divisor
010D 36 06 PSHU d
010F EC 42 USLASH: LDD 2,u
0111 AE 44 LDX 4,u
0113 AF 42 STX 2,u
0115 ED 44 STD 4,u
0117 68 43 ASL 3,u ; initial shift of L word
0119 69 42 ROL 2,u
011B 8E 00 10 LDX #$10
011E 69 45 USL1: ROL 5,u ; shift H word
0120 69 44 ROL 4,u
0122 EC 44 LDD 4,u
0124 A3 C4 SUBD ,u ; does divisor fit?
0126 1C FE ANDCC #$FE ; clc - clear carry flag
0128 2B 04 BMI USL2
012A ED 44 STD 4,u ; fits -> quotient = 1
012C 1A 01 ORCC #$01 ; sec - Set Carry flag
012E 69 43 USL2: ROL 3,u ; L word/quotient
0130 69 42 ROL 2,u
0132 30 1F LEAX -1,x
0134 26 E8 BNE USL1
0136 33 42 LEAU 2,u
0138 AE C4 LDX ,u ; quotient
013A EC 42 LDD 2,u ; remainder
It looks like that the input is D via user stack. In this example code: 0x000058000 / 0x3000 isn't it?
But where is the result in the end?
Re: Small assembler test programms...
Posted: Mon Jun 30, 2014 7:13 pm
by JeeK
jedie wrote:For the 6809 emulator in Python i need some small test programs... I hope that helps debugging
[..]
I have take a look on the "6809 32/16 divison" program:
https://github.com/jedie/sbc09/blob/usl ... uslash.asm
But i need help here.
The current listing:
Code: Select all
0100 .ORG $100
0100 ; sample parameters on stack ...
0100 CC 00 00 LDD #$0000 ; dividend low word
0103 36 06 PSHU d
0105 CC 58 00 LDD #$5800 ; dividend high word
0108 36 06 PSHU d
010A CC 30 00 LDD #$3000 ; divisor
010D 36 06 PSHU d
[..]
0136 33 42 LEAU 2,u
0138 AE C4 LDX ,u ; quotient
013A EC 42 LDD 2,u ; remainder
It looks like that the input is D via user stack. In this example code: 0x000058000 / 0x3000 isn't it?
But where is the result in the end?
No, 0x580000000 / 0x3000. I used these values to provoke an overflow situation.
On entry D is just used to push arguments on the forth parameter stack to keep the basic routine unchanged as it will be used in Talbot System Forth.
At 0136 one from the three word on the parameter stack is thrown away, only one word (16 bit) for the quotient and (16 bit for the remainder) will kept. The result in Forth context is left on the parameter stack. I finally loaded values into the registers just to see it better in the trace output ...
This implementation does not care about overflows. With the values above you just get garbage.
It was just for analyzing purposes to compare and improve the USLASH in ef09.asm, which is faster and handles overflow too. (note: parameter stack is register S)
Re: Small assembler test programms...
Posted: Mon Jun 30, 2014 7:24 pm
by JeeK
jedie wrote:For the 6809 emulator in Python i need some small test programs... I hope that helps debugging
[..]
It looks like that the input is D via user stack. In this example code: 0x000058000 / 0x3000 isn't it?
But where is the result in the end?
Swap lines at 100 and 105 and the division is as you suggested above. Then, X should 1 (quotient) and D 2800 (the remainder).
Re: Small assembler test programms...
Posted: Mon Jun 30, 2014 8:22 pm
by jedie
Thx, for the info... I will try to use it...
Re: Small assembler test programms...
Posted: Mon Jun 30, 2014 10:06 pm
by jedie
OK, division test code runs. See commit:
https://github.com/jedie/DragonPy/commi ... 2f9972d62f
But some tests failed:
These all are ok:
Code: Select all
test(10, 5) # is: 10/5
test(10, 3)
test(1000, 2000)
test(0xffff, 0x80)
test(0xfffff, 0x800)
test(0xffffff, 0x8000)
test(0xfffffff, 0x8000)
test(1, 0x8000)
These failed:
Code: Select all
test(1, 0x8001) # Error: '1/32769=65534 remainder: 3' != '1/32769=0 remainder: 1'
test(1, 0x9000) # Error: '10/65535=65533 remainder: 7' != '10/65535=0 remainder: 10'
test(10, 0xffff) # Error: '10/65535=65533 remainder: 7' != '10/65535=0 remainder: 10'
test(0xfffffff, 0xffff) # Error: '268435455/65535=57342 remainder: 57341' != '268435455/65535=4096 remainder: 4095'
Don't know if it simply out of range from the division code... Or a problem in my 6809 implementation?!?
Re: Small assembler test programms...
Posted: Tue Jul 01, 2014 7:49 am
by JeeK
jedie wrote:OK, division test code runs. See commit:
https://github.com/jedie/DragonPy/commi ... 2f9972d62f
But some tests failed:
These all are ok:
Code: Select all
test(10, 5) # is: 10/5
test(10, 3)
test(1000, 2000)
test(0xffff, 0x80)
test(0xfffff, 0x800)
test(0xffffff, 0x8000)
test(0xfffffff, 0x8000)
test(1, 0x8000)
These failed:
Code: Select all
test(1, 0x8001) # Error: '1/32769=65534 remainder: 3' != '1/32769=0 remainder: 1'
test(1, 0x9000) # Error: '10/65535=65533 remainder: 7' != '10/65535=0 remainder: 10'
test(10, 0xffff) # Error: '10/65535=65533 remainder: 7' != '10/65535=0 remainder: 10'
test(0xfffffff, 0xffff) # Error: '268435455/65535=57342 remainder: 57341' != '268435455/65535=4096 remainder: 4095'
Don't know if it simply out of range from the division code... Or a problem in my 6809 implementation?!?
These are all underflows which are not correct handled by UMMOD, especially in the Talbot System variant.
Even my implementation in ef09 does not handle this cases correctly.
Please be patient, I will push a new version of uslash.asm soon, which will contain both variants and
with my variant handling above underflows correctly (hopefully).
JeeK
Re: Small assembler test programms...
Posted: Tue Jul 01, 2014 8:49 am
by jedie
JeeK wrote:Please be patient, I will push a new version of uslash.asm soon, which will contain both variants and
with my variant handling above underflows correctly (hopefully).
I'm curious
One question to crc32:
The current implementation:
Code: Select all
...
; ZIP polynomic, reflected (bit reversed) from $04C11DB7
CRCHH EQU $ED
CRCHL EQU $B8
CRCLH EQU $83
CRCLL EQU $20
...
eora #CRCLH ; apply CRC polynomic low word
eorb #CRCLL
exg d,x
eora #CRCHH ; apply CRC polynomic high word
eorb #CRCHL
So is doesn't use the "normal" polynomic $04C11DB7
How must this code looks like, if $04C11DB7 is used?
Code: Select all
...
; ZIP polynomic, reflected (bit reversed) from $04C11DB7
CRCHH EQU $04
CRCHL EQU $c1
CRCLH EQU $1d
CRCLL EQU $b7
...
eora #CRCLH ; apply CRC polynomic low word
eorb #CRCLL
exg d,x
eora #CRCHH ; apply CRC polynomic high word
eorb #CRCHL
is this right?
EDIT: This question is no longer important!
Re: Small assembler test programms...
Posted: Tue Jul 01, 2014 10:56 am
by jedie
OK, the crc32 test works now with commit
https://github.com/jedie/DragonPy/commi ... d2ded38abf
These Tests run fine:
Code: Select all
Test String: 'F'
python..: $4dbd0b28
crc32...: $4dbd0b28
Test String: 'DragonPy test!'
python..: $570e3666
crc32...: $570e3666
Test String: 'DragonPy Integration testing...'
python..: $728b1186
crc32...: $728b1186
Test String: 'An Arbitrary String'
python..: $6fbeaae7
crc32...: $6fbeaae7
Test String: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789'
python..: $749f0b1a
crc32...: $749f0b1a
But this failed:
Code: Select all
Test String: 'ZYXWVUTSRQPONMLKJIHGFEDBCA'
python..: $99cdfdb2
crc32...: $-6632024e
Any idea why?
EDIT: failed test is fixed: I have to used
binascii.crc32(txt) & 0xffffffff (add & 0xffffffff) ->
https://github.com/jedie/DragonPy/commi ... db27776a2a
Re: Small assembler test programms...
Posted: Wed Jul 02, 2014 10:36 am
by jedie
I have include the new division assembler code from
https://github.com/6809/sbc09/pull/2 info DragonPy with commit:
https://github.com/jedie/DragonPy/commi ... 16e6d19d7a
Also some tests are ok and some fails:
These are fine:
Code: Select all
test(10, 10) # OK: 10/10=1 remainder: 0
test(10, 5) # OK: 10/5=2 remainder: 0
test(10, 3) # OK: 10/3=3 remainder: 1
test(0xffff, 0x80) # OK: 65535/128=511 remainder: 127
test(0xffff, 0xff) # OK: 65535/255=257 remainder: 0
test(0xfffff, 0x800) # OK: 1048575/2048=511 remainder: 2047
test(0xffffff, 0x8000) # OK: 16777215/32768=511 remainder: 32767
test(0xfffffff, 0x8000) # OK: 268435455/32768=8191 remainder: 32767
test(0xfffffff, 0xffff) # OK: 268435455/65535=4096 remainder: 4095
But this fails:
Code: Select all
test(1, 0x8000) # ERROR: '1/32768=0 remainder: 0' should be: '1/32768=0 remainder: 1'
test(1, 0x8001) # ERROR: '1/32769=0 remainder: 0' should be: '1/32769=0 remainder: 1'
test(1, 0x9000) # ERROR: '1/36864=0 remainder: 0' should be: '1/36864=0 remainder: 1'
test(10, 0xffff) # ERROR: '10/65535=0 remainder: 0' should be: '10/65535=0 remainder: 10'
test(0x10000000, 0x10000) # ERROR: '268435456/65536=16 remainder: 65535' should be: '268435456/65536=4096 remainder: 0'
Re: Small assembler test programms...
Posted: Wed Jul 02, 2014 12:49 pm
by JeeK
jedie wrote:I have include the new division assembler code from
https://github.com/6809/sbc09/pull/2 info DragonPy with commit:
https://github.com/jedie/DragonPy/commi ... 16e6d19d7a
[..]
But this fails:
Code: Select all
test(1, 0x8000) # ERROR: '1/32768=0 remainder: 0' should be: '1/32768=0 remainder: 1'
test(1, 0x8001) # ERROR: '1/32769=0 remainder: 0' should be: '1/32769=0 remainder: 1'
test(1, 0x9000) # ERROR: '1/36864=0 remainder: 0' should be: '1/36864=0 remainder: 1'
test(10, 0xffff) # ERROR: '10/65535=0 remainder: 0' should be: '10/65535=0 remainder: 10'
test(0x10000000, 0x10000) # ERROR: '268435456/65536=16 remainder: 65535' should be: '268435456/65536=4096 remainder: 0'
Last line: divisor is only 16 bit, 0x10000 is out of range (0x10000 = 0x0000). This test makes no sense.
The other ones: You are right, there is bug - my "underflow" handling is wrong - there no special handling necessary. Register D contains already the correct value.