Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.0 kB
2
Indexable
Never
assume CS:code,DS:data

data segment
string db 255, 254 dup (0)
chr db 2, 3 dup (0)
result db "-1$"
data ends

code segment
strrchr proc
push bp
mov bp, sp

mov si, [bp + 6] ; указатель на строку
mov di, [bp + 4] ; указатель на символ
mov bl, [di + 2] ; символ
mov di, [bp + 8] ; указатель на результат

inc si
xor cx, cx
mov cl, [si]
add si, cx

find_loop:
mov al, [si]
cmp al, bl
je found
dec cl
dec si
test cl, cl
jz finish
jmp find_loop

found:
dec cl
xor ax, ax
mov al, cl
add di, 2
mov bl, 10

convert_loop:
dec di
div bl
add ah, '0'
mov [di], ah
xor ah, ah
test al, al
jnz convert_loop

finish:
mov ax, 0900h
mov dx, di
int 21h

mov ax, 4c00h
int 21h
strrchr endp


start:
mov AX, data
mov DS, AX

push offset result

mov ax, 0a00h
mov dx, offset string
int 21h
push offset string

mov ax, 0200h
mov dx, 10
int 21h

mov ax, 0a00h
mov dx, offset chr
int 21h
push offset chr

mov ax, 0200h
mov dx, 10
int 21h

call strrchr
code ends
end start
Leave a Comment