home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l440 / 2.ddi / CHAP5 / STACK.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-09-26  |  1.9 KB  |  96 lines

  1. ;STACK.ASM
  2.  
  3. ;Define segment names used by C
  4. ;
  5. _TEXT   segment byte public 'CODE'
  6. _TEXT   ends
  7.  
  8. CONST   segment word public 'CONST'
  9. CONST   ends
  10.  
  11. _BSS    segment word public 'BSS'
  12. _BSS    ends
  13.  
  14. _DATA   segment word public 'DATA'
  15. _DATA   ends
  16.  
  17. DGROUP  GROUP   CONST, _BSS, _DATA
  18.  
  19.     assume  CS:_TEXT, DS:DGROUP  
  20.  
  21.     public  _set_stack, _restore_stack
  22.     extrn   _stack_ptr:near     ;our TSR stack
  23.     extrn   _ss_save:near       ;save foreground SS
  24.     extrn   _sp_save:near       ;save foreground SP
  25.  
  26. _TEXT   segment
  27. ;*****
  28. ;void far set_stack(void) - 
  29. ;   save current stack and setup our local stack
  30. ;*****
  31. _set_stack  proc    far
  32.  
  33. ;save foreground stack
  34.  
  35. ;we need to get the return values from the stack 
  36. ;since the current stack will change
  37.     pop ax  ;get return offset
  38.     pop bx  ;get return segment
  39.  
  40. ;save away foreground process' stack
  41.     mov word ptr _ss_save,ss
  42.     mov word ptr _sp_save,sp
  43.  
  44. ;setup our local stack
  45.     mov ss,word ptr _stack_ptr+2
  46.     mov sp,word ptr _stack_ptr    
  47.  
  48. IFDEF MULTI 
  49.    mov bp,sp   ;make bp relative to our stack frame
  50. ENDIF
  51.  
  52. ;setup for ret
  53.     push    bx  
  54.     push    ax
  55.             
  56.     ret
  57. _set_stack  endp
  58.  
  59. ;*****
  60. ;void far restore_stack(void) - 
  61. ;   restore foreground stack, throw ours away 
  62. ;*****
  63. _restore_stack  proc    far
  64.  
  65. ;we need to get the return values from the stack 
  66. ;since the current stack will change
  67.     pop cx  ;get return offset
  68.     pop bx  ;get return segment
  69.  
  70. ;save background stack
  71.     mov word ptr _stack_ptr+2,ss
  72.     mov word ptr _stack_ptr,sp
  73.  
  74. ;restore foreground stack here
  75.     mov ss,word ptr _ss_save
  76.     mov sp,word ptr _sp_save      
  77.  
  78. IFDEF MULTI 
  79.    mov bp,sp   ;make bp relative to our stack frame
  80. ENDIF
  81.  
  82. ;setup for ret
  83.     push bx 
  84.     push cx
  85.             
  86.     ret
  87. _restore_stack  endp
  88. _TEXT   ends
  89.  
  90. _DATA   segment 
  91.  
  92. _DATA   ends
  93.  
  94.     end
  95.  
  96.