Jump to content

Tokenize a string: Difference between revisions

Add 8086 Assembly
(Add 8080 assembly)
(Add 8086 Assembly)
Line 164:
{{out}}
<pre>Hello. How. Are. You. Today.</pre>
=={{header|8086 Assembly}}==
<lang asm> cpu 8086
org 100h
section .text
jmp demo
;;; Split the string at DS:SI on the character in DL.
;;; Store pointers to strings starting at ES:DI.
;;; The amount of strings is returned in CX.
split: xor cx,cx ; Zero out counter
.loop: mov ax,si ; Store pointer to current location
stosw
inc cx ; Increment counter
.scan: lodsb ; Get byte
cmp al,'$' ; End of string?
je .done
cmp al,dl ; Character to split on?
jne .scan
mov [si-1],byte '$' ; Terminate string
jmp .loop
.done: ret
;;; Test on the string given in the task
demo: mov si,hello ; String to split
mov di,parts ; Place to store pointers
mov dl,',' ; Character to split string on
call split
;;; Print the resulting strings, and periods
mov si,parts ; Array of string pointers
print: lodsw ; Load next pointer
mov dx,ax ; Print string using DOS
mov ah,9
int 21h
mov dx,period ; Then print a period
int 21h
loop print ; Loop while there are strings
ret
section .data
period: db '. $'
hello: db 'Hello,How,Are,You,Today$'
section .bss
parts: resw 10</lang>
{{out}}
<pre>Hello. How. Are. You. Today. </pre>
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
2,124

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.