LoginSignup
5
3

More than 1 year has passed since last update.

Z80 アセンブラからCの関数を呼ぶ

Last updated at Posted at 2016-03-17

Z80 アセンブラからCの関数を呼ぶ方法です

 

アセンブラからCの関数を呼ぶ

実行したい関数のサンプル

C
ULONG test(UBYTE bt,UWORD wd,ULONG lg);

これをアセンブラから呼び出すには以下のように記述する

ASM
    LD      XWA,04050607H   ;3番目の引数「lg」にセットする値
    PUSH    XWA             ;スタックに引数を格納
    LDW     BC,0203H        ;2番目の引数「wd」にセットする値
    PUSHW   BC              ;スタックに引数を格納
    LDW     DE,0001H        ;1番目の引数「bt」にセットする値
    PUSHW   DE              ;スタックに引数を格納

    CALL    _test           ;関数を呼び出す

    POPW   DE               ;スタックの後始末
    POPW   BC               ;スタックの後始末
    POP    XWA              ;スタックの後始末

なお、関数の戻り値は

ASM
XHL

というレジスタに格納されます。
 

5
3
2

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
5
3