home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
vol_300
/
355_01
/
slk1.exe
/
SHERLOCK
/
REGS.ASM
< prev
next >
Wrap
Assembly Source File
|
1988-04-14
|
2KB
|
101 lines
;
; Register Extractor
; Copy IBM machine registers into corresponding C language variables.
;
; source: regs.asm
; started: December 12, 1986
; version: December 12, 1986; April 14, 1988
;
; EXAMPLE:
;
; int flags, ip, ax, bx, cx, dx, sp, bp, si, di, cs, ds, ss, es;
; main(argc, argv)
; int argc, char **argv;
; {
; /* Set the variables flags, ip, ax, bx, etc. */
; sl_regs();
; printf("ax = %d\n", ax);
; }
;
;
; NOTE: Assemble this file with the Microsoft MASM assembler and
; link this file with the Microsoft or TURBO C linkers.
; Use the /MX and /ML options when assembling this file.
;
; NOTE: Use the /DNEAR option on the MASM command line when producing
; a .obj file to be used with memory models with small code
; space, namely the Microsoft small and compact models. Do NOT
; use the /DNEAR option when using the other memory models.
;
; WARNING! You must MAKE SURE that you change this code correctly
; reflects the memory model you are using in your C code.
; If you get this wrong, the code will die a quick death.
;
TITLE asmprofile
_TEXT SEGMENT BYTE PUBLIC 'CODE'
_TEXT ENDS
_DATA SEGMENT WORD PUBLIC 'DATA'
_DATA ENDS
CONST SEGMENT WORD PUBLIC 'CONST'
CONST ENDS
_BSS SEGMENT WORD PUBLIC 'BSS'
_BSS ENDS
DGROUP GROUP CONST, _BSS, _DATA
ASSUME CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
_DATA SEGMENT
EXTRN _ax:WORD, _bx:WORD, _cx:WORD, _dx:WORD
EXTRN _sp:WORD, _bp:WORD, _si:WORD, _di:WORD
EXTRN _ds:WORD, _cs:WORD, _ss:WORD, _es:WORD
EXTRN _ip:WORD, _flags:WORD
_DATA ENDS
_TEXT SEGMENT
PUBLIC _sl_regs
IFDEF NEAR
_sl_regs PROC NEAR
ELSE
_sl_regs PROC FAR
ENDIF
pushf ;save flags and ax
mov _ax,ax
pop ax ;flags
mov _flags,ax
pop ax
mov _ip,ax ;ip
push ax
mov ax,bx ;bx
mov _bx,ax
mov ax,cx ;cx
mov _cx,ax
mov ax,dx ;dx
mov _dx,ax
mov ax,sp ;sp
mov _sp,ax
mov ax,bp ;bp
mov _bp,ax
mov ax,si ;si
mov _si,ax
mov ax,di ;di
mov _di,ax
mov _ds,ds ;ds
mov _cs,cs ;cs
mov _ss,ss ;ss
mov _es,es ;es
mov ax,_flags ;restore flags and ax
push ax
mov ax,_ax
popf
ret
_sl_regs ENDP
_TEXT ENDS
END