I'm trying to put together a BYTE array of chars and a DWORD array of numbers and reverse them into a QWORD array. so if 1,2,3,4,5 and s,h,r,u,g are entered, it will print out g5 u4 r3 h2 s1. I keep getting weird garbage values for only ONE of the arrays. Only one will print like it should. If I change one of the arrays to a copy of the other, it works perfectly fine.
include irvine32.inc
.data
string1 byte 0Ah,0Dh,"Dumping out charArr",0
string2 byte 0Ah,0Dh,"Dumping out numArr", 0
string3 byte 0Ah,0Dh,"Dumping out newArr", 0
charArr byte 5 dup (?)
numArr dword 5 dup (?)
newArr qword 5 dup (?)
prompt1 byte "Please enter a number: ", 0
prompt2 byte "Please enter 5 characters: ", 0
prompt3 byte "The integer array you entered is: ", 0
prompt4 byte "The characters you entered are: ", 0
prompt5 byte "The mean of the integer array is: ", 0
prompt6 byte "The elements of the new array are: ", 0
prompt7 byte " ", 0
mov esi, offset numArr ; number input
mov ecx, lengthof numArr
mov edx, offset prompt1
L1:
call writeString
call readDec
mov [esi], eax
add esi, type numArr
loop L1
mov esi, offset numArr ; array output
mov ecx, lengthof numArr
mov edx, offset prompt3
call writeString
L3:
mov eax, [esi]
call writeDec
add esi, type numArr
mov al, ' '
call writeChar
loop L3
call crlf
mov esi, offset charArr ; char input
mov ecx, lengthof charArr
mov edx, offset prompt2
call writeString
L2:
call readChar
mov [esi], al
add esi, type charArr
loop L2
call crlf
mov esi, offset charArr ;char output
mov ecx, lengthof charArr
mov edx, offset prompt4
call writeString
L4:
mov eax, [esi]
call writeChar
add esi, type charArr
mov al, ' '
call writeChar
loop L4
call crlf
sub eax, eax
sub edx, edx
mov esi, offset numArr
mov ecx, lengthof numArr
L5:
add eax, [esi]
add esi, type numArr
loop L5
mov ecx, lengthof numArr
div ecx
mov ebx, edx
mov edx, offset prompt5
call writeString
call writeDec
call crlf
; reversing and combining arrays
mov esi, offset newArr
mov edi, offset charArr + type numArr
mov ecx, lengthof newArr
mov edx, offset prompt6
call writeString
L6:
mov eax, [edi]
dec edi
mov [esi], eax
add esi, type newArr
loop L6
mov esi, offset newArr + type numArr
mov edi, offset numArr + type numArr * type numArr
mov ecx, lengthof newArr
L7:
mov eax, [edi]
sub edi, type numArr
mov [esi], eax
add esi, type newArr
loop L7
;printing
mov esi, offset newArr
mov ecx, lengthof newArr
mov edx, offset prompt7
L8:
mov eax, [esi]
call writeChar
add esi, type numArr
call writeDec
add esi, type numArr
call writeString
loop L8