What is the purpose of the offset in assembly language?

  • Thread starter Thread starter pairofstrings
  • Start date Start date
AI Thread Summary
In assembly language, the stack operates on a Last In, First Out (LIFO) principle, with its base defined by the Stack Segment register. The term "offset" refers to the specific location within a segment, distinguishing it from the overall address, which combines the segment register and the offset. The Base Pointer (EBP) is utilized to reference local variables, while the Stack Pointer (ESP) is restricted to push and pop operations. In a 32-bit environment, segment registers typically point to a unified flat virtual memory space. Compilers commonly use EBP to establish a base offset for local variables, allocating space on the stack and adjusting EBP accordingly to manage local variable addresses effectively.
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?
 
Technology 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
        ...
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top