Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help needed. String comparing. Index find.

.model small
.Stack 100h
.Data

str1 db 'abcd ef$'
str2 db 'ef$'
message db 6 dup (0)
n dw ?

.code
mov ax,@data ;
mov ds,ax ; i DS perkelia duomenu segmento
mov es, ax ; ;ir ES pradzios paragrafu numerius
xor cx,cx ;
lea si,str1 ; irasomas eilutes vykdomasis adresas i SI
lea di, str2 ;
call index
jmp print_numb


INDEX PROC near
PUSH SI
PUSH DI
PUSH BX
PUSH CX
PUSHF;
CLD

MOV AL, ES:[DI]; get the length of the test string
CMP AL,[SI]; see if it is longer than
JA NotThere; the length of the source string [there are mistakes because the str2 is shorter than str1, but it jumps to NoThere and always prints 0]

MOV AL,ES:[DI]; length of the test string
MOV CL,AL; save it for later
MOV CH,0
MOV AL,[SI]; length of source string
SUB BL,AL; times to repeat loop
INC DI; skip over length byte
XOR AX,AX; init index to zero
CmpLoop:INC AX; bump index by one
INC SI; move onto the next char in source
PUSH SI; save string pointers and
PUSH DI; the length of the test string
PUSH CX
REPE CMPSB; compare strings
POP CX; restore string pointers
POP DI; and the length
POP SI
JE FoundIndex; if we found the substring
DEC BL
JNZ CmpLoop; try next entry in source string

NotThere:XOR AX,AX; return index=0

FoundIndex:
POPF
POP CX
POP BX
POP DI
POP SI
RET
INDEX ENDP

print_numb: [I need to print out the contens of AX, I don't know if the code below do this]
mov bx, offset message

mov ax, [n]
sub dx, dx ; DX:AX = n
mov cx, 10000 ; Divide it by 10000
div cx ; result in AX, remainder in DX

add al, 30h
mov [bx], al
inc bx
mov ax, dx
sub dx, dx
mov cx, 1000 ; Divide it by 1000
div cx

add al, 30h
mov [bx], al
inc bx
mov ax, dx
sub dx, dx
mov cx, 100 ; Divide it by 100
div cx

add al, 30h
mov [bx], al
inc bx
mov ax, dx
sub dx, dx
mov cx, 10 ; Divide it by 10
div cx

add dl, 30h
mov [bx], dl
jmp myloop


myloop:
mov dl, [bx] ; --> means fetch a character pointed by BX to DL.
inc bx ; --> BX = BX + 1
cmp dl, 0 ; --> Is DL zero?
je quit ; --> If yes, then quit
cmp al, 0
ja print
jb myloop
print:
mov ah, 09 ; --> Otherwise, do the print service and repeat
int 21h
jmp myloop

quit:

mov ax, 4c00h
int 21h


END

It would be of a great help if someone could help me and make this code work :)
Sign In or Register to comment.