我正在使用MASM & Irvine 32位程序集,並且我有數組A,B,C和堆疊執行A + B = C,將數組A的每個[i]項與數組B和寫入陣列C正確地求和數組
例如,
arrA 1, 2, 4, 1
+
arrB 2, 1, 1, 3
=
arrC 3, 3, 5, 4
我試圖用指針來工作,但我有00,00,00,0F輸出。
不關注StrHex_MY程序,它在輸出數組上測試。
代碼:
.586
.model flat, stdcall
ExitProcess PROTO, dwExitCode:DWORD
include \Irvine\Irvine32.inc
includelib \Irvine\kernel32.lib
includelib \Irvine\user32.lib
include module.inc
.data
CaptionGreet BYTE "Test me", 0
arrA DWORD 1, 2, 4, 1
arrB DWORD 2, 1, 1, 3
arrC DWORD 0, 0, 0, 0
toOut DB 64 dup(?)
.code
main PROC
mov edi, OFFSET arrA ; Address of arrA
mov esi, OFFSET arrB ; Address of arrB
mov eax, 0 ; Register with result
mov ecx, LENGTHOF arrA ; Lenght of arrays
L1:
add eax, [edi] ; Add current arrA element to eax
add eax, [esi] ; Add current arrB element to eax
add edi, TYPE arrA ; Move pointer to the next arrA element
add esi, TYPE arrB ; Move pointer to the next arrB element
mov arrC, eax ; Move current eax value to arrC
loop L1
; Converting result to HEX toOut. Don't pay attention to this part
; ----
push OFFSET toOut
push OFFSET arrC
push 256
call StrHex_MY
; ---
; Output result
INVOKE MessageBoxA, 0, ADDR toOut, ADDR CaptionGreet, 0
INVOKE ExitProcess,0
main ENDP
END main
所以它輸出0F,現在我堆棧訪問每個arrC元素並用arrA + arrB當前元素的總和重寫它。 – NLis