For my x86 Assembly Language class we were given an assignment wherein we needed to take in 12 integers and store them in an array called Autumn
, and then display them. My question is why with this code:
INCLUDE Irvine32.inc
.data
Prompt1 BYTE "Please input a value:", 0
Autumn WORD 12 DUP(?)
.code
main PROC
mov esi, OFFSET Autumn
mov ecx, LENGTHOF Autumn
call PromptForIntegers
mov edi, OFFSET Autumn
mov ecx, LENGTHOF Autumn
L2:
mov eax, [edi]
add edi, TYPE Autumn
call WriteInt ;Displays value in EAX
call Crlf ;Moves to next output line
loop L2
exit
main ENDP
;-----------------------------------------------------
PromptForIntegers PROC USES ecx edx esi
;
; Prompts the user for an arbitrary number of integers
; and inserts the integers into an array.
; Receives: ESI points to the array, ECX = array size
; Returns: nothing
;-----------------------------------------------------
mov edx,OFFSET prompt1
L1: call WriteString ; display string
call ReadInt ; read integer into EAX
call Crlf ; go to next output line
mov [esi],eax ; store in array
add esi,TYPE SWORD ; next integer
loop L1
ret
PromptForIntegers ENDP
END main
When I input the integers 1 - 12 into the array. It prints out:
+131073
+196610
+262147
+327684
+393221
+458758
+524295
+589832
+655369
+720906
+786443
+12
The only correct output is the +12
. The rest should be the numbers 1-11.
EDIT: Got it working for positive numbers by changing mov eax, [edi]
to mov ax, [edi]
in L2