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.

N-BASICで機械語

Last updated at Posted at 2021-07-14

N-BASICから機械語のルーチンを呼び出すUSRを使ってみます。

何もしないサブルーチンを機械語で保存します。

monでRET(C9)を書いておきます。

mon
* SE800
E800 FF-C9 FF-
*

コントロール+BでN-BASICに戻ります。

N-BASICで

DEF USR=&HE800

しておくとUSRが使えるようになります

? USR(0)
0

引数が数値の場合2バイトの値がHLレジスタの示すメモリに保存されています。また返り値も同じアドレスになるので、0が返ってきます。

インクリメントの関数を書いてみます。

   1:				;
   2:				; PC-8001 assembra
   3:				;
   4:				
   5:				
   6:     -	E800'         		ORG	0E800H
   7:     -	E800'         	USR:
   8:    0+7	E800' 4E      		LD	C,(HL)
   9:    7+4	E801' 0C      		INC	C
  10:   11+7	E802' 71      		LD	(HL),C
  11:   18+10	E803' C9      		RET
  12:				

HLの先のアドレスには下位バイト、上位バイトが保存されていて、下位バイトしか処理していないので、255までになります。

? USR(0)
1
? USR(255)
0
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?