Hey people,

I'm working on a test unit for KnightOS (test_sort) which tests the in-place sort function. The thing is, test units are ran from ROM, so I need to copy the string to sort in RAM before the actual sort. I'm pretty sure the problem isn't in any of the routines I call but in my own code.


Code:
; sort 000E
.macro assert(input, payloadSize, expected)
    in a, (6)
    push af
        xor a
        out (6), a
        ld bc, payloadSize
        call malloc
        push ix \ pop de \ push de
            ld hl, input
            ld bc, payloadSize
            ldir
            pop hl \ push hl
            ld de, payloadSize - 1
            add hl, de
            pop de \ push de
            ex de, hl
            call radixSort
            pop hl \ push hl
            ld de, expected
            call compareStrings
            jr z, $ + 6
            ld e, 1
            jr $ + 4
            ld e, 0
        pop ix
        call free
    pop af
    out (6), a
    xor a
    or e
    jr nz, .fail
.endmacro
test_sort:
    assert(.test1, 5, .expected1)
    assert(.test2, 8, .expected2)
    assert(.test3, 10, .expected3)
    assert(.test4, 2, .expected4)
    assert_pass()
.fail:
    assert_fail()
.undefine assert
.test1:
    .db 7, 4, 8, 6, 0
.expected1:
    .db 4, 5, 7, 8, 0
.test2:
    .db 7, 6, 5, 4, 3, 2, 1, 0
.expected2:
    .db 1, 2, 3, 4, 5, 6, 7, 0
.test3:
    .db 4, 5, 7, 10, 15, 17, 18, 22, 25, 0
.expected3:
    .db 4, 5, 7, 10, 15, 17, 18, 22, 25, 0
.test4:
    .db 7, 0
.expected4:
    .db 7, 0

Here's how I use each routine of this code :
  • malloc gets the number of bytes to allocate in BC and returns the allocated memory in IX.
  • radixSort gets the start of the data to sort in HL and its last element in DE. This is an in-place sort.
  • compareStrings gets two strings in HL and DE to compare. Z = strings equal.
  • assert_pass() and assert_fail() are macros, but they never execute from what I saw on the output.
  • free frees the memory whose first byte is pointed to by IX.


Any idea ?
Bump,
Actually I didn't need all the pages changes. Malloc does the work correctly.

New source code is here : http://pastebin.com/xbkzMGur

This time the test doesn't freeze anymore, but now it always return assert_pass(), even though I expressely put the wrong string in .expected1
Actually never mind, I solved it myself.
matrefeytontias wrote:
Actually never mind, I solved it myself.
Congrats! However, you should leave this topic here for the next time you run into a z80 ASM problem that we can help with. The only catch is I suspect most of your debugging requires a more intimate knowledge of KnightOS's routines than many of us have.
Well, I'll just use this topic for other related problems, and if people can't help me, I'll just search alone, it's not a big deal.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement