0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

DPMI32でCコード

Last updated at Posted at 2021-06-24

DPMIで32ビットに移行した後にCのコードを引っ付けてみました。

16bitの処理は前と同じです。

32bitのアセンブラを以下のようにします。

;--- this is a 32bit DPMI application.

    .386
    .model small

    .dosseg    ;ensures that segments are ordered: code

    .code
    PUBLIC start
    PUBLIC printstring_
    EXTERN hello_:BYTE

start:
    call near ptr hello_
    mov ax, 4C00h   ;normal client exit
    int 21h

;--- print a string in protected-mode with simple
;--- DOS commands not using pointers.

printstring_:
    mov esi, eax
printstring:
    lodsb
    and al,al
    jz stringdone
    mov dl,al
    mov ah,2
    int 21h
    jmp printstring
stringdone:
    ret

    end

Cのコードはこうしました。

# pragma off (check_stack);

void printstring(char *);

hello()
{
        printstring("Hello World!!\n");
}

Open Watcomは標準でスタックチェックの__CHKの呼び出しが入るので、それをprogmaで止めてます。またstdioを使わないためにアセンブラで文字列出力ルーチンを用意してます。

DOS -> ASM -> C -> ASM -> C -> ASM -> DOSになっています。

Cからの呼び出し規約はwdisで確認しました。

これでアセンブリとコンパイルするとHello World!!できます。

IMG_20210625_090100.jpg

リンクのときにsystemがdosなのに32bitコード入ってるよって警告でますが、ちゃんと動くexeが作られます。

Warning! W1080: file start.o is a 32-bit object file
Warning! W1080: file main.o is a 32-bit object file
Warning! W1080: file hello.o is a 32-bit object file

Open WatcomではDOS/4Gという仕組みでDOSの32Bit環境をサポートしていてそのライブラリはあるようなのですが、使い方がよくわかりません。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?