The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Joker2u on March 01, 2010, 07:24:07 AM

Title: Difference in registers
Post by: Joker2u on March 01, 2010, 07:24:07 AM
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.
Title: Re: Difference in registers
Post by: jj2007 on March 01, 2010, 07:43:10 AM
Joker,
If you have already imnstalled Masm32, this is the right page for you (http://www.masm32.com/board/index.php?topic=13487.msg105482#msg105482).
Title: Re: Difference in registers
Post by: BlackVortex on March 01, 2010, 07:50:15 AM
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.
Title: Re: Difference in registers
Post by: Joker2u on March 01, 2010, 08:09:33 AM
Anyone of EIP or EDI?
Title: Re: Difference in registers
Post by: 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.
Title: Re: Difference in registers
Post by: hutch-- on March 01, 2010, 10:26:37 AM
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".
Title: Re: Difference in registers
Post by: dedndave on March 01, 2010, 10:39:52 AM
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
Title: Re: Difference in registers
Post by: jj2007 on March 01, 2010, 04:08:27 PM
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
Title: Re: Difference in registers
Post by: MichaelW on March 02, 2010, 01:32:44 AM
It's not directly accessible in that you cannot use it as an instruction operand.
Title: Re: Difference in registers
Post by: Joker2u on March 04, 2010, 02:25:30 AM
what would be a valid instruction for changing the EIP from where it points to 100 spots of memory before that point??
Title: Re: Difference in registers
Post by: dedndave on March 04, 2010, 02:27:52 AM
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
Title: Re: Difference in registers
Post by: BlackVortex on March 04, 2010, 06:48:31 PM
jmp $-100

100 bytes before that (decimal)

but better use a labelĀ  :bg