flat assembler
Message board for the users of flat assembler.

Index > Windows > how to understand INC EDI and ADD EDI, 4?

Author
Thread Post new topic Reply to topic
jacky_zz



Joined: 10 Oct 2007
Posts: 4
jacky_zz 11 Oct 2007, 06:12
i got a problem about INC EDI and ADD EDI, 4.
*****code begin*****
long test(void* p) {
__asm {
push edi
mov edi, p
mov [edi], 02h
add edi, 4 // inc edi

mov [edi], 20h
mov eax, [edi]

pop edi
}
}

long* long_array = new long[2];
long result = test(long_array);
*****code end*****
my question: when i use "INC EDI" replace statement "add edi, 4", the EDI's address add one, the pointer "long_array" points to first element of array or not? why?
Post 11 Oct 2007, 06:12
View user's profile Send private message Reply with quote
Artlav



Joined: 23 Dec 2004
Posts: 188
Location: Moscow, Russia
Artlav 11 Oct 2007, 06:28
inc edi is add edi,1, not 4. You have array of long, 4 bytes per element, so add edi,4 seems right to access array[1].

That is, if i got it right what you were asking.
Post 11 Oct 2007, 06:28
View user's profile Send private message Visit poster's website Reply with quote
jacky_zz



Joined: 10 Oct 2007
Posts: 4
jacky_zz 11 Oct 2007, 06:35
yes, it is, when i call "inc edi", and edi's address add 1, if address before call "inc edi" is 0012FEA4, after call, the current address is 0012FEA5, then i call "mov [edi], 20H", i want to know what is value of adress 0012FEA5?
Post 11 Oct 2007, 06:35
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 11 Oct 2007, 11:44
Code:
mov     edi, $0012FEA4   ; EDI = $0012FEA4
inc     edi              ; EDI = $0012FEA5
mov     dword [edi], $20 ; memory at address range $0012FEA5..$0012FEA8 = $00000020 ($0012FEA5 = $20, the other 3 addresses are $00)

    
Post 11 Oct 2007, 11:44
View user's profile Send private message Reply with quote
jacky_zz



Joined: 10 Oct 2007
Posts: 4
jacky_zz 12 Oct 2007, 03:36
oh, i get it, thanks!
Post 12 Oct 2007, 03:36
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.