某个字符出现在字符串中的次数(程序集emu8086)

时间:2018-06-08 15:29:41

标签: assembly x86 emu8086

我有一个随机字符串,说' 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

0 个答案:

没有答案