flat assembler
Message board for the users of flat assembler.
Index
> DOS > DOS memory allocation and stack overwrite. |
Author |
|
revolution 10 Jul 2020, 12:07
What are the values of SP and SS?
|
|||
10 Jul 2020, 12:07 |
|
Tomasz Grysztar 10 Jul 2020, 12:24
BoraxMan wrote:
Code: STACK STACK16:ENDSTACK |
|||
10 Jul 2020, 12:24 |
|
Tomasz Grysztar 10 Jul 2020, 12:29
Also, additional bit of advice: instead of having to resize the program segment, you can make your program image not allocate excess memory in the first place. Do it with:
Code: HEAP 0 This tells DOS to not allocate any additional memory on top of your defined segments, and leaves the rest of conventional memory available. Then you can safely get rid of that initial 4Ah system call. It was only needed for .COM programs, or maybe as a workaround for MZ linkers that had no option to make the program image not "greedy" (although I don't remember whether that was a real issue). |
|||
10 Jul 2020, 12:29 |
|
BoraxMan 10 Jul 2020, 14:45
Tomasz Grysztar wrote:
That makes sense. My previous assembly experience is with DOS and Linux, but with MASM for DOS many years ago, and I don't recall having to define the stack in any more detail than simply using a directive. With Linux, the stack is set up by the OS. I based my code off a tutorial here https://www.codeproject.com/Articles/45788/The-Real-Protected-Long-mode-assembly-tutorial-for But that has errors, and claims that SS and SP are automatically set. My error was assuming that SP would point to the top of the stack, and I think the example program in the tutorial has the same bug/assumption. It works when I use STACK STACK16:ENDSTACK If I use in place of that, "STACK 100h", I note that the stack is placed right at the end, at location 0x1763. ENDSEG is at 0x1763, and DOS allocates memory at location 0x1764, which overwrites the stack again. So FASM must be putting the stack at the end, after ENDSEG and therefore I'm "freeing" the stack with my call to resize the program. Removing the code which calls on DOS frees memory (Fuction 4Ah), and using "HEAP 0" as per your recommendation, results in correct behaviour. Thanks for your help. Documentation was a little hard to come by with regards to proper memory management in DOS |
|||
10 Jul 2020, 14:45 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.