Search code examples
assembly68000easy68k

assembly 68k - clear starting from address efficently


This is my snippet to clear data from SCREEN address to 600 bytes.

    lea SCREEN,a3
    move.w  #(600/4)-1,d0   ; bytes / 4 bytes (long)
clear_data:
   clr.l    (a3)+
   dbra d0,clear_data

This works, however I wonder how to achieve the same result without cycling by 600/4 times. Basically I guess to point directly to SCREEN and doing something like

; point PC to SCREEN ?
dcb.b 600,0

Is is possible ?

EDIT POST ANSWER

Still using software code, this cycle is about 2 times faster (Stolen from RamJam course):

    lea SCREEN,a3
    move.w  #(600/32)-1,d0   ; bytes / 32 bytes (long*8)
clear_data:
    clr.l    (a3)+
    clr.l    (a3)+
    clr.l    (a3)+
    clr.l    (a3)+
    clr.l    (a3)+
    clr.l    (a3)+
    clr.l    (a3)+
    clr.l    (a3)+
    dbra d0,clear_data

However, as Peter mentioend on the answer, using a blitter (if provided by the hardware) can drastically optimize the performance.


Solution

  • No, storing 4 bytes at a time in a loop is probably about as good as you can get. Maybe unrolling a bit to reduce loop overhead, if that tight loop doesn't max out memory bandwidth on whatever m68k hardware you care about. Or maybe not: @jasonharper comments that later m68k chips have special support for 2-instruction loops.


    dcb.b 600,0 is an assemble-time thing which assembles bytes into your output file.

    You can't "run" it at runtime. Remember that asm source doesn't run directly; it's a way to create binary files containing m68k machine code and/or data.

    You can use data directives mixed with instructions to "manually" encode instructions by specifying the machine-code bytes you want, but 600 bytes of zeros will just decode as some m68k instructions. (I didn't check how 00 00 decodes on m68k.)


    Some computers based on m68k had hardware chips for doing stuff to big blocks of memory. This was typically called a blitter chip (Wikipedia). e.g. some Atari m68k desktops, like the Mega STe, had a BLiTTER chip.

    You could run a few instructions on the CPU to program the blitter to clear or copy a big block of memory while the CPU went on to run other instructions. This is basically a DMA copy engine.