Open Watcom IDE -- Cからとアセンブラールーチンを呼び出す
2018-03-02


禺画像]
cd C:\SHELL\SAMPLE wmake -f C:\SHELL\SAMPLE\callasm.mk -h -e C:\SHELL\SAMPLE\callasm.exe wasm FOO.ASM -i="E:\WATCOM/h" -ms -fp0 -w4 -e25 Open Watcom Assembler Version 1.9 Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved. Source code is available under the Sybase Open Watcom Public License. See http://www.openwatcom.org/ for details. FOO.ASM: 27 lines, 0 warnings, 0 errors wcc callasm.c -i="E:\WATCOM/h" -w4 -e25 -zp2 -od -fp2 -fpi87 -bt=dos -fo=.obj -ms Open Watcom C16 Optimizing Compiler Version 1.9 Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved. Source code is available under the Sybase Open Watcom Public License. See http://www.openwatcom.org/ for details. callasm.c: 11 lines, included 773, 0 warnings, 0 errors Code size: 60 wlink name callasm d all sys dos op m op maxe=25 op q op symf @callasm.lk1 Error! E2028: foo_ is an undefined reference file callasm.obj(C:\SHELL\SAMPLE\callasm.c): undefined symbol foo_ Error(E42): Last command making (C:\SHELL\SAMPLE\callasm.exe) returned a bad status Error(E02): Make execution terminated Execution complete というわけで、foo.asm内の"_foo"を"foo_"に編集し再ビルドしました。
          ; foo.asm
          _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
          _text    SEGMENT
          ; ---------------------------------------------------------------------
          ;        foo(int val)
          ;        val=bp+4
          foo_     PROC NEAR
                   PUBLIC foo_
                   push bp
                   mov bp,sp
                   mov ax,[bp+4]
                   shl ax,1
                   mov sp,bp
                   pop bp
                   ret
          foo_     ENDP
          _TEXT    ENDS
                   END

再ビルドしてみると、エラーはなくなりました。

          cd C:\SHELL\SAMPLE
          wmake -f C:\SHELL\SAMPLE\callasm.mk -h -e C:\SHELL\SAMPLE\callasm.exe
          wasm FOO.ASM -i="E:\WATCOM/h" -ms -fp0 -w4 -e25
          Open Watcom Assembler Version 1.9
          Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
          Source code is available under the Sybase Open Watcom Public License.
          See http://www.openwatcom.org/ for details.
          FOO.ASM: 27 lines, 0 warnings, 0 errors
          wlink name callasm d all sys dos op m op maxe=25 op q op symf @callasm.lk1
          Execution complete

テストです。

          C:\SHELL\SAMPLE>callasm
          7 => 3522

アセンブラールーチン"foo"は、受け取った引数を左に1bitシフトする事で受け取った引数を2倍して値を返します。 結果は、"14"になるはずですが、そうなっていません。確認のため、 "callasm.c"のコンパイル結果を見るためにコンパイルリストをコンパイラーに吐かせようとしましたが、"wcc"のオプションに 該当するものが見当たらいません。調べてみると"Open Watcom Assembler"Wikiの"Disassembler"の項目に、 以下の記述を見つけました。

          The assembler does not have listing facilities; instead the use of
          wdis for generating listings is recommended.

この指示に従い、callasm.objを"wdis"で、逆アセンブルしてみました。



続きを読む
戻る
[コンピューター]
[OS/2]
[DOS Shell]

コメント(全9件)
コメントをする


記事を書く
powered by ASAHIネット