Bitwise IO: Difference between revisions

m
→‎{{header|Z80 Assembly}}: simplified label names
m (→‎{{header|Z80 Assembly}}: simplified label names)
Line 3,433:
; are as far left as possible.
 
outerloop:
loop_compressBinaryStrings_7bit:
inc de ;skip bit 7
ld b,7 ;loop counter
innerloop:
innerloop_compressBinaryStrings_7bit:
ld a,(de)
or a ;compares accumulator to zero. Assumes a null-terminated string.
; Otherwise compare A to your terminator of choice.
 
jr z,HandleEarlyExit
jr z,HandleEarlyExit_compressBinaryStrings_7bit
 
sub &30 ;we're left with 0 if the ascii was "0" and 1 if the ascii was "1"
Line 3,447:
rl (hl) ;rotate it out of the carry into (HL)
inc de
z_djnz innerloop
z_djnz innerloop_compressBinaryStrings_7bit
;a macro that becomes DJNZ <label> on Zilog Z80 and DEC B JR NZ,<label> on Sharp LR35902
 
inc hl ;next output byte
jp outerloop
jp loop_compressBinaryStrings_7bit
HandleEarlyExit:
HandleEarlyExit_compressBinaryStrings_7bit:
xor a ;LD A,0
cp b ;compare B to zero
ret z ;if B=0, we're done. No need to adjust the last byte
loop_earlyExit
loop_earlyExit_compressBinaryStrings_7bit:
rlc (hl)
z_djnz loop_earlyExit
z_djnz loop_earlyExit_compressBinaryStrings_7bit
ret</lang>
 
1,489

edits