Re: 8051 Speed Optimization
- From: Tilmann Reh <tilmannreh@xxxxxxxxxxxxx>
- Date: Thu, 29 Sep 2005 08:12:02 +0200
alexmchale@xxxxxxxxx schrieb:
> I'm working on optimizing code for a C8051F120 that needs to run at an
> extremely fast clip. The following few lines are repeated over, as
> fast as possible. The looping is a straightforward djnz. The bulk of
> the cpu time is spent on the following lines. This is repeated (cut
> and paste, but with the binary value changed) 8 times per loop.
>
> ; for reference
> rLEVEL equ R0
> mDATAOUT DATA 64
>
> ; the code
> row0:
> movx A, @DPTR
> inc DPTR
> subb A, rLEVEL
> jc row1
> orl mDATAOUT, #00000001b
> row1:
You could also use CJNE for the comparison - it also sets carry, but is
non-destructive, so you don't need to reload A from XRAM for each test:
movx a,@dptr
cjne a,ar0,$+3
mov mDataOut.0,c
cjne a,...
mov ...,c
As like Frieder's approach, this one also resets the output bit in case
the data value is lower than the treshold. If you want latching
operation, you need to use conditional jumps again or consider the
previous state:
movx a,@dptr
cjne a,ar0,$+3
orl c,mDataOut.0
mov mDataOut.0,c
cjne a,...
orl c,...
mov ...,c
Then it's only slightly faster than your original code, however the time
is fixed (independent of the data), which might also be an advantage.
--
Dipl.-Ing. Tilmann Reh
http://www.autometer.de - Elektronik nach Maß.
.
- Follow-Ups:
- Re: 8051 Speed Optimization
- From: Tilmann Reh
- Re: 8051 Speed Optimization
- References:
- 8051 Speed Optimization
- From: alexmchale@xxxxxxxxx
- 8051 Speed Optimization
- Prev by Date: Re: Bit manipulation
- Next by Date: Re: 8051 Speed Optimization
- Previous by thread: Re: 8051 Speed Optimization
- Next by thread: Re: 8051 Speed Optimization
- Index(es):