公平地說,我完全迷路了,這段代碼可能完全錯誤,但我想問我如何創建一個回圈來檢查我的陣列中的兩位數。[在此處輸入影像描述][1]
[1]:https : //i.stack.imgur.com/BZ2BM.png /// 編輯,完全重寫代碼現在可以作業了,謝謝大家的幫助<3
uj5u.com熱心網友回復:
據我了解,您有一個包含數字的陣列。你想找到兩位數字的總和。為此,首先,讓我們定義一個陣列和一個 sum 變數。將 a0xFFFF放在串列的末尾將有助于我們找到串列的末尾。
arr: dd 15, 16, 9, 8, 0xFFFFFFFF
sum: dd 0x00000000
現在我們需要遍歷陣列并找到兩位數:
start:
push ebx
mov edx, arr ; get the address of the array
xor ecx, ecx
.loop:
mov eax, dword [edx] ; get the nth word into eax
cmp eax, 0xFFFFFFFF ; check if we are at the end of list
je endLoop ; if we are end the loop
add edx, 4 ; add 2 to the pointer to get the next word.
cmp eax, 9 ; check if the nth word is 1 digit
jng .loop ; if it is 1 digit just loop
cmp eax, 99 ; check if it is 3 digits
jg .loop ; loop if it is
add ecx, eax ; we have the two digit number, add it to sum
jmp .loop ; and loop
endLoop:
mov dword [sum], ecx
pop ebx
ret
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/515475.html
標籤:部件masm
