This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's z80 & ez80 Assembly subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Z80 & 68k Assembly => z80 & ez80 Assembly
Author Message
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 15 Jan 2009 10:35:07 am    Post subject:

A checksum is just any type of sum calculated from an arbitrarily long data file -- so that if a byte gets changed somehow, the checksum becomes different and you know that something got changed. Adding all the bytes together and ignoring overflow is one way.

Last edited by Guest on 15 Jan 2009 10:35:18 am; edited 1 time in total
Back to top
FloppusMaximus


Advanced Member


Joined: 22 Aug 2008
Posts: 472

Posted: 15 Jan 2009 06:08:54 pm    Post subject:

darkstone knight wrote:
isnt the checksum the amount of set bits in a number?

10010000 becomes 2..

What you're thinking of is known as population count or Hamming weight. Fastest way to compute it? LUT, of course.
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 29 Jan 2009 01:23:27 pm    Post subject:

FloppusMaximus wrote:
For a simple 8-bit checksum I don't see any way to improve on

Code:
   xor a
loop:
   add a,(hl)
   inc hl
   djnz loop

(unless of course you know that L + B < 257, in which case use "inc l" instead of "inc hl".)

Why not the sp trick?


Code:
   xor a
   di
   ld   (saveSP),sp
   ld   sp,Data
      ldb,number_of_bytes
loop2:
   pop hl
   add a,h
   add a,l
   djnz loop2
   ld sp,(saveSP)
   ei
   ret
saveSP:
   .dw 0


And if you unroll more like this:


Code:
   xor a
   di
   ld   (saveSP),sp
   ld   sp,Data
      ldb,number_of_bytes
loop2:
   pop hl
   pop de
   add a,h
   add a,l
   add a,d
   add a,e
   djnz loop2
   ld sp,(saveSP)
   ei
   ret
saveSP:
   .dw 0
Better.
Back to top
FloppusMaximus


Advanced Member


Joined: 22 Aug 2008
Posts: 472

Posted: 29 Jan 2009 11:47:06 pm    Post subject:

Good point. I don't tend to think of using the stack pointer in unusual ways, which is perhaps a flaw in my coding style. (Although, to be honest, the only time I would consider doing so is in extremely speed-optimized code, which I don't write very often.)

In any case, this thread is supposed to be about obfuscation! Let's see some more bizarre-looking code! Has anyone ever written a (real, useful) program that uses the CPD instruction? I don't think I have.
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 30 Jan 2009 07:43:37 am    Post subject:

FloppusMaximus wrote:
Good point. I don't tend to think of using the stack pointer in unusual ways, which is perhaps a flaw in my coding style. (Although, to be honest, the only time I would consider doing so is in extremely speed-optimized code, which I don't write very often.)

In any case, this thread is supposed to be about obfuscation! Let's see some more bizarre-looking code! Has anyone ever written a (real, useful) program that uses the CPD instruction? I don't think I have.
Stack and shadow registers combined use can be used to speed lightning code. While sp retrieves data from memory, shadow registers compensate the pushes and pops and/or you feel like having more registers to play with. The only down is you must have interrupts disabled, and so no gray...
And in most ASM tasks, you don't need desperate speed increase. It is better to optimise for size. It is a thing I appreciate very much in programs.

I will look to the CPD. Also, I have ideas for obfuscating code. Not forgotten...
Back to top
Display posts from previous:   
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
    » Goto page Previous  1, 2
» View previous topic :: View next topic  
Page 2 of 2 » All times are UTC - 5 Hours

 

Advertisement