Sunday 26 February 2017

Quick look at Intel Assembly

Intel registries 64 x86



Assembly Instructions

MOV
  • mov eax, ESP   ;  Move stack pointer to eax
  • mov ebx, [ESP] ;  Move value at top-of-stack to ebx  ( memory content moved 
  • .DATA
    array DD 20 DUP (0) ; Array of 20 integers initialized to zero
    .CODE
    mov ecx, OFFSET array ;  Move starting address of 'array' to ecx. OFFSET is used to move addresses not memory content
  • mov ecx, array ; copy the first element of the array into ecx.  ( memory content moved )
  • mov ecx, 20[ebp]  ;copy the element at [ebp+20] into ecx ( memory content moved )
  • mov eax, table[ESI*4] ; copy element at [ OFFSET table + esi * 4] into eax ( memory content moved )
  • mov ecx, DWORD PTR ?myArray@@3PAHA[eax]  ;  move a DWORD element from myArray@@3PAHA position EAX  into ECX. myArray@@3PAHA is a pointer to the segment area (memory) where myArray lives.  ( memory content moved )
    PTR gives size directives to the instruction.

LEA (Load Effective address)  
  • lea edi, DWORD PTR [ebp-192] ; copy [ebp-192] address into o edi
ADD

  • add eax,[DI + 20 ] ; eax = eax + memory [ DI +20 ]   ( memory content moved )
  • add BYTE PTR  [var], 10 ; add 10 to the single byt eax = eax + memory [ DI +20 ]   ( memory content moved )