home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / doc / ems / demos / asmexamp / overlay.asm < prev    next >
Encoding:
Assembly Source File  |  1988-04-22  |  8.6 KB  |  249 lines

  1. PAGE 60, 132
  2. NAME    pseudo_overlay_module
  3.  
  4. ;-----------------------------------------------------------------------------;
  5. ;   Placing null segment declarations at this point forces the segment        ;
  6. ;   order for the remainder of the program.                                   ;
  7. ;-----------------------------------------------------------------------------;
  8.  
  9. CODE    SEGMENT PARA PUBLIC 'CODE'
  10. ORG    100h
  11. CODE    ENDS
  12.  
  13. DATA    SEGMENT PARA PUBLIC 'DATA'
  14. DATA    ENDS
  15.  
  16.  
  17. PAGE
  18. ;-----------------------------------------------------------------------------;
  19. ;                     E Q U A T E S   &   M A C R O S                         ;
  20. ;-----------------------------------------------------------------------------;
  21. cr    EQU    0Dh
  22. lf    EQU    0Ah
  23.  
  24. DISPLAY    MACRO        msg
  25.     MOV        AH, 09h
  26.     LEA        DX, msg
  27.     INT        21h
  28. ENDM
  29.  
  30.  
  31. PAGE
  32. ;-----------------------------------------------------------------------------;
  33. ;         C O D E   S E G M E N T    F O R   T H E   O V E R L A Y            ;
  34. ;-----------------------------------------------------------------------------;
  35.  
  36. CODE    SEGMENT PARA PUBLIC 'CODE'
  37.  
  38. ASSUME CS:CODE, DS:DATA
  39.  
  40. ;-----------------------------------------------------------------------------;
  41. ;   We will establish a convention in which the first object located at the   ;
  42. ;   expanded memory page frame will be a data structure which describes       ;
  43. ;   the data & extra segments of the loaded overlay, the number of procedure  ;
  44. ;   entry points in the loaded overlay, and a list of far pointers to         ;
  45. ;   each of the procedures contained in the pseudo-overlay which is to be     ;
  46. ;   loaded in expanded memory.  The developer must establish a convention     ;
  47. ;   for the sequence of the far pointers and what the procedures they point   ;
  48. ;   to do.  Other information could be passed in this structure as well.      ;
  49. ;   Such as, number and types of parameters which are be passed by the        ;
  50. ;   calling procedures to the called procedures in the pseudo-overlay.        ;
  51. ;                                                                             ;
  52. ;   This example uses a literal to determine the actual number of far         ;
  53. ;   pointers which are passed.  To allocate additional space for a larger     ;
  54. ;   number of entries, simply increase the value of actual_proc_entries.      ;
  55. ;   The example assumes an actual count of 2 entries will be returned.        ;
  56. ;-----------------------------------------------------------------------------;
  57.  
  58. actual_proc_entries        EQU    2
  59.  
  60. overlay_entry_struct        STRUC
  61.     proc_data_segment    DW    ?
  62.     proc_extra_segment    DW    ?
  63.     proc_entry_count    DW    ?
  64.     proc_entry_ptr        DD actual_proc_entries DUP (?)
  65. overlay_entry_struct        ENDS
  66.  
  67.  
  68. PAGE
  69. ;-----------------------------------------------------------------------------;
  70. ;         C O D E   S E G M E N T    F O R   T H E   O V E R L A Y            ;
  71. ;-----------------------------------------------------------------------------;
  72.  
  73. initialization    PROC    FAR
  74.  
  75.     MOV    AX, DATA                    ;   Set up local data segment
  76.     MOV    DS, AX
  77.  
  78.     MOV    AH, 41h                        ;   Get the page frame segment
  79.     INT    67h                        ; address from EMM
  80.     OR    AH, AH
  81.     JNZ    error_exit
  82.  
  83.     MOV    ES, BX                        ; Create a pointer to the expanded memory 
  84.     MOV    DI, 0                        ; page frame segment address
  85.  
  86.     MOV    ES:[DI].proc_data_segment, DS            ; Return local data & extra segement back to kernal
  87.     MOV    ES:[DI].proc_extra_segment, DS
  88.  
  89.     MOV    WORD PTR ES:[DI].proc_entry_count, 2        ; Return number of local callable
  90.                                 ; procedures back to kernal
  91.  
  92.     MOV    WORD PTR ES:[DI].proc_entry_ptr[0], OFFSET sum    ; Return a far pointer to each
  93.     MOV    WORD PTR ES:[DI].proc_entry_ptr[2], SEG    sum    ; local callable procedure in
  94.     MOV    WORD PTR ES:[DI].proc_entry_ptr[4], OFFSET diff    ; the pseudo-overlay back to kernal
  95.     MOV    WORD PTR ES:[DI].proc_entry_ptr[6], SEG    diff
  96.  
  97. exit:
  98.  
  99.     MOV    AH, 0                        ; Set status in AH = passed
  100.  
  101. error_exit:
  102.  
  103.     RET                            ; Return status in AH
  104.  
  105.  
  106. initialization    ENDP
  107.  
  108.  
  109. PAGE
  110. ;-----------------------------------------------------------------------------;
  111. ;   This procedure merely informs a user that this is an overlay and cannot   ;
  112. ;   be executed from the command line.                                        ;
  113. ;-----------------------------------------------------------------------------;
  114.  
  115. command_line_entry_point    PROC    NEAR
  116.  
  117.     ;---------------------------------------------------------------------;
  118.     ;   Initialization                                                    ;
  119.     ;---------------------------------------------------------------------;
  120.     MOV    AX, DATA
  121.     MOV    DS, AX
  122.  
  123.     ;---------------------------------------------------------------------;
  124.     ;   Indicate to the user that the overlay cannot be executed from     ;
  125.     ;   The command line.                                                 ;
  126.     ;---------------------------------------------------------------------;
  127.     DISPLAY    overlay_err_msg
  128.  
  129.     ;---------------------------------------------------------------------;
  130.     ;   Exit to DOS command line.                                         ;
  131.     ;---------------------------------------------------------------------;
  132.     MOV    AX, 4C00h
  133.     INT    21h
  134.  
  135. command_line_entry_point    ENDP
  136.  
  137.  
  138. PAGE
  139. ;-----------------------------------------------------------------------------;
  140. ;   This procedure simpy adds the numbers in AX & DX and displays them.       ;
  141. ;-----------------------------------------------------------------------------;
  142.  
  143. sum    PROC    FAR
  144.  
  145.     ;---------------------------------------------------------------------;
  146.     ;   Simple minded procedure to add two numbers passed to it.          ;
  147.     ;---------------------------------------------------------------------;
  148.     ADD        AX, DX
  149.  
  150.     ;---------------------------------------------------------------------;
  151.     ;   Display the results.                                              ;
  152.     ;---------------------------------------------------------------------;
  153.     PUSH        AX
  154.     DISPLAY        sum_msg
  155.     POP        AX
  156.     CALL        display_result
  157.     DISPLAY        cr_lf_msg
  158.  
  159.     ;---------------------------------------------------------------------;
  160.     ;   Return to the caller.                                             ;
  161.     ;---------------------------------------------------------------------;
  162.     RET
  163.  
  164. sum    ENDP
  165.  
  166.  
  167. ;-----------------------------------------------------------------------------;
  168. ;   This procedure simply subtracts the numbers in AX & DX and displays them. ;
  169. ;-----------------------------------------------------------------------------;
  170.  
  171. diff    PROC    FAR
  172.  
  173.     ;---------------------------------------------------------------------;
  174.     ;   Simple minded procedure to subtract two numbers passed to it.     ;
  175.     ;---------------------------------------------------------------------;
  176.     SUB        AX, DX
  177.  
  178.     ;---------------------------------------------------------------------;
  179.     ;   Display the results.                                              ;
  180.     ;---------------------------------------------------------------------;
  181.     PUSH        AX
  182.     DISPLAY        diff_msg
  183.     POP        AX
  184.     CALL        display_result
  185.     DISPLAY        cr_lf_msg
  186.  
  187.     ;---------------------------------------------------------------------;
  188.     ;   Return to the caller.                                             ;
  189.     ;---------------------------------------------------------------------;
  190.     RET                        ; Return to caller
  191.  
  192. diff    ENDP
  193.  
  194.  
  195. ;-----------------------------------------------------------------------------;
  196. ;   Procedure to display the number in AX in decimal.                         ;
  197. ;-----------------------------------------------------------------------------;
  198.  
  199. display_result    PROC    NEAR
  200.  
  201.     LEA        DI, powers_of_ten
  202.     MOV        CX, 5
  203.  
  204. display_loop:
  205.  
  206.     XOR        DX, DX                ; Divide the number passed
  207.     DIV        WORD PTR [DI]            ; in AX by descending powers of ten
  208.     ADD        AL, '0'                ; Convert digit to ASCII
  209.  
  210.     PUSH        DX                ; Output the digit
  211.     MOV        DL, AL
  212.     MOV        AH, 02h
  213.     INT        21h
  214.     POP        AX
  215.  
  216.     ADD        DI, 2
  217.     LOOP        display_loop
  218.  
  219.     RET
  220.  
  221. display_result    ENDP
  222.  
  223.  
  224. PAGE
  225.  
  226. CODE    ENDS
  227.  
  228.  
  229. PAGE
  230. ;-----------------------------------------------------------------------------;
  231. ;         D A T A   S E G M E N T    F O R   T H E   O V E R L A Y            ;
  232. ;-----------------------------------------------------------------------------;
  233.  
  234. DATA    SEGMENT PARA PUBLIC 'DATA'
  235.  
  236.     executing_overlay_msg    DB    '.  .  Excuting code in expanded memory', cr, lf, '$'
  237.     sum_msg            DB    '.  .  Executing sum of numbers proc in expanded memory', cr, lf
  238.                 DB    '.  .     SUM = $'
  239.     diff_msg        DB    '.  .  Executing difference of numbers proc in expanded memory', cr, lf
  240.                 DB    '.  .     DIFFERENCE = $'
  241.     overlay_err_msg        DB    'Overlay cannot be executed via the command line$'
  242.     cr_lf_msg            DB    cr, lf, '$'
  243.  
  244.     powers_of_ten    DW    10000, 1000, 100, 10, 1
  245.  
  246. DATA ENDS
  247.  
  248. END    command_line_entry_point
  249.