Recent

Author Topic: Inline asm problem with assign  (Read 18349 times)

rvk

  • Hero Member
  • *****
  • Posts: 6921
Re: Inline asm problem with assign
« Reply #30 on: June 24, 2015, 01:33:01 pm »
So off topic , what records contain what?
ebp - local varibles
ebx - information about visual component (Edit, Label, etc)
esi - ?
A few sources to learn about these (These are just the first 3 hits on Google :)):
The Art of Picking Intel Registers
x86 Registers
understand.... registers

Or:
http://docwiki.embarcadero.com/RADStudio/XE8/en/Using_Inline_Assembly_Code
(index at: http://docwiki.embarcadero.com/RADStudio/XE8/en/Inline_Assembly_Code_Index)

Well, you get my drift... there are a lot of sources.

Rekumkacz

  • New Member
  • *
  • Posts: 21
Re: Inline asm problem with assign
« Reply #31 on: June 24, 2015, 02:11:49 pm »
I have already written in pure x86 ASM . I wonder what keeps esi.

Code: [Select]
mov        dword ptr [esi],eax
 mov        eax,dword ptr [esi] 


These two instructions tell me nothing what do.

rvk

  • Hero Member
  • *****
  • Posts: 6921
Re: Inline asm problem with assign
« Reply #32 on: June 24, 2015, 02:29:27 pm »
I have already written in pure x86 ASM . I wonder what keeps esi.

Code: [Select]
mov        dword ptr [esi],eax
 mov        eax,dword ptr [esi]


These two instructions tell me nothing what do.
Wait... You've written this yourself in pure x86 ASM and you don't know what is held in esi?

I can't tell you either. You need to look further back to see where esi is filled with something. These are registers. Registers are only temporary for "doing things". They need to be filled before you can use them.

If you DIDN'T write this ASM yourself but it's part of a compiled pascal program then this code could be part of two statements. One in which the result is stored in a memory location (dword ptr [esi]) and the other where that result again is needed for following statements.

Quote
DS:ESI EDI SI : Source index register
                Used for string and memory array copying

But without seeing more you can't say anything about these statements.



B.T.W.
If you want to snoop around in the assembler-window of the debugger in Lazarus, and you're more familiar with the Intel-syntax, you might want to change the settings. It's explained here.

Default setting: AT&T syntax
Code: [Select]
unit1.pas:36                      s:= 'a';
00425780 bba8915500               mov    $0x5591a8,%ebx
00425785 8d45f4                   lea    -0xc(%ebp),%eax
00425788 e803e4fdff               call   0x403b90 <fpc_ansistr_decr_ref>
0042578D 895df4                   mov    %ebx,-0xc(%ebp)
00425790 e80b62feff               call   0x40b9a0 <fpc_popaddrstack>

x86/x64 Intel syntax:
Code: [Select]
unit1.pas:36                      s:= 'a';
00425780 bba8915500               mov    ebx,0x5591a8
00425785 8d45f4                   lea    eax,[ebp-0xc]
00425788 e803e4fdff               call   0x403b90 <fpc_ansistr_decr_ref>
0042578D 895df4                   mov    DWORD PTR [ebp-0xc],ebx
00425790 e80b62feff               call   0x40b9a0 <fpc_popaddrstack>

(I prefer the Intel syntax)
« Last Edit: June 24, 2015, 02:40:56 pm by rvk »

Rekumkacz

  • New Member
  • *
  • Posts: 21
Re: Inline asm problem with assign
« Reply #33 on: June 24, 2015, 03:20:00 pm »
I don't use debug in Lazarus i got used IDA Pro with intel syntax :)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Inline asm problem with assign
« Reply #34 on: June 25, 2015, 12:04:12 am »
Compile a pure Pascal program with -ar, register allocation steps will be written. You will know what register represents what. AFAIR, in the default register calling convention, only eax, edx and ecx have defined rules. All other registers are free, meaning they may be used for whatever the compiler wants. The x86 code generator is smart enough to use esi & edi for sequential data operation, because x86 has specific instruction that deals with the two (and ecx as counter).

Rekumkacz

  • New Member
  • *
  • Posts: 21
Re: Inline asm problem with assign
« Reply #35 on: June 26, 2015, 09:05:31 am »
And not for something completely different.
In the code, I want to re-use are registers esi and edi . The program compiles , but appears access violation error.

I know the this is a for loop in asm
Quote
   
mov   dword ptr ds:[gvar_456BEC],7Ah
mov   dword ptr [edi],1
@loc2:
   mov   eax,[gvar_456BEC]
   add   eax,dword ptr [edi]
   mov   dword ptr [esi],eax
   inc   dword ptr [edi]
   cmp   dword ptr [edi],0Bh
   jne   @loc2
 
How to eat this cake?
« Last Edit: June 26, 2015, 09:09:12 am by Rekumkacz »

rvk

  • Hero Member
  • *****
  • Posts: 6921
Re: Inline asm problem with assign
« Reply #36 on: June 26, 2015, 10:12:48 am »
This doesn't feel like a for loop from FPC. For/to uses jl as end instruction and For/downto uses jg. Neither uses jne. It's more likely a repeat or while loop.

And again... I'm seeing you're using esi... (putting eax in the memory location where esi is pointing to) but where is esi filled ?
You are not showing enough code.

If esi is undefined, it's easy to explain why you're getting an access violation.


Rekumkacz

  • New Member
  • *
  • Posts: 21
Re: Inline asm problem with assign
« Reply #37 on: June 26, 2015, 10:28:24 am »
This is not my code :)

I make a trick, i created a v_esi and v_edi as integer, and work and profit.

Quote
   mov   dword ptr ds:[gvar_456BEC],7Ah
   mov   dword ptr [v_edi],1

  @loc2:
   mov   eax,[gvar_456BEC]   
   add   eax,dword ptr [v_edi]
   mov   dword ptr [v_esi],eax
   inc   dword ptr [v_edi]
   cmp   dword ptr [v_edi],0Bh
   jne   @loc2

 

TinyPortal © 2005-2018