News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Difference in registers

Started by Joker2u, March 01, 2010, 07:24:07 AM

Previous topic - Next topic

Joker2u

Hi all I am new to ASM and I am using Kip Irvine's Assembly Language for Intel Based Computers 5th edition.  I was wondering if anyone could explain registers other than EAX, EBX, ECX, and EDX, as I am confident in my use of these registers.  I mainly need a brief explanation of ESI, EIP, EDI, EBP, and ESP, any explanations would be greatly appreciated whether they are short or long.  Thank you.

jj2007


BlackVortex

ESI and EDI are usually used as "source" and "destination" when copying memory or equivalent operations. There are some opcodes that work with esi/edi specifically.

ESP is the stack pointer, it changes automatically by pushing,popping,ret,call etc. Usually you don't want to change it manually.

EBP is usually used at the start of procedures to save the stack pointer, so that local variables can easily be accessed and then the original pointer is restored before returning.

EDIT: Yes, like JJ says, you need to understand which registers get thrashed when using APIs and other external calls. And macros.

Joker2u


MichaelW

EIP holds the 32-bit instruction pointer. It is not one of the general-purpose registers and is not directly accessible to the programmer. It is used as an offset into the code segment when the processor fetches instructions.
eschew obfuscation

hutch--

It is actually spelt out in the Asm Intro Help file in masm32 that you get to from the help menu. Select the helptopic "Register Preservation Convention".
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

the letters actually do mean something - lol
it gives you a guideline to go by, but most of them are called "general registers" - you can use them as needed

EAX - accumulator
EBX - base
ECX - count
EDX - data
ESI - source index
EDI - destination index
EBP - base pointer
ESP - stack pointer

jj2007

Quote from: MichaelW on March 01, 2010, 08:57:42 AM
EIP holds the 32-bit instruction pointer. It is not one of the general-purpose registers and is not directly accessible to the programmer. It is used as an offset into the code segment when the processor fetches instructions.

"not so directly" accessible...

include \masm32\include\masm32rt.inc

.data?
zebuffer db 100 dup(?)

.code
start: mov ebx, $
call @F
@@: pop esi
sub esi, ebx
MsgBox 0, cat$(offset zebuffer, "EIP=", hex$(ebx), ", and the mov ebx, $ plus call @F costs 2*5=", str$(esi), " bytes"), "Hellooo...!", MB_OK
exit
end start

MichaelW

It's not directly accessible in that you cannot use it as an instruction operand.
eschew obfuscation

Joker2u

what would be a valid instruction for changing the EIP from where it points to 100 spots of memory before that point??

dedndave

to change EIP, use JMP or CALL (or one of the conditional branches)
RET also changes it, of course
that is sometimes done in special cases - PUSH the address, then RET

BlackVortex

jmp $-100

100 bytes before that (decimal)

but better use a labelĀ  :bg