Search code examples
cassemblymemoryheap-memorysbrk

How the system know the end of data segment


2 Questions (the same topic) :

Some examples :

Let's say i have something like that in assembly (GCC Compilation) :

movl 12 -4(%rbp)

When i will give the adress -4(%rbp) to another instruction, how the system will know where stop ? Because -4(%rbp) is the starting adress but we don't have any informations about the stop, it could be a 2x2bytes instead of 4bytes.

My 2nd question is kinda the same, but with the heap, considering i'm using sbrk :

When i'll call sbrk(0) it will give the adress of the break in the heap.
Let's say i'm using sbrk(20)and then sbrk(40) the break will be moved, now i'm trying to access to the space allocated by sbrk(20), same as the assembly, how the system will know when stop and not overflow on the sbrk(40) space ?

Maybe it's a little confusing, tell me if you want me to develop more.


Solution

  • The 'l' of movl means long(32 bit integer, 64 bit float). The last letter defines the size(in gas syntax). Wiki: https://en.wikibooks.org/wiki/X86_Assembly/GAS_Syntax