Skip to content

Instantly share code, notes, and snippets.

@WideWord
Created April 2, 2015 20:22
Show Gist options
  • Select an option

  • Save WideWord/62bd8f0de49769607bf1 to your computer and use it in GitHub Desktop.

Select an option

Save WideWord/62bd8f0de49769607bf1 to your computer and use it in GitHub Desktop.
org 100h
jmp main
include 'proc16.inc'
main:
stdcall get_arg, .buffer, 64
cmp byte [.buffer], 0
jne .buffer_not_empty
stdcall read_line, .buffer, 64
.buffer_not_empty:
stdcall split_str, .buffer, 0, .filename, 32
stdcall split_str, .buffer, 1, .symbol, 1
mov ah, 3Dh
mov al, 0
mov dx, .filename
int 21h
mov word [.descriptor], ax
.eloop:
mov bx, word [.descriptor]
mov ah, 3Fh
mov cx, 512
mov dx, .data_buffer
int 21h
cmp ax, 0
je .exit
mov cx, ax
mov si, .data_buffer
.loop_start:
cmp byte [si], '_'
je .replace
cmp byte [si], '.'
je .replace
cmp byte [si], ','
je .replace
cmp byte [si], ':'
je .replace
cmp byte [si], ';'
je .replace
cmp byte [si], '!'
je .replace
cmp byte [si], '?'
je .replace
cmp byte [si], 12
je .replace
cmp byte [si], '('
je .replace
cmp byte [si], ')'
je .replace
cmp byte [si], '?'
je .replace
cmp byte [si], '#'
je .replace
cmp byte [si], '%'
je .replace
cmp byte [si], '*'
je .replace
cmp byte [si], '\'
je .replace
cmp byte [si], '/'
je .replace
inc si
dec cx
cmp cx, 0
jne .loop_start
jmp .loop_end
.replace:
mov dl, [.symbol]
mov [si], dl
inc si
dec cx
cmp cx, 0
jne .loop_start
.loop_end:
mov ah, 40h
mov bx, 1
mov cx, si
sub cx, .data_buffer
mov dx, .data_buffer
int 21h
jmp .eloop
.exit:
ret
.buffer rb 64
.filename rb 32
.symbol db 0
.data_buffer rb 512
.descriptor dw 0
proc get_arg uses cx si di, buffer, limit
sub word [limit], 1
mov cl, [80h]
mov ch, 0
cmp cx, 0
je .proc_exit
sub cx, 1
mov si, 82h
mov di, [buffer]
.copy_loop:
movsb
sub word [limit], 1
cmp word [limit], 0
je .copy_loop_exit
loop .copy_loop
.copy_loop_exit:
mov byte [di], 0
.proc_exit:
ret
endp
proc split_str uses si di cx, string, substr_num, buffer, limit
mov si, [string]
.skip_spaces:
cmp byte [si], ' '
jne .skip_spaces_end
inc si
jmp .skip_spaces
.skip_spaces_end:
.skip_chars:
cmp [substr_num], 0
je .skip_chars_end
cmp byte [si], ' '
je .space_found
cmp byte [si], 0
je .skip_chars_end
inc si
jmp .skip_chars
.space_found:
sub [substr_num], 1
jmp .skip_spaces
.skip_chars_end:
mov cx, [limit]
cmp cx, 0
je .proc_exit
sub cx, 1
mov di, [buffer]
.copy_loop:
cmp byte [si], ' '
je .copy_loop_exit
cmp byte [si], 0
je .copy_loop_exit
movsb
loop .copy_loop
.copy_loop_exit:
mov byte [di], 0
.proc_exit:
ret
endp
proc read_line uses cx di ax, buffer, limit
mov di, [buffer]
mov cx, [limit]
sub cx, 1
.read_loop:
cmp cx, 0
je .read_loop_exit
mov ah, 01h
int 21h
cmp al, 13
je .read_loop_exit
mov [di], al
inc di
dec cx
jmp .read_loop
.read_loop_exit:
mov byte [di], 0
ret
endp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment