example2.c

来自「XLIB 2.0版 32位应用程序开发 ASM/C语言的DOS 扩展库」· C语言 代码 · 共 50 行

C
50
字号
#include <stdio.h>
#include <xlib.h>
#define som _emit 0x66               /* switch operand mode */
#define sam _emit 0x67               /* switch address mode */
long __far getextmem(long address);

int goterr = 0;                      /* error flag */

main()
{
  long l;
  l = INITXLIB();                    /* initialize XLIB */
  if(l != 0)
  {
    printf("Library initialization error:  %lX",l);
    return 0;
  }
  l = getextmem(0x100000);           /* read first address in 2ond meg */
  if(goterr != 0)
  {
    printf("Inline mode-switch error:  %lX",l);
    return 0;
  }
  printf("%lX\n",l);
}

long __far getextmem(long address)
{
  __asm
  {
    som                             ;mov  eax,[bp+6]
    mov       ax,[bp+6]             ;  ""
    call      INLINEPM
    jc        error                 ;Error code in ax
    mov       ds,es:FLATDSEL
    sam                             ;push dword ptr [eax]
    som                             ;  ""
    _emit     0ffh                  ;  ""
    _emit     030h                  ;  ""
    pop       ax
    pop       dx
    call      es:INLINERMPTR
    jmp       done
error:
    xor       dx,dx                 ;Return error code in dx:ax
    inc       goterr
done:
  }
}

⌨️ 快捷键说明

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