Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
48
Task/Tokenize-a-string/8080-Assembly/tokenize-a-string.8080
Normal file
48
Task/Tokenize-a-string/8080-Assembly/tokenize-a-string.8080
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
puts: equ 9
|
||||
org 100h
|
||||
jmp demo
|
||||
;;; Split the string at DE by the character in C.
|
||||
;;; Store pointers to the beginning of the elements starting at HL
|
||||
;;; The amount of elements is returned in B.
|
||||
split: mvi b,0 ; Amount of elements
|
||||
sloop: mov m,e ; Store pointer at [HL]
|
||||
inx h
|
||||
mov m,d
|
||||
inx h
|
||||
inr b ; Increment counter
|
||||
sscan: ldax d ; Get current character
|
||||
inx d
|
||||
cpi '$' ; Done?
|
||||
rz ; Then stop
|
||||
cmp c ; Place to split?
|
||||
jnz sscan ; If not, keep going
|
||||
dcx d
|
||||
mvi a,'$' ; End the string here
|
||||
stax d
|
||||
inx d
|
||||
jmp sloop ; Next part
|
||||
;;; Test on the string given in the task
|
||||
demo: lxi h,parts ; Parts array
|
||||
lxi d,hello ; String
|
||||
mvi c,','
|
||||
call split ; Split the string
|
||||
lxi h,parts ; Print each part
|
||||
loop: mov e,m ; Load pointer into DE
|
||||
inx h
|
||||
mov d,m
|
||||
inx h
|
||||
push h ; Keep the array pointer
|
||||
push b ; And the counter
|
||||
mvi c,puts ; Print the string
|
||||
call 5
|
||||
lxi d,period ; And a period
|
||||
mvi c,puts
|
||||
call 5
|
||||
pop b ; Restore the counter
|
||||
pop h ; Restore the array pointer
|
||||
dcr b ; One fewer string left
|
||||
jnz loop
|
||||
ret
|
||||
period: db '. $'
|
||||
hello: db 'Hello,How,Are,You,Today$'
|
||||
parts: equ $
|
||||
Loading…
Add table
Add a link
Reference in a new issue