Solved

TSR Guru needed

Posted on 1998-11-13
6
192 Views
Last Modified: 2010-04-15
I have writen a TSR for DOS that displays the current files is use. This is done by traversing the DOS Systems File Table the pointer to which can be retrieved by an INT 21,34 call.
When the Hot Key is detected I need to build my own Stack for the TSR's local variables and functions. Otherwise it will use the foreground program's Stack and the results would be very unpredictable. I achive this with the following code.
1. _asm
2. {
3.    mov ss_register, ss
4.    mov sp_register, sp
5.    mov ax, offset my_stack[499]
6.    mov sp, ax
7.    mov ax, ds
8.    mov ss, ax
9. {
in line 3 & 4 i save the SS and SP in to my own variables. and in line 5 & 6 I move the SP to the top of my newly built Stack (my_stack). My doubt hear is that my_stack is a global variable. Hence I am actually creating this Stack in the Data Segment.
* Firstly is their any problems in doing this??

As to the size of the Stack I allocated 500 bytes taking into account the following local variables and one function which I am using in the code that uses this Stack.
    struct table_tag {
                        struct table_tag * table_previous;
                        struct table_tag * table_next;
                        long int _far * table_sft;
                        int table_sft_entries;
                     };
    typedef struct table_tag * TABLE_POINTER;
    TABLE_POINTER current_table, previous_table,          first_table;
    char * save_screen;
    char page_entry[21];
    long int _far * current_sft;
    char _far * table_sft_file;
    char _far * video_position;
    int no_of_elements, no_of_pages, page_tag_element,         general_counter,general2_counter;
    int table_sft_counter, key_press, key_scan,         element_counter;
/* and the function */
PaintPicture()
{
    int general_counter, general2_counter;
    char _far * video_position;
* Is 500 bytes adequet for these variables and one function??

I am using MS C ver 7. When I call the TSR through the Hotkey, the routine pops us and works fine. But when I exit the routine I get a runtime error "Stack Overflow" and the foreground program terminates to the DOS prompt. I cannot run any more programs thereafter. The COMMAND interpertor gives "Program too big" even for the simple MEM program. When I compile without Code Optimization and without Stack Probes, the program simply hangs along with the OS.

What is wrong in what I am doing? and how could I solve this problem?
Any help would be much apreciated.
0
Comment
Question by:ravipal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:scrapdog
ID: 1254249
Did you restore the SS and SP to it's original values (in ss_register and sp_register) when the program finishes?
0
 

Author Comment

by:ravipal
ID: 1254250
Hi scrapdog,

Yes I did restore the SS and SP, with the following code.

    _asm
    {
        mov ss, ss_register
        mov sp, sp_register
    }

0
 

Author Comment

by:ravipal
ID: 1254251
One more thing I fogot to mension. In side my routine I am building a Link List to link all the individual DOS System File Tables into one. For this I use the runtime function "maclloc".

Could their be any problem in using this function in side my TSR routine ??
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Accepted Solution

by:
laeuchli earned 70 total points
ID: 1254252
the site :http://www.fys.ruu.nl/~faber/Amain.html has lots of stuff on tsrs. Take a look.

0
 

Author Comment

by:ravipal
ID: 1254253
Hi Scrapdog,

I am still waiting for your response...


0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1254254
Beats me...you probably know more than I do about TSRs!!

I was just checking if you restored SS and SP, because I know if you didn't that would cause problems.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question