Количество раз, когда определенный символ появляется в строке (сборка emu8086) - PullRequest
0 голосов
/ 08 июня 2018

У меня есть случайная строка, скажем «coccoo», и я хочу сохранить в регистре AX количество раз, когда появляется символ «c» (поэтому в этом случае я должен получить 3, но я получу только 2).Это мой код: `


 include 'emu8086.inc'
 org 100h
LEA SI,x ; SI points to 1st character in string
MOV CX,n ; size of string
MOV AX,0 ;the initial value stored in AX is 0  

check:
  CMP [SI],99     ;ASCII for 'c', compares the content of SI with c
  JNE next        ; If it's not c, then move to the next element in the string
  INC AX          ;If it's 'c', then increment the value in AX

next:
ADD SI,2       ;go to the next element in string

loop check     ;do it again for the next element(CX is decremented anyhow)
ret
x db 'coccoo' 
n dw  6                                                         
END
...