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