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 その3

Last updated at Posted at 2019-12-25

概要

ilasmでstack machineやってみた。
俺言語、プリプロセッサ作って見た。

俺言語サンプルコード


    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



プリプロセッサ処理後

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