6 Replies - 216 Views - Last Post: 18 February 2019 - 03:33 AM

#1 DiesIrae   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-February 19

Having trouble with a supposed multidimensional array

Posted 15 February 2019 - 08:19 AM

Hello Everyone!
I am trying to move the sum of corresponding elements of two arrays into a third array without any luck. I am using masm615 with irvine's library. Could anyone please help me out with it?

include irvine32.inc

.data
myArray1 word 9, 7, 6, 5, 4, 4, 3, 3
       word 6, 6, 5, 4, 4, 3, 3, 2
       word 5, 5, 5, 4, 4, 3, 3, 2
       word 4, 4, 4, 4, 4, 4, 2, 2
       word 3, 3, 3, 3, 3, 2, 2, 2
       word 3, 3, 3, 2, 2, 2, 2, 2
       word 2, 2, 2, 2, 2, 2, 2, 2
       word 2, 2, 2, 2, 2, 2, 2, 2

myArray2 word 8, 6, 6, 5, 5, 4, 4, 4 
       word 6, 6, 6, 5, 5, 4, 4, 4
       word 6, 6, 6, 5, 5, 5, 4, 4
       word 6, 6, 5, 5, 4, 4, 4, 3
       word 6, 5, 5, 5, 4, 4, 4, 3
       word 5, 5, 5, 5, 4, 4, 4, 3
       word 5, 5, 5, 4, 4, 4, 4, 3
       word 5, 5, 4, 4, 4, 4, 3, 3 
       
myArray3 word 8 DUP (8 DUP (?))

space BYTE ' '
count WORD ?
.code
main PROC
mov ax,0
mov cx,64
mov ebx, 0
mov esi, OFFSET myArray1
mov edi, OFFSET myArray2
L1:

mov dx,0

add dx, [esi]
add dx, [edi]
mov myArray3[ebx], 0
add esi, TYPE myArray1
add edi, TYPE myArray1
add ebx, 2
loop L1
mov cx, 4
mov esi, OFFSET myArray3
L2:
mov count,cx
mov cx,8
call crlf
L3:

mov ax, [esi]
call writeint
mov al, space
call writechar
add esi, 2
mov ecx,0
loop L3
mov cx, count
loop L2
exit
main ENDP
END main 




Is This A Good Question/Topic? 0
  • +

Replies To: Having trouble with a supposed multidimensional array

#2 Ornstein   User is offline

  • New D.I.C Head

Reputation: 11
  • View blog
  • Posts: 20
  • Joined: 13-May 15

Re: Having trouble with a supposed multidimensional array

Posted 15 February 2019 - 09:23 AM

When you say you're not having any luck, what are you struggling with specifically?

I've only skimmed over your code, but it looks at first glance like your logic before line 44 is fine. The problems seem to begin after that. For example, on line 57 you set ecx to 0 and then on line 58 use the loop instruction? Presumably you know how the loop instruction works?
Was This Post Helpful? 1
  • +
  • -

#3 DiesIrae   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-February 19

Re: Having trouble with a supposed multidimensional array

Posted 15 February 2019 - 01:06 PM

Yes, actually I was tinkering with my code so that I could know where the problem lay but the program kept giving me non-sensical outputs. Even the number of outputs didn't correspond to my loop counts, I tried to set ecx to zero to check if there was a problem with how many times the loop ran but it didn't help much. I am sorry for the code, this isn't what I had actually written.
I was just trying to debug it and grew quite frustrated and posted it here.
Was This Post Helpful? 0
  • +
  • -

#4 Ornstein   User is offline

  • New D.I.C Head

Reputation: 11
  • View blog
  • Posts: 20
  • Joined: 13-May 15

Re: Having trouble with a supposed multidimensional array

Posted 17 February 2019 - 03:56 AM

So have you figured it out since - or do you still need help?
Was This Post Helpful? 1
  • +
  • -

#5 DiesIrae   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-February 19

Re: Having trouble with a supposed multidimensional array

Posted 17 February 2019 - 04:23 AM

Still no luck. The program assembles correctly but nothing gets printed on the command line. The process gets terminated after a few seconds. Here's the code

include irvine32.inc

.data
myArray1 word 9, 7, 6, 5, 4, 4, 3, 3
       word 6, 6, 5, 4, 4, 3, 3, 2
       word 5, 5, 5, 4, 4, 3, 3, 2
       word 4, 4, 4, 4, 4, 4, 2, 2
       word 3, 3, 3, 3, 3, 2, 2, 2
       word 3, 3, 3, 2, 2, 2, 2, 2
       word 2, 2, 2, 2, 2, 2, 2, 2
       word 2, 2, 2, 2, 2, 2, 2, 2

myArray2 word 8, 6, 6, 5, 5, 4, 4, 4 
       word 6, 6, 6, 5, 5, 4, 4, 4
       word 6, 6, 6, 5, 5, 5, 4, 4
       word 6, 6, 5, 5, 4, 4, 4, 3
       word 6, 5, 5, 5, 4, 4, 4, 3
       word 5, 5, 5, 5, 4, 4, 4, 3
       word 5, 5, 5, 4, 4, 4, 4, 3
       word 5, 5, 4, 4, 4, 4, 3, 3 
       
myArray3 word 8 DUP (8 DUP (?))
ptrA DWORD ?
; ptrC DWORD myArray3
space BYTE ' '
count WORD ?
.code
main PROC
mov ax,0
mov cx,64
mov ebx, OFFSET myArray3
mov esi, OFFSET myArray1
mov edi, OFFSET myArray2
L1:
mov dx,0
add dx, [esi]
add dx, [edi]
mov [ebx], dx
add esi, TYPE myArray1
add edi, TYPE myArray1
add ebx, TYPE myArray3
loop L1
mov cx, 8
mov esi, OFFSET myArray3
L2:
mov count,cx
mov cx,8
call crlf
L3:
mov ax, [esi]
call writeint
mov al, space
call writechar
add esi, TYPE myArray3
loop L3
mov cx, count
loop L2
exit
main ENDP
END main 



Was This Post Helpful? 0
  • +
  • -

#6 Ornstein   User is offline

  • New D.I.C Head

Reputation: 11
  • View blog
  • Posts: 20
  • Joined: 13-May 15

Re: Having trouble with a supposed multidimensional array

Posted 17 February 2019 - 05:35 AM

As far as I can tell, your code between lines 29 and 42 must work because I've tested it myself and it writes the correct values to the array.

The problem must lie in the other code. You probably already know that function calls may result in your registers being overwritten (by/within the function) - so maybe one of the irvine32 functions is overwriting ecx and that's messing up one of your loops? Try saving and restoring its value somewhere (you already do this for one of the loops, but not the other).
Was This Post Helpful? 1
  • +
  • -

#7 DiesIrae   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-February 19

Re: Having trouble with a supposed multidimensional array

Posted 18 February 2019 - 03:33 AM

Changed a few things and it eventually ran correctly. Still not sure what the problem was.

include irvine32.inc

.data
myArray1 word 9, 7, 6, 5, 4, 4, 3, 3
       word 6, 6, 5, 4, 4, 3, 3, 2
       word 5, 5, 5, 4, 4, 3, 3, 2
       word 4, 4, 4, 4, 4, 4, 2, 2
       word 3, 3, 3, 3, 3, 2, 2, 2
       word 3, 3, 3, 2, 2, 2, 2, 2
       word 2, 2, 2, 2, 2, 2, 2, 2
       word 2, 2, 2, 2, 2, 2, 2, 2

myArray2 word 8, 6, 6, 5, 5, 4, 4, 4 
       word 6, 6, 6, 5, 5, 4, 4, 4
       word 6, 6, 6, 5, 5, 5, 4, 4
       word 6, 6, 5, 5, 4, 4, 4, 3
       word 6, 5, 5, 5, 4, 4, 4, 3
       word 5, 5, 5, 5, 4, 4, 4, 3
       word 5, 5, 5, 4, 4, 4, 4, 3
       word 5, 5, 4, 4, 4, 4, 3, 3 
       
myArray3 word 8 DUP (8 DUP (?))
count1 word 0
; ptrC DWORD myArray3
space BYTE ' '
count WORD ?
.code
main PROC
mov ax,0
mov cx,63
mov ebx, OFFSET myArray3
mov esi, OFFSET myArray1
mov edi, OFFSET myArray2
L1:
mov dx,0
add dx, [esi]
add dx, [edi]
mov [ebx], dx
add esi, TYPE myArray1
add edi, TYPE myArray1
add ebx, TYPE myArray3
dec cx
jnz L1
mov cx, 8
mov esi, OFFSET myArray3
mov eax, 0
L2:
mov count,cx
mov cx,8
		L3:
		mov ax, [esi]
		call writedec
		mov al, space
		call writechar
		add esi, TYPE myArray3
		inc count1
	        dec cx
		jnz L3
mov cx, count
call crlf
dec cx

jnz L2
exit
main ENDP
END main 








Thanks a lot @Ornstein.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1