Microsoft C: Getting The DS & SS For A Module

Larry Backman backman at interlan.UUCP
Wed Jan 7 23:30:44 AEST 1987


In article <1273 at kontron.UUCP> cramer at kontron.UUCP (Clayton Cramer) writes:
>I'm writing a program using Microsoft C and MASM which installs a new
>interrupt 17 ISR.  The new ISR calls a C function.  How do I get the
>DS and SS values for the C function to set before calling the C function?
>

	I've solved this problem before by calling an assembly function
	from the C module sometime during program initialization.  The
	assembly function copies both the DS and SS into variables located
	in its code segment.  Then when the ISR is invoked, it replaces
	the existing DS and SS values with the values aaved in code segment.
	For example:

	CODE SEGMENT

	save_ds		dw	?
	save_ss		dw	?

	post_init	proc 	far

	
		push	ax	
		mov	ax,ds	
		mov	cs:save_ds,ax

		mov	ax,ss
		mov	cs:save_ss,ax
		pop	ax
		
		retf
	post_init	endp	

	something_isr	proc	far

		... save registers ...
		mov	ax,cs:save_ds
		mov	ds,ax

		mov	ax,cs:save_ss
		mov	ss,ax

		....call C with correct segments

		....
		iret
	something_isr	proc	far

	A word of warning - Make sure that interrupts are off when you start
	playing with DS and SS!


			Larry Backman\
			Micom - Interlan Inc
			155 Swanson Rd.
			Boxborough Ma, 01719
			617-263-9929  x291

			ulowell  
			mit-eddie      !interlan!backman



More information about the Comp.lang.c mailing list