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 >
Assembly Source File  |  1988-04-14  |  2KB  |  101 lines

  1. ;
  2. ;    Register Extractor
  3. ;    Copy IBM machine registers into corresponding C language variables.
  4. ;
  5. ;    source:  regs.asm
  6. ;    started: December 12, 1986
  7. ;    version: December 12, 1986; April 14, 1988
  8. ;
  9. ;    EXAMPLE:
  10. ;
  11. ;    int flags, ip, ax, bx, cx, dx, sp, bp, si, di, cs, ds, ss, es;
  12. ;    main(argc, argv)
  13. ;    int argc, char **argv;
  14. ;    {
  15. ;        /* Set the variables flags, ip, ax, bx, etc.  */
  16. ;        sl_regs();        
  17. ;        printf("ax = %d\n", ax);
  18. ;    }
  19. ;
  20. ;
  21. ;    NOTE:    Assemble this file with the Microsoft MASM assembler and
  22. ;        link this file with the Microsoft or TURBO C linkers.
  23. ;        Use the /MX and /ML options when assembling this file.
  24. ;
  25. ;    NOTE:   Use the /DNEAR option on the MASM command line when producing
  26. ;        a .obj file to be used with memory models with small code 
  27. ;        space, namely the Microsoft small and compact models.  Do NOT
  28. ;        use the /DNEAR option when using the other memory models.
  29. ;
  30. ;    WARNING!  You must MAKE SURE that you change this code correctly
  31. ;          reflects the memory model you are using in your C code.
  32. ;          If you get this wrong, the code will die a quick death.
  33. ;
  34.         TITLE    asmprofile
  35.  
  36. _TEXT        SEGMENT    BYTE PUBLIC 'CODE'
  37. _TEXT        ENDS
  38. _DATA        SEGMENT WORD PUBLIC 'DATA'
  39. _DATA        ENDS
  40. CONST        SEGMENT WORD PUBLIC 'CONST'
  41. CONST        ENDS
  42. _BSS        SEGMENT WORD PUBLIC 'BSS'
  43. _BSS        ENDS
  44.  
  45. DGROUP        GROUP    CONST, _BSS, _DATA
  46.         ASSUME CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
  47.  
  48. _DATA        SEGMENT
  49.         EXTRN _ax:WORD, _bx:WORD, _cx:WORD, _dx:WORD
  50.         EXTRN _sp:WORD, _bp:WORD, _si:WORD, _di:WORD
  51.         EXTRN _ds:WORD, _cs:WORD, _ss:WORD, _es:WORD
  52.         EXTRN _ip:WORD, _flags:WORD
  53. _DATA        ENDS
  54.  
  55. _TEXT        SEGMENT
  56.  
  57.         PUBLIC _sl_regs
  58. IFDEF NEAR
  59. _sl_regs    PROC NEAR
  60. ELSE
  61. _sl_regs    PROC FAR
  62. ENDIF
  63.  
  64.         pushf            ;save flags and ax
  65.         mov    _ax,ax
  66.  
  67.         pop    ax    ;flags
  68.         mov    _flags,ax
  69.         pop    ax
  70.         mov    _ip,ax    ;ip
  71.         push    ax
  72.  
  73.         mov    ax,bx    ;bx
  74.         mov    _bx,ax
  75.         mov    ax,cx    ;cx
  76.         mov    _cx,ax
  77.         mov    ax,dx    ;dx
  78.         mov    _dx,ax
  79.         mov    ax,sp    ;sp
  80.         mov    _sp,ax
  81.         mov    ax,bp    ;bp
  82.         mov    _bp,ax
  83.         mov    ax,si    ;si
  84.         mov    _si,ax
  85.         mov    ax,di    ;di
  86.         mov    _di,ax
  87.         mov    _ds,ds    ;ds
  88.         mov    _cs,cs    ;cs
  89.         mov    _ss,ss    ;ss
  90.         mov    _es,es    ;es
  91.  
  92.         mov    ax,_flags    ;restore flags and ax
  93.         push    ax
  94.         mov    ax,_ax
  95.         popf
  96.         ret
  97.  
  98. _sl_regs    ENDP
  99. _TEXT        ENDS
  100.         END
  101.