J
So what exactly is it? The length of the line may be counted directly in a shydrated entry, but it begins in bx (I do not recall whether functions 2 and 8 of the register change, or not): mov bx,0 ;iнiцiалiзацiя iндексацiї введення
; я бы написал xor bx,bx
lea si, string
/users/10778/passer :
mov ah,08h ;Функцiя введення символу в AL без ехо
int 21h
cmp al,13 ;<Enter> ?
je @compare ;Так, на порiвняння
mov [si],al
mov ah,02
mov dl,'*' ;Запишемо на екран *
int 21h
inc si
inc bx ; увеличиваем счётчик длины
jmp /users/10778/passer
Or so: lea si, string
mov bx, si
/users/10778/passer :
mov ah,08h ;Функцiя введення символу в AL без ехо
int 21h
cmp al,13 ;<Enter> ?
je @compare ;Так, на порiвняння
mov [si],al
mov ah,02
mov dl,'*' ;Запишемо на екран *
int 21h
inc si
jmp /users/10778/passer
@compare:
; длина строки = si-bx
UPD It was tonight, there was nothing to do. ♪ ♪section .data
; ------------------------------------------
; internal data
; ------------------------------------------
ok db " - OK", 0Ah
ok_length equ $-ok
fail db " - FAIL", 0Ah
fail_length equ $-fail
http db "http://"
http_length equ $-http
; ------------------------------------------
; strings for test
; ------------------------------------------
http1 db "http://a" ; FAIL
h1_length equ $-http1
http2 db "http://.a" ; FAIL
h2_length equ $-http2
http3 db "http://a." ; FAIL
h3_length equ $-http3
http4 db "http://a.a" ; OK
h4_length equ $-http4
section .text
; ------------------------------------------
;
; $ nasm -f elf http.asm
; $ gcc http.o
; $ ./a.out
;
; http://a - FAIL
; http://.a - FAIL
; http://a . - FAIL
; http://a.a - OK
;
; ------------------------------------------
global main
main:
mov esi, http1
mov ebx, h1_length
call check_http
mov esi, http2
mov ebx, h2_length
call check_http
mov esi, http3
mov ebx, h3_length
call check_http
mov esi, http4
mov ebx, h4_length
call check_http
mov eax, 1
xor ebx, ebx
int 80h
; ------------------------------------------
; IN: esi = string, ebx = string length
; ------------------------------------------
check_http:
pushfd
push es
push edi
push esi
push ds
pop es
mov ecx, esi
mov edx, ebx
call print
mov ecx, http_length
sub ebx, ecx
jbe check_fail
mov edi, http
cld
rep cmpsb
jne check_fail
lodsb
cmp al, '.'
je check_fail
dec ebx
jz check_fail
xchg ecx, ebx
xchg esi, edi
mov al, '.'
repne scasb
jcxz check_fail
mov ecx, ok
mov edx, ok_length
jmp check_print
check_fail:
mov ecx, fail
mov edx, fail_length
check_print:
call print
pop esi
pop edi
pop es
popfd
ret
; ------------------------------------------
; IN: ecx = string, edx = string length
; ------------------------------------------
print:
push eax
push ebx
mov eax, 4
mov ebx, 1
int 80h
pop ebx
pop eax
ret