Author Topic: Array and Loops  (Read 10486 times)

Offline captainamerica

  • Jr. Member
  • *
  • Posts: 5
Array and Loops
« on: October 06, 2018, 04:32:19 PM »
Hi, So i am new to NASM, and I am trying to add the contents of two arrays and place those contents in another array. I just want to know how do i store the third array onto a stack if i already used esi and edi for the first two arrays. Also, so for what I have done is add the two arrays in loop with esi and edi and placed those contents into AL since they are bytes. But how do I get the third array that is filled with 0s to increment to the next integer so that the sum of each elements can go in there? i just have
Code: [Select]
mov bl, [Array3] but that will only hit the first element of the six. How do i traverse through this array if I am already using and incrementing esi and edi for array 1 and 2.
Sorry if that didn't make sense.

Also, my teacher has his own function library like Irvine32 but for linux. To print an array he has a function to call but would I have to call it inside the loop?

Thanks!
« Last Edit: October 06, 2018, 04:43:13 PM by captainamerica »

Offline dreamCoder

  • Full Member
  • **
  • Posts: 107
Re: Array and Loops
« Reply #1 on: October 06, 2018, 05:11:08 PM »
Show some code so that I/we can get a clue of the 'direction' you're taking. For example, how do you use ESI / EDI in addressing the arrays and stuff. I don't trust beginners with the registers. It could be a dword while implying a byte etc.

For simple additions to the third array (based on what you're telling) it could be something like so;

mov al,byte[Array1]
mov bl,byte[Array2]
add al,bl
mov byte[Array3],al



 

Offline captainamerica

  • Jr. Member
  • *
  • Posts: 5
Re: Array and Loops
« Reply #2 on: October 06, 2018, 05:14:06 PM »
Okay, this is my code for it
Code: [Select]
        I erased my code so that It wouldnt look like i was plagiarizing
« Last Edit: October 06, 2018, 06:34:52 PM by captainamerica »

Offline dreamCoder

  • Full Member
  • **
  • Posts: 107
Re: Array and Loops
« Reply #3 on: October 06, 2018, 05:26:54 PM »
You can point EDX to the Array3 just like you did to other arrays and increment it the same after every iteration.

mov edx,Array3

You need to write to the last array to save the result to Array 3;

mov BYTE[edx],bl

Not the other way around.

Offline captainamerica

  • Jr. Member
  • *
  • Posts: 5
Re: Array and Loops
« Reply #4 on: October 06, 2018, 05:45:42 PM »
okay, thank you so much!