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

MSX Cとアセンブラの実験

Last updated at Posted at 2018-09-08

Cでオブジェクトを作ってアセンブラのように実行してみるテスト。

hello1.c
/*
z88dk / WebMSX
zcc +msx -lndos -ohello1.bin --list -create-app hello1.c
*/

void main()
{
	puts("hello,\r\nworld one");
}
hello2.c
/*
z88dk / WebMSX
zcc +msx -c --list hello2.c
z80asm -b -r=0xd000 hello2.o
appmake +msx -b hello2.bin --org 0xd000 --fmsx
*/

void __FASTCALL__ myputs(char *str);

void mymain()
{
	myputs("hello,\r\nworld two");
}

void __FASTCALL__ myputs(char *str)
{
# asm
.loop
	ld	a, (hl)
	inc	hl
	or	a
	jr	z, exit
	call	$00a2		; CHPUT
	jr	loop
.exit
# endasm
}

hello1.bin 651バイト
hello2.bin 38バイト

hello2.dmp
 ADDRESS   00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F   0123456789ABCDEF 
------------------------------------------------------------------------------
 00000000  21 14 D0 CD 07 D0 C9 E5 7E 23 B7 28 05 CD A2 00   !.ミヘ.ミノ蛬#キ(.ヘ「. 
 00000010  18 F6 C1 C9 68 65 6C 6C 6F 2C 0D 0A 77 6F 72 6C   .ノhello,..worl 
 00000020  64 20 74 77 6F 00                                 d two.           
hello2.c.lis(抜粋)
16    0000              	SECTION	code_compiler
17    0000              
18    0000              ; Function mymain flags 0x00000200 __smallc
19    0000              ; void mymain()
20    0000              ._mymain
21    0000  21 00 00    	ld	hl,i_1+0
22    0003  CD 07 00    	call	_myputs
23    0006  C9          	ret
24    0007              
25    0007              
26    0007              
27    0007              ; Function myputs flags 0x00000208 __smallc __z88dk_fastcall
28    0007              ; void myputs(char *str)
29    0007              ; parameter 'char *str' at 2 size(2)
30    0007              ._myputs
31    0007  E5          	push	hl
32    0008              .loop
33    0008  7E          	ld	a, (hl)
34    0009  23          	inc	hl
35    000A  B7          	or	a
36    000B  28 05       	jr	z, exit
37    000D  CD A2 00    	call	$00a2		; CHPUT
38    0010  18 F6       	jr	loop
39    0012              .exit
40    0012  C1          	pop	bc
41    0013  C9          	ret

WMSX Screen (1).png

2
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
2
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?