flat assembler
Message board for the users of flat assembler.

Index > OS Construction > multiple stacks in real mode.

Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
hello.
as i was thinking about a real time path list, i sudentlly think have the idea to use the push and pop operations to do that.
but then, it will act on a secondary stack.

Code:
normal stack dd 1000h:0
secondary stack dd 2000h:0
    


then, use the normal stack for basic operations on push & pops during code exustions.

and use the secondary stack as a path, updated each time we call or ret.
then, it will be easy to know the exact location of curent code or item...

someting like that.

but i wonder how i can do it efficienttly, and securelly...
Post 06 Mar 2010, 09:06
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
edfed,

This resembles the concept from FORTH: separate data and return stacks. Nothing really complex, you may use following (straightforward) macros, assuming that return stack is pointed by es:bp:
Code:
macro _call_f target* {
local ..retaddr
  mov [es:bp-2], cs
  mov word[es:bp-4], ..retaddr
  lea ebp, [bp-4]
  jmp target
..retaddr:
}

macro _ret_f {
  lea ebp, [bp+4]
  jmp dword[es:bp-4]
}    
Another technique is to reserve one register as link register which will contain return address upon function entry, RISC style. In this case, called function is responsible to save/restore that address (if it needs that register for something, e.g. to call another function).
Code:
macro _call_r target* {
local ..retaddr
  mov bp, ..retaddr
  jmp target
..retaddr:
}

macro _ret_r {
  jmp bp
}    
Post 06 Mar 2010, 10:44
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.