user3274535
user3274535

Reputation:

conceptual x86 assembly 32 bit

enter image description here

can someone explain as to how yval = 3, 5, 7, 9, 11, 13, 10

I get lost at the add esi, 4 and after that it is all a jumble

Upvotes: 0

Views: 201

Answers (2)

Ira Baxter
Ira Baxter

Reputation: 95306

ESI contains a pointer to the array of 32 bit (DWORD) values xval.

"add esi, 4" advances ESI by 4 bytes, e.g., the size of a DWORD; if this were C, it would be ESI+=sizeof(DWORD); thus advancing ESI to point to the next slot in the array xval.

When in doubt, get an instruction set manual, and study it carefully; there are spectactularly good ones at the intel web site. Yes, they are actually daunting in size, and the first time you open one will likely cost you a few hours as you stumble around in the manuals trying to get all the pieces in place. Its a hugely valuable experience if you intend to do any serious assembly language programming.

I'll leave the rest to you.

Upvotes: 0

Paul R
Paul R

Reputation: 212929

I recommend you get hold of a simulator such as Jasmin so that you can step through simple examples like this and see what's going on:

Jasmin screen shot

As you step through the code you can see that for each loop iteration you are loading two consecutive values form xval, adding them, and storing them to yval.

So on the first iteration you load 1 and 2, add them to get 3, then store this to the first element of yval. On the next iteration you get 2 + 3 = 5, and so on.

The last iteration is slightly tricky as the source values are loaded from the last element of xval and the the first element of yval, so you get 7 + 3 = 10.

Upvotes: 2

Related Questions