1
1

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 5 years have passed since last update.

zcc インラインアセンブラ

Last updated at Posted at 2018-07-11

z88dkのzccでインラインアセンブラを使う。

参考
z88dk - The Stack Frame

inline.c
/*
zcc +msx -lndos -create-app inline.c
bload"cas:",r
*/

#include <stdio.h>

int myfunc(char len, unsigned char *p)
{
        #asm

        ld      hl, 2
        add     hl, sp
        ld      e, (hl)
        inc     hl
        ld      d, (hl)         ; de=p
        inc     hl
        ld      b, (hl)         ; b=len
loop:
        ld      a, (de)
        call    $00a2           ; CHPUT
        inc     de
        djnz    loop

        ld      hl, $cafe       ; return value

        #endasm
}

void main()
{
        int ret = myfunc(5, "0123456789");
        printf("\nret = %x\n", ret);
}

WebMSXを起動しa.casファイルをCassetteにドロップする。
WMSX Screen (1).png

  • FASTCALL版
fast.c
/*
zcc +msx -lndos -create-app fast.c
bload"cas:",r
*/

#include <stdio.h>

int __FASTCALL__ myfunc(unsigned char *p)
{
        #asm

loop:
        ld      a, (hl)
        or      a
        jr      z, exit
        call    $00a2           ; CHPUT
        inc     hl
        jr      loop
exit:
        ld      hl, $babe       ; return value

        #endasm
}

void main()
{
        int ret = myfunc("hello, world");
        printf("\nret = %x\n", ret);
}

WMSX Screen (3).png

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?