-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathERRC.ASM
124 lines (90 loc) · 1.92 KB
/
ERRC.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
; *******************************************************
; * *
; * Turbo Pascal Runtime Library *
; * Error Check Routines *
; * *
; * Copyright (C) 1988,90 Borland International *
; * *
; *******************************************************
TITLE ERRC
INCLUDE SE.ASM
DATA SEGMENT WORD PUBLIC
; Externals
EXTRN InOutRes:WORD
IF NOT WindowsVersion AND NOT DPMIVersion
EXTRN StackLimit:WORD
ENDIF
DATA ENDS
CODE SEGMENT BYTE PUBLIC
ASSUME CS:CODE,DS:DATA
; Externals
EXTRN HaltError:NEAR
; Publics
PUBLIC GetIORes,InOutCheck,RangeCheck,StackCheck
PUBLIC Overflow,RangeError
; IOResult standard function. May modify only AX.
GetIORes:
XOR AX,AX
XCHG AX,InOutRes
RETF
; Check I/O result. Called after any I/O standard routine in
; the {$I+} state. May modify no registers.
InOutCheck:
CMP InOutRes,0
JNE @@1
RETF
@@1: MOV AX,InOutRes
JMP HaltError
; Check range of integer value. Called to validate integer values
; in the {$R+} state. DX:AX contains value, and DI contains pointer
; to range data in callers code segment. May modify SI, DI, and ES.
RangeCheck:
MOV SI,SP
MOV ES,SS:[SI+2]
CMP DX,ES:[DI+2]
JG @@1
JL RangeError
CMP AX,ES:[DI]
JB RangeError
@@1: CMP DX,ES:[DI+6]
JL @@2
JG RangeError
CMP AX,ES:[DI+4]
JA RangeError
@@2: RETF
; Range check error
RangeError:
MOV AX,201
JMP HaltError
; Overflow error
Overflow:
MOV AX,215
JMP HaltError
; Check for stack overflow. Called on entry to any procedure or
; function compiled in the {$S+} state. AX contains number of
; bytes to allocate. May modify only AX.
StackCheck:
IF WindowsVersion
ADD AX,1024
ELSE
ADD AX,512
ENDIF
JC @@2
SUB AX,SP
JAE @@2
NEG AX
IF WindowsVersion OR DPMIVersion
CMP AX,SS:pStackTop
JB @@2
CMP AX,SS:pStackMin
JAE @@1
MOV SS:pStackMin,AX
ELSE
CMP AX,StackLimit
JB @@2
ENDIF
@@1: RETF
@@2: MOV AX,202
JMP HaltError
CODE ENDS
END