1
Im在添加數組時遇到了一些問題,但在輸入的索引上。例如,用戶輸入4作爲開始,6作爲結束數組,所以我將不得不遍歷數組[4]到數組[6]並且包含數字。我不確定我是否可以在ArraySum過程的.data中使用我的數組。我是否必須以某種方式將它推入程序?在彙編x86中彙總數組。在輸入的索引
我正在使用Kip Irvine的外部庫。
我的代碼是在這裏:
TITLE Assignment 7
INCLUDE Irvine32.inc
.data
str1 BYTE "The array sum is: ",0
start BYTE "Enter the Starting Index: ",0
endinx BYTE "Enter the Ending Index: ",0
array DWORD 4, 6, 2, 5, 6, 7, 8, 4
sum DWORD ?
j DWORD ?
k DWORD ?
.code
main PROC
mov esi, OFFSET array
mov ecx, LENGTHOF array
mov edx, OFFSET start
call WriteString
call ReadInt
mov j, eax
mov esi, j
mov edx, OFFSET endinx
call WriteString
call ReadInt
mov k, eax
mov ecx, k
call ArraySum
mov sum,eax
call WriteInt
main ENDP
;---------------------------------------------------
ArraySum PROC
;sums an array falling within j..k inclusive
;---------------------------------------------------
push esi
push ecx
mov eax, 0
L1:
add eax, array[esi]
add esi, TYPE DWORD
loop L1
pop ecx
pop esi
ret
ArraySum ENDP
END main