home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 171_01 / cc.asm < prev    next >
Assembly Source File  |  1983-10-30  |  4KB  |  130 lines

  1. PAGE 64,132
  2. TITLE C -- DOS 2.0 version for Lattice 'C'  07/12/83
  3. ; name        XCMAIN -- initiate execution of C program
  4. ;
  5. ; description    This is the main module for a C program on the
  6. ;        MS-DOS implementation.    It initializes the segment
  7. ;        registers, sets up the stack, and calls the C main
  8. ;        function _main with a pointer to the remainder of
  9. ;        the command line.
  10. ;
  11. ;        Also defined in this module is the exit entry point
  12. ;        XCEXIT.
  13. ;
  14. ;            Ted Reuss     c/o South Texas Software, Inc.
  15. ;          Home: 713/961-3926      4544 Post Oak Place, Suite 176
  16. ;          Offi: 713/877-8205      Houston, Tx 77027
  17. ;
  18. pgroup    group    base,prog
  19. dgroup    group    data,stack
  20. ;
  21. ; The following segment serves only to force "pgroup" lower in
  22. ; memory.  It also contains the Lattice C revision number.
  23. ;
  24. base    segment 'prog'
  25.     db    "Lattice C 1.04"
  26. base    ends
  27. ;
  28. ; The data segment defines locations which contain the offsets
  29. ; of the base and top of the stack.
  30. ;
  31. data    segment byte public 'data'
  32.     public    _top, _base
  33. _top    dw    0
  34. _base    dw    0
  35. data    ends
  36. ;
  37. ; The stack segment is included to prevent the warning from the
  38. ; linker, and also to define the base (lowest address) of the stack.
  39. ;
  40. stack    segment stack 'data'
  41. sbase    dw    128 dup (?)
  42. stack    ends
  43. ;
  44. ; The main program must set up the initial segment registers
  45. ; and the stack pointer, and free memory via function call(4A).
  46. ; The command line bytes from the program segment prefix are
  47. ; moved onto the stack, and a pointer to them supplied to the
  48. ; C main module _main (which calls main).
  49. ;
  50. prog    segment byte public 'prog'
  51.     public    XCMAIN, XCEXIT
  52.     extrn    _main:near
  53.     assume    cs:pgroup, ds:dgroup, ss:dgroup
  54. XCMAIN    proc    far
  55.     cli            ;disable interrupts
  56.     mov    ax,dgroup
  57.     mov    ds,ax        ;initialize ds and ss
  58.     mov    ss,ax
  59.     mov    bx,es:2     ;total memory size (paragraphs)
  60.     sub    bx,ax
  61.     test    bx,0f000h
  62.     jnz    m1        ;branch if more than 64K bytes
  63.     mov    cl,4
  64.     shl    bx,cl        ;highest available byte
  65.     jmp    short m2
  66. m1:    mov    bx,0fff0h
  67. m2:    mov    sp,bx        ;set stack pointer
  68.     sti            ;enable interrupts
  69.     mov    _top,bx     ;save top of stack
  70.     mov    ax,offset dgroup:sbase
  71.     mov    _base,ax    ;store ptr to bottom of stack
  72.     push    es        ;push ptr to pgm segment prefix
  73.     xor    ax,ax
  74.     push    ax        ;instr ptr for far return
  75.     mov    bp,sp        ;save in bp
  76.     mov    si,80h        ;ptr to command line bytes
  77.     mov    cl,es:[si]    ;get number of bytes
  78.     inc    si
  79.     xor    ch,ch        ;clear high byte
  80.     mov    bx,cx
  81.     add    bx,4        ;3 bytes additional, 1 for rounding
  82.     and    bx,0fffeh    ;force even number of bytes
  83.     sub    sp,bx        ;allocate space on stack
  84.     mov    di,sp
  85.     mov    byte ptr [di],'c'       ;store dummy program name
  86.     inc    di
  87.     jcxz    m4        ;skip if no bytes to move
  88.     mov    byte ptr [di],' '
  89.     inc    di
  90. m3:    mov    al,es:[si]    ;move bytes to stack
  91.     mov    [di],al
  92.     inc    si
  93.     inc    di
  94.     loop    m3
  95. m4:    xor    ax,ax
  96.     mov    [di],al     ;store null byte
  97.     mov    bx,ds        ;set up es:bx with
  98.     mov    ax,es        ; the # paragraphs
  99.     sub    bx,ax        ; required and tell
  100.     add    bx,1000h    ; DOS.
  101.     mov    ah,4ah        ;DOS SETBLOCK
  102.     int    21h
  103.     mov    ax,ds
  104.     mov    es,ax        ;es, ds, and ss are all equal
  105.     mov    ax,sp
  106.     push    ax        ;ptr to command line
  107.     call    _main        ;call C main
  108.     xor    al,al
  109.     jmp    short XCE10    ;exit to DOS
  110. XCMAIN    endp
  111. ;
  112. ; name        XCEXIT -- terminate execution of C program
  113. ;
  114. ; description    This function terminates execution of the current
  115. ;        program by returning to MS-DOS.  The error code
  116. ;        argument is passed to MS-DOS via function call(4C)
  117. ;
  118. XCEXIT    proc    near
  119.     mov    bp,sp
  120.     mov    ax,[bp+2]    ;get error code
  121. XCE10:    mov    ah,4ch        ;DOS exit
  122.     int    21h
  123. here:    jmp    short here    ;should never get here
  124. XCEXIT    endp
  125. prog    ends
  126.     end    XCMAIN
  127. ode
  128. XCE10:    mov    ah,4ch        ;DOS exit
  129.     int    21h
  130. here