optimizing memory reads
I've written a routine to copy a byte of data from a serial memory chip (Ramtron FM25256) to a variable.
SCK = serial memory clock pin
SO = serial output pin from memory to SX
Note that the memory is already primed and already has the first bit of the byte on the SO pin prior to entering this routine.
My serial memory can run pretty fast, up to 15mhz clock. MOVB is a multi-word 4-cycle instruction. As a result, it's expensive.
The code works fine, but is there a way to optimize it?
Thanks
Keith
SCK = serial memory clock pin
SO = serial output pin from memory to SX
Note that the memory is already primed and already has the first bit of the byte on the SO pin prior to entering this routine.
MOV nsb, #8 CLR gotdata 'this is unnecessary loopzz: SETB SCK ‘outputs are latched on falling edge, this just raises the clock ‘note that the other instructions that follow serve to allow ‘at least 28ns for a minimum clock high time. MOVB C, SO ‘read the bit into carry RL gotdata ‘bring the bit via carry into gotdata, leftshifting for MSB DEC nsb ‘decrement bit counter CLRB SCK ‘drop clock (clock low min is 28ns, data not valid until Todv, or 24ns) ‘data comes valid 24ns after this clock drop. JNZ loopzz ‘delay here is long enough for Todv and Tcl(clock low time)
My serial memory can run pretty fast, up to 15mhz clock. MOVB is a multi-word 4-cycle instruction. As a result, it's expensive.
The code works fine, but is there a way to optimize it?
Thanks
Keith
Comments
Also, you could unroll the loop. Just repeat the instruction 8 times instead of doing "DEC nsb" and "JNZ loopzz".
Bean.
Post Edited By Moderator (Chris Savage (Parallax)) : 11/2/2007 3:54:59 PM GMT
Because a lot of my operations are bit-based routines, and I'm processing literally millions of bits, every little bit helps.
Thank you.
Keith