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