What is the purpose of the offset in assembly language?

  • Thread starter Thread starter pairofstrings
  • Start date Start date
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
1 reply · 3K views
pairofstrings
Messages
411
Reaction score
7
In stack pointer register of assembly language, the stack is maintained as a LIFO with it's bottom at the start of the Stack Segment (specified by the Stack Segment register). Unlike the Stack Pointer register, the Base Pointer can be used to specify the offset of other program segment.
My question is : What is the offset it is talking about? What is the meaning of offset in assembly language?
 
Physics news on Phys.org
The term "offset" is used instead of "address" because the address is a combination of segment register and the "offset" specified in the instruction and/or a register or two. Note that ESP can't be used as an index or offset register; it's only used for push and pop type instructions, so EBP is used instead.

In 32 bit mode, generally the segment registers all point to the same flat virtual memory address space used by a program.

The default usage for EBP by most compilers is to be used as the base offset for local variables. If a program needs 100 hex bytes of space for local variablex, it allocates it from the stack (ESP) and puts this address in EBP:

Code:
        push    ebp             ;save ebp
        mov     ebp,esp         ;set ebp = esp - 0x100
        sub     ebp,0100h
        ...