SteveOS for 16 bit processors (286)

string.asm 1.0KB

    bits 16 ;; Strings in cx and dx ;; Returns 1(true), 0(false) in cl strcmp: pusha strcmp_cont: mov bx, cx mov al, [bx] mov bx, dx mov ah, [bx] cmp ah, al jne strdif cmp ah, 0 ;Both strings have terminated je strsame add cx, 1 add dx, 1 jmp strcmp_cont strdif: ;strings are different popa mov cl, 0 ret strsame: popa mov cl, 1 ret ;; input(string pointer) in bx ;; input(delimeter) in al ;; input(points to array of pointers) in dx (output) strsplit: pusha ;; put start of string in dx array mov cx, bx mov bx, dx mov [bx], cx mov bx, cx add dx, 2 inc bx mov cx, bx ;points to beginning of next "section" strsplit_loop: cmp [bx], byte 0 je strsplit_done cmp [bx], al je strsplit_match add bx, 1 ;inc pointer jmp strsplit_loop strsplit_match: ;delimeter found mov [bx], byte 0 ;replaces delimeter w/ null char push bx mov cx, bx mov bx, dx inc cx mov [bx], cx pop bx inc bx add dx, 2 jmp strsplit_loop strsplit_done: popa ret