我修正了错误,但是现在可以有人建议让CountNearMatches
计算两个数组中有多少匹配匹配的方法。我使用diff变量作为最大允许差异。
这是我到目前为止所做的:
INCLUDE Irvine32.inc
CountNearMatches PROTO, ; procedure prototype
arr1:PTR SDWORD,
arr2:PTR SDWORD,
diff3:DWORD
.data
arraySyze DWORD 6
diff DWORD 3
index DWORD 0 ;var to use as the first index
Array1 SDWORD 15, 9, 11, 13, 19, 6
Array2 SDWORD 14, 5, 3, 12, 1, 4
text1 BYTE "************* ASM *****************", 0
text2 BYTE "*** Counting Nearly Matching Elements ***", 0
text3 BYTE "the arrays are:...", 0
text4 BYTE "Nearly Mathces were: ",0
.code
main PROC
mov edx, offset text1 ;hands the address of the firs char of text1
call WriteString ;prints out text1
call Crlf
call Crlf
mov edx, offset text2 ; hands the address of the firs char of text2
call WriteString ; prints out text2
call Crlf
call Crlf
mov edx, offset text3 ;hands the address of the firs char of text3
call WriteString ;prints out text3
call Crlf
mov esi,OFFSET Array1 ; puts the offset of array in esi
mov ecx,arraySyze ;6
mov ebx,TYPE Array1
call DumpMem
call Crlf
mov esi,OFFSET Array2 ; puts the offset of array in esi
mov ecx,arraySyze ; 6
mov ebx,TYPE Array1
call DumpMem
mov eax,0
swapLoop:
mov ebx, index ;moves index1 to ebx
;here i use the registers to add 8 in to the stack addresses
INVOKE CountNearMatches, ADDR[Array1 + ebx], ADDR[Array2 + ebx], diff
add ebx, 4 ;adding 4 to ebx
mov index, ebx ;putting ebx back in to index1
loop swapLoop
call Crlf
mov edx, offset text4 ;hands the address of the firs char of text4
call WriteString ;prints out text4
call WriteInt
call Crlf
call Crlf
call WaitMsg ; Press any key to contineu...
exit
main ENDP
; ***************************************
; This is where the magic happnes!
; This function gets its parameters from
; the stack and counts the near mathches
; from the two arrays...
; ***************************************
CountNearMatches PROC USES ebx edx esi edi,
arr1:PTR SDWORD, ;points to the first array
arr2:PTR SDWORD, ;points to the second array
diff3:DWORD ;gets the diff from the stack
;-------------------------------------------------------
mov eax,[arr1]
mov ebx,[arr2]
mov edx, diff3
sub eax,ebx
ret
CountNearMatches ENDP
END main
答案 0 :(得分:0)
我想通了..现在它实际上计算了所有近距离比赛,不确定这是否是最好的方式,但它的工作原理。 这就是我想出来的
var word = 'javascript'.split(''); // ['j', 'a', 'v', 'a' ...]
function guessLetter(guess) {
if(word.indexOf(guess) > -1) {
// remove correct letter guess from word
word.splice(word.indexOf(guess), 1);
}
if(word.length === 0) {
console.log('you win');
}
}
guessLetter('j');