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?

ilasmでstack machine その6

Last updated at Posted at 2019-12-30

概要

ilasmでstack machineやってみた。
俺言語、コンパイラを考えてみた。
3段階です。

1回目コンパイル後

pushi   1
    set     i
loop:
    get     i
    pushi   100
    if<     bye
    get     i
    pushi   15
    %
    if      fizzbuzz
    get     i
    pushi   5
    %
    if      buzz
    get     i
    pushi   3
    %
    if      fizz
    get     i
    call    printi
    jp      tugi

fizzbuzz:
    push    "fizzbuzz"
    jp      print
buzz:
    push    "buzz"
    jp      print
fizz:
    push    "fizz"

print:
    call    prints

tugi:
    get     i
    pushi   1
    +
    set     i
    jp      loop

bye:
    ret

ソース

10 i=1
30 j=i/15
40 #=%=0*120
50 j=i/5
60 #=%=0*140
70 j=i/3
80 #=%=0*160
90 ?=i
100 #=i<100*180
110 #=300
120 ?="fizzbuzz "
130 #=180
140 ?="buzz "
150 #=180
160 ?="fizz "
180 i=i+1
190 #=30

2回目コンパイル後

.assembly fizzbuzz {}
.method static void main() {
.entrypoint
.locals init(int32 i)
    ldc.i4   1
    stloc     i
loop:
    ldloc     i
    ldc.i4   100
    bgt     bye
    ldloc     i
    ldc.i4   15
    rem
    brfalse      fizzbuzz
    ldloc     i
    ldc.i4   5
    rem
    brfalse      buzz
    ldloc     i
    ldc.i4   3
    rem
    brfalse      fizz
    ldloc     i
    call    void [mscorlib] System.Console::WriteLine(int32)
    br      tugi

fizzbuzz:
    ldstr    "fizzbuzz"
    br      print
buzz:
    ldstr    "buzz"
    br      print
fizz:
    ldstr    "fizz"

print:
    call    void [mscorlib] System.Console::WriteLine(string)

tugi:
    ldloc     i
    ldc.i4   1
    add
    stloc     i
    br      loop

bye:
    ret

}


以上。

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?