;written by Russell Nelson, improved by Jan Engvald to drain capacitive mem.
;enter with ax = segment of memory to test, cx = number of bytes to test.
;exit with ne, bx->failing byte if the memory test failed.
mov al,ds:[bx] ;get a copy of the location.
mov ah,ds:[bx+2] ;get a copy of the location.
mov ds:[bx],al ;try to store the complement.
mov ds:[bx+2],ah ;drain any capacitive memory
cmp ds:[bx],al ;did the store work?
mov ds:[bx],ah ;(in any case, restore the original)
loope memory_test_1 ;keep going if the store worked.