⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crt0r.asm

📁 Embedded magazine source code. this is the source code in the year 1989
💻 ASM
字号:
	page	,132
	TITLE	crt0r - ROMABLE Microsoft C start up routine
INCLUDE MODEL.INC
;-------------------------------------------------------
;  Assemble with the "/Mx" switch.
;  Link with the "/DOSSEG" linker switch.
;-------------------------------------------------------
public	__acrtused 		; This symbol "extrn"-ed by Compiler,
	__acrtused = 9876h	; ...so linker will look for it.
extrn	_end:byte		; end of BSS, start of stack.

_TEXT	SEGMENT  WORD PUBLIC 'CODE'
_TEXT	ENDS
C_ETEXT	SEGMENT  PARA PUBLIC 'ENDCODE'
	db	16 dup(?)		; EXE2ROM puts initial SP here.
C_ETEXT	ENDS
CDATA	SEGMENT  WORD COMMON 'DATA'
CDATA	ENDS
_DATA	SEGMENT  WORD PUBLIC 'DATA'
_DATA	ENDS

XIB	SEGMENT  WORD PUBLIC 'DATA'
xibegin	label	byte
XIB	ENDS
XI	SEGMENT  WORD PUBLIC 'DATA'
XI	ENDS
XIE	SEGMENT  WORD PUBLIC 'DATA'
xiend	label	byte
XIE	ENDS

STACK	SEGMENT  PARA STACK 'STACK'	; Dummy Stack, not really used.
STACK	ENDS

DGROUP GROUP CDATA,_DATA,STACK,XIB,XI,XIE
	ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP

EXTERNPROC _main
extrn __fptrap:near

_DATA	SEGMENT
	public __fac,_errno
__fac	dq	0		; floating accumulator
_errno	dw	0		; initial error code
_DATA	ENDS

CDATA	SEGMENT			; floating point setup segment
	PUBLIC	_fpinit
	dw	0
_fpinit	label	dword
fpmath	dd	1 dup (?)
fpdata	dd	1 dup (?)
fpsignal dd	1 dup (?)
CDATA	ENDS

_TEXT	SEGMENT
;****************************************
;  ColdStart     ( FFFF:0000 points here )
;****************************************

ColdStart proc far
	cli
	cld
	mov	ax,SEG DGROUP
	mov	ss,ax		; SS = DGROUP
	mov	ds,ax		; DS = DGROUP
	mov	ax,SEG C_ETEXT
	mov	es,ax		; ES = C_ETEXT
	mov	sp,word ptr es:[0]	; EXE2ROM supplies SP here
	call	_datainit	; Set up initialized Data
	call	_cinit		; Do special "C" inits
	call	_main		; ** Go to the Application !!! **
	jmp	short ColdStart	; (in case _main returns)
ColdStart	endp

_datainit	proc	near
	push	ds
	pop	es		; ES = DS
	mov	di,0		; es:[di] is beginning of RAM data segment
;---------------------------------------
;  Pre-clear the data area from es:0 to es:(offset DGROUP:_end)
;  This includes both _DATA and _BSS.
;---------------------------------------
	mov	cx,offset DGROUP: _end
	xor	ax,ax
	rep	stosb
	mov	ax,SEG C_ETEXT
	inc	ax		; ax = SEG of crunched data table
	mov	es,ax
	mov	si,0		; es:[si] is top of initialized data table
;--------------------------------------
;  The ROM table of initialized data has the following format:
;	word	<N=count of words in this block.  0=end of list>
;	word	<offset (into DS) where this block goes>
;	word....word	<N words that comprise the block>
;--------------------------------------
datainit0:
	mov	cx,es:[si]	; get a word count
	add	si,2
	jcxz	datainit_done
	mov	bx,es:[si]	; get offset of block destination
	add	si,2
datainit2:
	mov	ax,es:[si]	; fetch a data word of the block
	mov	[bx],ax		; place it in RAM
	add	si,2
	add	bx,2
	loop	datainit2	; do it CX times
	jmp	short datainit0	; on to the next block
datainit_done:
	push	ss
	pop	es
	ret
_datainit	endp

_cinit	proc	near
	mov	cx,word ptr [fpmath+2]	; ..if floating point used,
	jcxz	nofloat_i		; ..set up floating pt. stack.

	lds	ax,[fpdata]	; get task data area
	assume	ds:nothing
	mov	dx,ds		;   into dx:ax
	xor	bx,bx
	call	[fpmath]	; fpmath(0) - init
	jnc	fpok
	push	ss		; restore ds from ss
	pop	ds
	jmp	__fptrap
fpok:
	lds	ax,[fpsignal]	; get signal address
	assume	ds:nothing
	mov	dx,ds
	mov	bx,3
	call	[fpmath]	; fpmath(3) - set signal address
	push	ss
	pop	ds
	assume	ds:DGROUP
nofloat_i:
	ret
_cinit	endp

_TEXT	ENDS
	end	ColdStart

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -