Skip to content

Instantly share code, notes, and snippets.

@whitequark
Last active May 20, 2019 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whitequark/173aa5403819331be660edcd3f255d69 to your computer and use it in GitHub Desktop.
Save whitequark/173aa5403819331be660edcd3f255d69 to your computer and use it in GitHub Desktop.
lcall _delay_4c
sjmp .
_delay_4c::
; (ljmp delay_4c) ; 0c > 4c
mov acc, dph ; 3c
cjne a, #0, 00000$ ; 4c > 11c [A]
mov acc, dpl ; 3c
subb a, #(24/4+1) ; 2c
inc a ; 1c
jnc 00003$ ; 3c > 20c [B]
ret ; 4c > 24c
00000$:
mov a, dpl ; [A] > 2c
jz 00002$ ; 3c > 16c [C]
00001$:
djnz acc, 00001$ ; [C] > 4Lc > (16+4L)c [D]
; [E] > 1016c > (16+1024H+4L)c [G]
00002$:
nop ; [D] > 1c
mov acc, #-2 ; 3c
djnz dph, 00001$ ; 4c > (16+8+4L) [E]
nop ; 1c
mov acc, #-((28+4)/4) ; 3c > (28+4L) [F]
; [G] > 1c
; 3c
; 4c > (16+8+1024H+4L)c [E]
; 1c
; 3c > (28+1024H+4L)c [F]
00003$:
djnz acc, 00003$ ; [B] > 4Lc
ret ; 4c > (24+4L)c
; [F] > 992c
; 4c > (1024H+4L)c
#!/bin/sh -ex
sdas8051 -o -l _delay_4c.asm
sdld -i _delay_4c.rel
#!/bin/sh -e
dpl=${1-0}
dph=${2-0}
lowbound=6
if [ ${dph} -ge 1 -o ${dpl} -ge ${lowbound} ]; then
expect=$(( (${dpl}+(${dph}<<8))<<2 ))
else
expect=$(( ${lowbound}<<2 ))
fi
actual=$(s51 -t DS320 _delay_4c.ihx -c - <<END | grep Simulated | awk '{print $2/4-3}')
break 0x3
SP=0x80
dpl=${dpl}
dph=${dph}
cont
quit
END
[ ${expect} -eq ${actual} ] || (echo "failed: actual ${actual}, expect ${expect}"; exit 1)
#!/bin/sh -ex
./build.sh
for dph in `seq 0 255`; do
for dpl in `seq 0 255`; do
./run.sh ${dpl} ${dph}
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment