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.

インタープリタを作る その27

Last updated at Posted at 2021-06-19

#概要

インタープリタを作ってみた。
avrインタープリター書いてみた。
練習問題やってみた。

#練習問題

fizzbuzzをやれ。

#考え方

レジスタ16は、カウンター、1から100まで、回す。
15の剰余を求め、0ならfizzbuzz表示
5の剰余を求め、0ならbuzz表示
3の剰余を求め、0ならfizz表示
その他は、数値表示

#サンプルコード

avr.ldi(16, 0x00)
avr.ldi(18, 0x00)
avr.inc(18)
avr.mov(16, 18)
avr.ldi(17, 0x0f)
avr.cpi(16, 0x0e)
avr.brcs(22)
avr.cpi(16, 0x00)
avr.breq(1)
avr.jmp(31)
avr.ldi(19, 0x66)
avr.out(0, 19)
avr.ldi(19, 0x69)
avr.out(0, 19)
avr.ldi(19, 0x7a)
avr.out(0, 19)
avr.ldi(19, 0x7a)
avr.out(0, 19)
avr.ldi(19, 0x62)
avr.out(0, 19)
avr.ldi(19, 0x75)
avr.out(0, 19)
avr.ldi(19, 0x7a)
avr.out(0, 19)
avr.ldi(19, 0x7a)
avr.out(0, 19)
avr.ldi(19, 0x20)
avr.out(0, 19)
avr.jmp(72)
avr.sub(16, 17)
avr.jmp(5)
avr.mov(16, 18)
avr.ldi(17, 0x05)
avr.cpi(16, 0x04)
avr.brcs(14)
avr.cpi(16, 0x00)
avr.breq(1)
avr.jmp(51)
avr.ldi(19, 0x62)
avr.out(0, 19)
avr.ldi(19, 0x75)
avr.out(0, 19)
avr.ldi(19, 0x7a)
avr.out(0, 19)
avr.ldi(19, 0x7a)
avr.out(0, 19)
avr.ldi(19, 0x20)
avr.out(0, 19)
avr.jmp(72)
avr.sub(16, 17)
avr.jmp(33)
avr.mov(16, 18)
avr.ldi(17, 0x03)
avr.cpi(16, 0x02)
avr.brcs(14)
avr.cpi(16, 0x00)
avr.breq(1)
avr.jmp(71)
avr.ldi(19, 0x66)
avr.out(0, 19)
avr.ldi(19, 0x69)
avr.out(0, 19)
avr.ldi(19, 0x7a)
avr.out(0, 19)
avr.ldi(19, 0x7a)
avr.out(0, 19)
avr.ldi(19, 0x20)
avr.out(0, 19)
avr.jmp(72)
avr.sub(16, 17)
avr.jmp(53)
avr.out(1, 18)
avr.cpi(18, 0x64)
avr.breq(2)
avr.jmp(2)



#結果

1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 fizzbuzz 16 17 fizz 19 buzz fizz 22 23 fizz buzz 26 fizz 28 29 fizzbuzz 31 32 fizz 34 buzz fizz 37 38 fizz buzz 41 fizz 43 44 fizzbuzz 46 47 fizz 49 buzz fizz 52 53 fizz buzz 56 fizz 58 59 fizzbuzz 61 62 fizz 64 buzz fizz 67 68 fizz buzz 71 fizz 73 74 fizzbuzz 76 77 fizz 79 buzz fizz 82 83 fizz buzz 86 fizz 88 89 fizzbuzz 91 92 fizz 94 buzz fizz 97 98 fizz buzz 

#成果物

以上。

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?