Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
39
Task/Tokenize-a-string/8086-Assembly/tokenize-a-string.8086
Normal file
39
Task/Tokenize-a-string/8086-Assembly/tokenize-a-string.8086
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue