Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
char
;
ss offset
;
ented (16 bit)
;
frame1
saveflags1
savedi1
savesi1
saveds1
savebp1
saveret1
argone1
frame1
offone1
segone1
;
;
;
;
;
;
r)
;
char
;
ss offset
;
ented (16 bit)
;
frame2
saveflags2
savedi2
savesi2
saveds2
savebp2
saveret2
argtwo2
argone2
frame2
offtwo2
segtwo2
offone2
segone2
;
;
;
;
;
;
r)
;
char
;
ss offset
;
ented (16 bit)
;
frame3
?
?
?
?
?
?
?
argone1
argone1 + 2
?
?
?
?
?
?
?
?
argtwo2
argtwo2 + 2
argone2
argone2 + 2
saveflags3
savedi3
savesi3
saveds3
savebp3
saveret3
argthree3
argtwo3
argone3
frame3
offthree3
segthree3
offtwo3
segtwo3
offone3
segone3
;
;
;
;
;
;
r)
;
char
;
ss offset
;
ented (16 bit)
;
frame4
saveflags4
savedi4
savesi4
saveds4
savebp4
saveret4
argfour4
argthree4
argtwo4
argone4
frame4
offfour4
segfour4
offthree4
segthree4
offtwo4
segtwo4
offone4
segone4
;
;
;
;
;
;
r)
;
char
;
dw
dw
dw
dw
dw
dd
dd
dd
dd
ends
equ
equ
equ
equ
equ
equ
?
?
?
?
?
?
?
?
?
argthree3
argthree3 + 2
argtwo3
argtwo3 + 2
argone3
argone3 + 2
?
?
?
?
?
?
?
?
?
?
argfour4
argfour4 + 2
argthree4
argthree4 + 2
argtwo4
argtwo4 + 2
argone4
argone4 + 2
ss offset
;
ented (16 bit)
;
frame5
saveflags5
savedi5
savesi5
saveds5
savebp5
saveret5
argfive5
argfour5
argthree5
argtwo5
argone5
frame5
offfive5
segfive5
offfour5
segfour5
offthree5
segthree5
offtwo5
segtwo5
offone5
segone5
;
;
;
;
;
;
r)
;
char
;
ss offset
;
ented (16 bit)
;
frame6
saveflags6
savedi6
savesi6
saveds6
savebp6
saveret6
argsix6
argfive6
argfour6
argthree6
argtwo6
argone6
frame6
offsix6
segsix6
offfive6
segfive6
offfour6
?
?
?
?
?
?
?
?
?
?
?
argfive5
argfive5 + 2
argfour5
argfour5 + 2
argthree5
argthree5 + 2
argtwo5
argtwo5 + 2
argone5
argone5 + 2
?
?
?
?
?
?
?
?
?
?
?
?
argsix6
argsix6 + 2
argfive6
argfive6 + 2
argfour6
segfour6
offthree6
segthree6
offtwo6
segtwo6
offone6
segone6
;
;
;
;
;
;
r)
;
char
;
ss offset
;
ented (16 bit)
;
frame7
saveflags7
savedi7
savesi7
saveds7
savebp7
saveret7
argseven7
argsix7
argfive7
argfour7
argthree7
argtwo7
argone7
frame7
offseven7
segseven7
offsix7
segsix7
offfive7
segfive7
offfour7
segfour7
offthree7
segthree7
offtwo7
segtwo7
offone7
segone7
;
;
;
;
;
;
r)
;
char
;
equ
equ
equ
equ
equ
equ
equ
argfour6 + 2
argthree6
argthree6 + 2
argtwo6
argtwo6 + 2
argone6
argone6 + 2
?
?
?
?
?
?
?
?
?
?
?
?
?
argseven7
argseven7 + 2
argsix7
argsix7 + 2
argfive7
argfive7 + 2
argfour7
argfour7 + 2
argthree7
argthree7 + 2
argtwo7
argtwo7 + 2
argone7
argone7 + 2
ss offset
;
ented (16 bit)
;
frame8
saveflags8
savedi8
savesi8
saveds8
savebp8
saveret8
argeight8
argseven8
argsix8
argfive8
argfour8
argthree8
argtwo8
argone8
frame8
offeight8
segeight8
offseven8
segseven8
offsix8
segsix8
offfive8
segfive8
offfour8
segfour8
offthree8
segthree8
offtwo8
segtwo8
offone8
segone8
;
;
;
;
;
;
r)
;
char
;
ss offset
;
ented (16 bit)
;
frame9
saveflags9
savedi9
savesi9
saveds9
savebp9
saveret9
argnine9
argeight9
argseven9
?
?
?
?
?
?
?
?
?
?
?
?
?
?
argeight8
argeight8 + 2
argseven8
argseven8 + 2
argsix8
argsix8 + 2
argfive8
argfive8 + 2
argfour8
argfour8 + 2
argthree8
argthree8 + 2
argtwo8
argtwo8 + 2
argone8
argone8 + 2
?
?
?
?
?
?
?
?
?
argsix9
dd
?
;address of sixth operand
argfive9
dd
?
;address of fifth operand
argfour9
dd
?
;address of fourth operand
argthree9
dd
?
;address of third operand
argtwo9
dd
?
;address of second operand
argone9
dd
?
;first operand's address
frame9
ends
offnine9
equ
argnine9
segnine9
equ
argnine9 + 2
offeight9
equ
argeight9
segeight9
equ
argeight9 + 2
offseven9
equ
argseven9
segseven9
equ
argseven9 + 2
offsix9
equ
argsix9
segsix9
equ
argsix9 + 2
offfive9
equ
argfive9
segfive9
equ
argfive9 + 2
offfour9
equ
argfour9
segfour9
equ
argfour9 + 2
offthree9
equ
argthree9
segthree9
equ
argthree9 + 2
offtwo9
equ
argtwo9
segtwo9
equ
argtwo9 + 2
offone9
equ
argone9
segone9
equ
argone9 + 2
;
;
; TYPE 2 - float or non-trivial return value
;
;!on return the retval offset must be in AX and the restored DS value in DX !
;
; MS FORTRAN/MS Pascal return convention for REAL*4 REAL*8 and with MS C for
; STRUCTs, RECORDS &c (MS C floats and doubles are returned in global __fac
; but then SEG:OFF of __fac must be in DX:AX as here)
;
; CALLER allocates storage for return value in DGROUP segment(s) (DS on entry)
; and pushes offset before pushing addresses of args (all frames here based on
; large model, pass by reference (FORTRAN default, Pascal with VARS))
; to return value copy to return value location AND RETURN WITH SEGMENT:OFFSET
; OF RETURN VALUE LOCATION IN DX:AX !!!!! (w/o this last caller goes to flooby
; space and gets garbage)
;
; IBM FORTRAN v1 and v2, IBM Pascal v1 and v2 use essentially same conventions
;
; Borland C uses something like this for 3 byte and 5 or larger byte structs
; Borland C returns all 1 byte values in AL, 2 bytes in AX, and 4 bytes in DX:A
X
; except floats; floats, doubles and long doubles are returned on 8087 ST(0) st
ack top
;
;
;
frame struc for no arg subroutine
;
FORTRAN/Pascal external procedure calling convention
;
complex return value (struct, record, float or double)
;
caller has allocated space for retval in DS and pushed offset
;
before CALLing routine
;
sframe0
struc
;frame for stack access
savedflags0
dw
?
;save area for caller's flags
saveddi0
dw
?
;save area for caller's di
savedsi0
savedds0
savedbp0
savedret0
retvaloffs0
sframe0
;
;
;
;
;
;
;
;
;
sframe1
savedflags1
saveddi1
savedsi1
savedds1
savedbp1
savedret1
retvaloffs1
argsone1
sframe1
offsone1
segsone1
;
;
;
;
;
;
;
;
;
sframe2
savedflags2
saveddi2
savedsi2
savedds2
savedbp2
savedret2
retvaloffs2
argstwo2
argsone2
sframe2
offstwo2
segstwo2
offsone2
segsone2
;
;
;
;
;
;
;
;
;
dw
dw
dw
dd
dw
ends
?
?
?
?
?
?
?
?
?
?
?
?
?
argsone1
argsone1 + 2
?
?
?
?
?
?
?
?
?
argstwo2
argstwo2 + 2
argsone2
argsone2 + 2
sframe3
savedflags3
saveddi3
savedsi3
savedds3
savedbp3
savedret3
retvaloffs3
argsthree3
argstwo3
argsone3
sframe3
offsthree3
segsthree3
offstwo3
segstwo3
offsone3
segsone3
;
;
;
;
;
;
;
;
;
sframe4
savedflags4
saveddi4
savedsi4
savedds4
savedbp4
savedret4
retvaloffs4
argsfour4
argsthree4
argstwo4
argsone4
sframe4
offsfour4
segsfour4
offsthree4
segsthree4
offstwo4
segstwo4
offsone4
segsone4
;
;
;
;
;
;
;
;
;
sframe5
savedflags5
saveddi5
struc
dw
dw
dw
dw
dw
dd
dw
dd
dd
dd
ends
equ
equ
equ
equ
equ
equ
?
?
?
?
?
?
?
?
?
?
argsthree3
argsthree3 + 2
argstwo3
argstwo3 + 2
argsone3
argsone3 + 2
?
?
?
?
?
?
?
?
?
?
?
argsfour4
argsfour4 + 2
argsthree4
argsthree4 + 2
argstwo4
argstwo4 + 2
argsone4
argsone4 + 2
?
?
savedsi5
savedds5
savedbp5
savedret5
retvaloffs5
argsfive5
argsfour5
argsthree5
argstwo5
argsone5
sframe5
offsfive5
segsfive5
offsfour5
segsfour5
offsthree5
segsthree5
offstwo5
segstwo5
offsone5
segsone5
;
;
;
;
;
;
;
;
;
sframe6
savedflags6
saveddi6
savedsi6
savedds6
savedbp6
savedret6
retvaloffs6
argssix6
argsfive6
argsfour6
argsthree6
argstwo6
argsone6
sframe6
offssix6
segssix6
offsfive6
segsfive6
offsfour6
segsfour6
offsthree6
segsthree6
offstwo6
segstwo6
offsone6
segsone6
;
;
;
dw
dw
dw
dd
dw
dd
dd
dd
dd
dd
ends
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
?
?
?
?
?
?
?
?
?
?
argsfive5
argsfive5 + 2
argsfour5
argsfour5 + 2
argsthree5
argsthree5 + 2
argstwo5
argstwo5 + 2
argsone5
argsone5 + 2
?
?
?
?
?
?
?
?
?
?
?
?
?
argssix6
argssix6 + 2
argsfive6
argsfive6 + 2
argsfour6
argsfour6 + 2
argsthree6
argsthree6 + 2
argstwo6
argstwo6 + 2
argsone6
argsone6 + 2
;
;
;
;
;
;
sframe7
savedflags7
saveddi7
savedsi7
savedds7
savedbp7
savedret7
retvaloffs7
argsseven7
argssix7
argsfive7
argsfour7
argsthree7
argstwo7
argsone7
sframe7
offsseven7
segsseven7
offssix7
segssix7
offsfive7
segsfive7
offsfour7
segsfour7
offsthree7
segsthree7
offstwo7
segstwo7
offsone7
segsone7
;
;
;
;
;
;
;
;
;
sframe8
savedflags8
saveddi8
savedsi8
savedds8
savedbp8
savedret8
retvaloffs8
argseight8
argsseven8
argssix8
argsfive8
argsfour8
argsthree8
argstwo8
?
?
?
?
?
?
?
?
?
?
?
?
?
?
argsseven7
argsseven7 + 2
argssix7
argssix7 + 2
argsfive7
argsfive7 + 2
argsfour7
argsfour7 + 2
argsthree7
argsthree7 + 2
argstwo7
argstwo7 + 2
argsone7
argsone7 + 2
?
?
?
?
?
?
?
?
?
?
?
?
?
?
argsone8
sframe8
offseight8
segseight8
offsseven8
segsseven8
offssix8
segssix8
offsfive8
segsfive8
offsfour8
segsfour8
offsthree8
segsthree8
offstwo8
segstwo8
offsone8
segsone8
;
;
;
;
;
;
;
;
;
sframe9
savedflags9
saveddi9
savedsi9
savedds9
savedbp9
savedret9
retvaloffs9
argsnine9
argseight9
argsseven9
argssix9
argsfive9
argsfour9
argsthree9
argstwo9
argsone9
sframe9
offsnine9
segsnine9
offseight9
segseight9
offsseven9
segsseven9
offssix9
segssix9
offsfive9
segsfive9
offsfour9
segsfour9
offsthree9
segsthree9
offstwo9
dd
ends
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
argseight8
argseight8 + 2
argsseven8
argsseven8 + 2
argssix8
argssix8 + 2
argsfive8
argsfive8 + 2
argsfour8
argsfour8 + 2
argsthree8
argsthree8 + 2
argstwo8
argstwo8 + 2
argsone8
argsone8 + 2
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
argsnine9
argsnine9 + 2
argseight9
argseight9 + 2
argsseven9
argsseven9 + 2
argssix9
argssix9 + 2
argsfive9
argsfive9 + 2
argsfour9
argsfour9 + 2
argsthree9
argsthree9 + 2
argstwo9
segstwo9
equ
argstwo9 + 2
offsone9
equ
argsone9
segsone9
equ
argsone9 + 2
;
;
;
; NB - if modifications are made to the save/restore macros the frame
;
definitions above must be modified to match
save
macro
push bp
;IBM FORTRAN v1.0,2.0 IBM Pascal v1.0,2.0 & MicroSoft
push ds
;versions 3.x, 4.x, 5.x require preservation of BP & DS
push si
;Some versions of MS C require preservation of SI, DI
push di
pushf
;some versions of MS C, FORTRAN require preservation of
mov bp,sp ;establishes stack frame pointing to saved flags
cld
; direction flag
endm
restore macro
;
mov sp,bp ;restore stack frame from local storage allocation
;
;this is commented out because it is unnecessary ;
;no local storage is allocated
popf
;some versions of MS C, FORTRAN require preservation of
pop di
; direction flag, some require preservation of SI, DI
pop si
; almost all require preservation of DS
pop ds
;IBM FORTRAN v1.0,2.0 IBM Pascal v1.0,2.0 & MicroSoft
pop bp
;versions 3.x, 4.x, 5.x require preservation of BP & DS
endm
ksave macro
push bp
;IBM FORTRAN v1.0,2.0 IBM Pascal v1.0,2.0 & MicroSoft
push ds
;versions 3.x, 4.x, 5.x require preservation of BP & DS
push si
;Some versions of MS C require preservation of SI, DI
push di
pushf
;some versions of MS C, FORTRAN require preservation of
mov bp,sp ;establishes stack frame pointing to saved flags
cld
; direction flag
endm
krestore macro
;
mov sp,bp ;restore stack frame from local storage allocation
;
;this is commented out because it is unnecessary ;
;no local storage is allocated
popf
;some versions of MS C, FORTRAN require preservation of
pop di
; direction flag, some require preservation of SI, DI
pop si
; almost all require preservation of DS
pop ds
;IBM FORTRAN v1.0,2.0 IBM Pascal v1.0,2.0 & MicroSoft
pop bp
;versions 3.x, 4.x, 5.x require preservation of BP & DS
endm
save16 macro
push bp
;IBM FORTRAN v1.0,2.0 IBM Pascal v1.0,2.0 & MicroSoft
push ds
;versions 3.x, 4.x, 5.x require preservation of BP & DS
push si
;Some versions of MS C require preservation of SI, DI
push di
pushf
;some versions of MS C, FORTRAN require preservation of
mov bp,sp ;establishes stack frame pointing to saved flags
cld
; direction flag
endm
restore16 macro
;
mov sp,bp ;restore stack frame from local storage allocation
;
;this is commented out because it is unnecessary ;
;no local storage is allocated
popf
;some versions of MS C, FORTRAN require preservation of
pop di
pop si
pop ds
pop bp
endm
;
;
RET_FAR MACRO
DB
ENDM
;
RET_FAR_POP
DB
DW
ENDM
;
RET_NEAR
DB
ENDM
;
RET_NEAR_POP
DB
DW
ENDM
;
SRET
MACRO
IFB
0CBH
MACRO
0CAH
X
MACRO
0C3H
MACRO
0C2H
X
X
<X>
DB
0C3H
DB
DW
0C2H
X
X
<X>
DB
0C3H
DB
DW
0C2H
X
X
<X>
DB
0CBH
DB
DW
0CAH
X
X
<X>
DB
0CBH
DB
DW
0CAH
X
ELSE
ENDIF
ENDM
;
NRET
MACRO
IFB
ELSE
ENDIF
ENDM
;
LRET
MACRO
IFB
ELSE
ENDIF
ENDM
;
FRET
MACRO
IFB
ELSE
ENDIF
ENDM
;
;
;
;*******************header ******************************
;
;code header macro defined here
;
header
macro
;
;
DATA
segment
WORD PUBLIC 'DATA' USE16
DATA
ends
_DATA SEGMENT WORD PUBLIC 'DATA' USE16
_DATA ENDS
CONST SEGMENT WORD PUBLIC 'CONST' USE16
SEG_FAC DW SEG __fac
CONST ENDS
_BSS
SEGMENT WORD PUBLIC 'BSS' USE16
_BSS
ENDS
DGROUP GROUP
EXTRN
__fac:QWORD
;C7 OR LATER
EXTRN __fltused:ABS
;C6 OR EARLIER
;EXTRN __fltused:NEAR
;
code
segment
assume
;
;
endm
;
wswapeax
macro
xchg
db
xchg
endm
;
wswapebx
macro
xchg
db
xchg
endm
;
wswapecx
macro
xchg
db
xchg
endm
;
wswapedx
macro
xchg
db
xchg
endm
;
wswapesi
macro
; bswap
eax
bl,bh
066h,00Fh,0CBh
bl,bh
;wswapebx
; bswap
ebx
cl,ch
066h,00Fh,0C9h
cl,ch
;wswapecx
; bswap
ecx
dl,dh
066h,00Fh,0CAh
dl,dh
;wswapedx
; bswap
edx
;
wswapedi
;
wswapebp
;
;
.list
xchg
xchg
db
xchg
xchg
endm
ax,si
al,ah
066h,00Fh,0C8h
al,ah
ax,si
;wswapesi
; bswap
eax
macro
xchg
xchg
db
xchg
xchg
endm
ax,di
al,ah
066h,00Fh,0C8h
al,ah
ax,di
;wswapedi
; bswap
eax
macro
xchg
xchg
db
xchg
xchg
endm
ax,bp
al,ah
066h,00Fh,0C8h
al,ah
ax,bp
;wswapebp
; bswap
eax