![]() |
日本語プログラムの例 |
変数名や関数名を日本語で付けることもできます。
( ) [ ] + - などの記号を全角で記述することもできます。
たとえば、コード生成例で引用した prime.c を次のように書くこともできます。
ソースコード
1: #include <stdio.h>
2: #define 上限数 100
3: int main()
4: {
5: int 発見数 = 0;
6: int 調査対象 = 2;
7: while ( 発見数 < 上限数 )
8: { int 除数 = 2;
9: while ( 1 )
10: { if ( 除数 >= 調査対象 ) // 発見
11: { printf( "%d ", 調査対象 );
12: 発見数++;
13: break;
14: }
15: if ( 調査対象 % 除数 == 0 ) // 割り切れたら素数ではない
16: break;
17: 除数++;
18: }
19: 調査対象++;
20: }
21: printf( "\n" );
22: return( 0 );
23: }
コンパイル結果この場合、アセンブラ コードにも日本語の名前が出力されます。
public _main
_main proc near ; line 3
push bp
mov bp,sp
add sp,-2
push si ; 調査対象
push di ; 除数
発見数$ equ [bp-2] ; size=2
mov word ptr [発見数$],0h ; line 5
mov si,2h ; line 6
jmp ent_1 ; line 7
top_1:
mov di,2h ; line 8
jmp ent_2 ; line 9
top_2:
mov ax,si ; line 15
cwd
idiv di
cmp dx,0h
je bot_2
inc di ; line 17
ent_2:
cmp di,si ; line 10
jl top_2
push si ; line 11
mov ax,offset a1?
push ax
call near ptr _printf
add sp,4
inc word ptr [発見数$] ; line 12
bot_2:
inc si ; line 19
ent_1:
cmp word ptr [発見数$],64h ; line 7
jl top_1
mov ax,offset a2? ; line 21
push ax
call near ptr _printf
add sp,2
xor ax,ax ; line 22
pop di
pop si
mov sp,bp
pop bp
ret
_main endp