Subversion Repositories SvarDOS

Rev

Rev 1558 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1556 mateusz.vi 1
.8086
2
 
3
STACK_SIZE = 2048
4
 
5
      dgroup group _TEXT,_DATA,CONST,CONST2,_STACK,_BSS
6
 
7
      extrn   "C",main : near
8
 
9
;      public _cstart_, _small_code_, __STK
10
      public _cstart_, _small_code_
11
 
12
_TEXT segment word public 'CODE'
13
      org   100h
14
 
15
_small_code_ label near
16
 
17
_cstart_:
18
 
19
      ; DOS puts the COM program in the largest memory block it can find
20
      ; and sets SP to the end of this block. On top of that, it reserves
21
      ; the entire memory (not only the process' block) to the program, which
22
      ; makes it impossible to allocate memory or run child processes.
23
      ; for this reasons it is beneficial to resize the memory block we occupy
24
      ; into a more reasonable value
25
 
26
      ; step 1: if SP is higher than my top_of_stack, then set SP explicitely
27
      cmp sp, top_of_stack
28
      jle resizemem
29
      mov sp, top_of_stack
30
 
31
      ; step 2: resize our memory block to sp bytes (ie. sp/16 paragraphs)
32
    resizemem:
33
      mov ah, 4ah
34
      mov bx, sp
35
      shr bx, 1
36
      shr bx, 1
37
      shr bx, 1
38
      shr bx, 1
39
      inc bx
40
      int 21h
41
 
42
      call  main
43
      mov   ah, 4ch
44
      int   21h
45
 
46
; Stack overflow checking routine is absent. Remember to compile your
47
; programs with the -s option to avoid referencing __STK
48
;__STK:
49
;      ret
50
 
51
_DATA   segment word public 'DATA'
52
_DATA   ends
53
 
54
CONST   segment word public 'DATA'
55
CONST   ends
56
 
57
CONST2  segment word public 'DATA'
58
CONST2  ends
59
 
60
_BSS    segment word public 'BSS'
61
_BSS    ends
62
 
63
_STACK  segment para public 'BSS'
64
        db      (STACK_SIZE) dup(0) ; set this explicitely to zero, otherwise
65
                                    ; static variables are not properly
66
                                    ; initialized. this makes the COM file
67
                                    ; much bigger, but it is irrelevant if it
68
                                    ; is UPXed afterwards anyway. If you care,
69
                                    ; then you may zero out this area in
70
                                    ; code instead (before calling main)
71
        top_of_stack:
72
_STACK  ends
73
 
74
_TEXT ends
75
 
76
      end _cstart_