Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,116 @@
puts: equ 9
org 100h
jmp demo
;;; Squeeze the string at DE on the character in C.
;;; The result is written starting at HL.
squeez: mvi b,'$' ; Last character seen
dcx d ; Move pointer back one item
sqzlp: mvi m,'$' ; Stop on end of string
inx d ; Increment input pointer
ldax d ; Grab character from input string
cmp m ; End reached?
rz ; Then stop
cmp c ; Was it equal to the character to squeeze?
jnz sqzwr ; If not, then write it to the output
mov a,b ; If so, is the previous character?
cmp c
jz sqzlp ; If so, ignore this one
sqzwr: ldax d ; Retrieve the character again
mov m,a ; It goes in the output
mov b,a ; And it is the last character seen
inx h ; Increment output pointer
jmp sqzlp
;;; Print the string in DE and character in C as specified,
;;; squeeze the string and print the output.
prsqz: push b ; Save input parameters
push d
mov a,c ; Store character
sta chval
lxi d,chstr ; Print character
mvi c,puts
call 5
pop h ; Retrieve input string pointer
push h
call prbrkt ; Print the string in brackets
pop d ; Retrieve both input parameters
pop b
lxi h,buffer
call squeez ; Squeeze the input string
lxi h,buffer ; ... fall through to print the result
;;; Write the string at HL and its length in brackets
prbrkt: push h ; Keep the pointer
mvi b,0FFh ; Find the length
mvi a,'$' ; End marker
dcx h
lscan: inr b ; Scan through the string incrementing B
inx h ; and HL until the end is found
cmp m
jnz lscan
mov a,b ; Find high and low digit (assuming < 100)
mvi b,'0'-1
pdigit: inr b ; B = high digit
sui 10
jnc pdigit
lxi h,bstart+1
adi '0'+10
mov m,a ; Write low digit
dcx h
mov m,b ; Write high digit
xchg
mvi c,puts ; Print length and brackets
call 5
pop d ; Retrieve the string pointer
mvi c,puts ; Print the string
call 5
lxi d,bend ; Print the ending brackets
mvi c,puts
jmp 5
;;; Squeeze each string by the given character
demo: lxi h,list ; Pointer to start of list
loop: mov e,m ; Load pointer and character
inx h
mov d,m
inx h
mov c,m
inx h
xra a ; Stop when zero reached
ora c
rz
push h ; Keep list pointer
call prsqz ; Squeeze and print
pop h ; Restore list pointer
jmp loop
;;; Formatting strings
chstr: db 'Character: "'
chval: db '*"',13,10,'$'
bstart: db '##<<<$'
bend: db '>>>'
nl: db 13,10,'$'
;;; Input strings
str1: db '$'
str2: db '"If I were two-faced, would I be wearing'
db ' this one?" --- Abraham Lincoln $'
str3: db '..11111111111111111111111111111111111111'
db '11111111111111111111111117777888$'
str4: db 'I never give ',39,'em hell, I just tell the t'
db 'ruth, and they think it',39,'s hell. $'
str5: db ' '
db ' --- Harry S Truman $'
;;; Pairs of string pointers and characters to squeeze
list: dw str1
db ' '
dw str2
db '-'
dw str3
db '7'
dw str4
db '.'
dw str5
db ' '
dw str5
db '-'
dw str5
db 'r'
dw 0
db 0
buffer: equ $