HerobrinesArmy / DevCPU

Integrated DCPU-16 development and emulation environment
16 stars 2 forks source link

Add compressed string directive #44

Open s-ol opened 11 years ago

s-ol commented 11 years ago

Add a .asciz directive storing a string in "compressed" form (2 characters / word):

.asciz "ABC" => dat 0x4142, 0x4300

L3nn0x commented 11 years ago

But you can't decompress it without a lot of computation, so it's not really useful.

s-ol commented 11 years ago

@FaerieFrOSt you should unroll your loops anyway, and its not that much

s-ol commented 11 years ago
:_scr_packed_string
    SET PUSH, Y
:_scr_packed_string_loop

    SET Y, [J]  ; high byte
    SHR Y, 8    ; shift high byte to low one
    AND Y, 0x7f ; clear high

    IFE Y, 0
        SET PC, _scr_packed_string_done

    BOR Y, B    ; apply format
    SET [I], Y
    ADD I, 1

    SET Y, [J]  ; low byte
    AND Y, 0x7f ; clear our high byte

    IFE Y, 0
        SET PC, _scr_packed_string_done

    BOR Y, B    ; apply format
    STI [I], Y  ; increment I and J

    SET PC, _scr_packed_string_loop
:_scr_packed_string_done
    SET Y, POP
    SET PC, POP
L3nn0x commented 11 years ago

Well okay. That's feasible. But again it's speed against size. ;)

s-ol commented 11 years ago

And if you would unroll that loop, it would be much faster than a not-unrolled uncompressed loop.

Also you half the memory size of each string, so you the extra-size of the routine is easily compensated

L3nn0x commented 11 years ago

True enough. :)

HerobrinesArmy commented 10 years ago

I'll look into adding this. When I do, I'll make it work like Organic says it does, with .asciiz or.asciic for c-style, .asciip for pascal, and .ascii for a raw string