Skip to content

Commit 4a13312

Browse files
committed
More samples
1 parent f1d664e commit 4a13312

23 files changed

Lines changed: 398 additions & 20 deletions

samples/mm-1_discr1.mmach

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.cpu mm-1
2+
3+
.input 0x000B, 0x000C, 0x000D
4+
.output 0x000E
5+
6+
.code
7+
00 000C ; <- b
8+
03 000C ; * b
9+
10 000F ; -> b²
10+
00 0011 ; <- 4
11+
03 000B ; * a
12+
03 000D ; * c
13+
10 0010 ; -> 4ac
14+
00 000F ; <- b²
15+
02 0010 ; - 4ac
16+
10 000E ; -> d
17+
99 0000 ; halt
18+
000000 ; a
19+
000000 ; b
20+
000000 ; c
21+
000000 ; d
22+
000000 ; b²
23+
000000 ; 4ac
24+
000004 ; 4
25+
.enter 2 5 3

samples/mm-1_discr2.mmach

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.cpu mm-1
2+
3+
.input 0x0009, 0x000A, 0x000B
4+
.output 0x000C
5+
6+
.code
7+
00 000E ; <- 4
8+
03 0009 ; * a
9+
03 000B ; * c
10+
10 000D ; -> 4ac
11+
00 000A ; <- b
12+
03 000A ; * b
13+
02 000D ; - 4ac
14+
10 000C ; -> d
15+
99 0000 ; halt
16+
000000 ; a
17+
000000 ; b
18+
000000 ; c
19+
000000 ; d
20+
000000 ; 4ac
21+
000004 ; 4
22+
23+
.enter 2 5 3

samples/mm-1_max_of_2.mmach

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.cpu mm-1
2+
3+
; ввести два числа, вывести максимум
4+
.input 0x100, 0x102
5+
.output 0x104
6+
7+
.code
8+
00 0100 ; прочитать (здесь и далее — в аккумулятор, он же S1) 0100
9+
10 0104 ; записать в 0104 (это максимум по умолчанию)
10+
05 0102 ; сравнить с 0102
11+
86 0006 ; перейти, если больше, на 0006 (всё хорошо)
12+
00 0102 ; прочитать 0102
13+
10 0104 ; записать в 0104 (это настоящий максимум)
14+
99 0000 ; КОНЕЦ
15+
16+
.enter 123 234

samples/mm-2_factorial.mmach

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.cpu mm-2
2+
3+
; факториал
4+
.input 0x100
5+
.output 0x101
6+
7+
.code
8+
00 0102 0100 ; 0; Заносим N в счётчик
9+
00 0101 0008 ; 1; Заносим 1 в результат
10+
05 0102 0008 ; 2; Сравниваем счётчик и 1
11+
85 0000 0007 ; 3; Если ≤, цикл окончен
12+
03 0101 0102 ; 4; Домножаем результат на счётчик
13+
02 0102 0008 ; 5; Уменьшаем счётчик на 1
14+
80 0000 0002 ; 6; Переход на начало цикла
15+
99 0000 0000 ; 7; конец
16+
00 0000 0001 ; 8; 1
17+
18+
.enter 6

samples/mm-2_flags.mmach

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.cpu mm-2
2+
3+
.input 0x1000,0x1001,0x1002,0x1003,0x1004,0x1005
4+
.output 0x1000,0x1001,0x1002,0x1003,0x1004,0x1005
5+
6+
.code
7+
05 1000 1000
8+
05 1000 1001
9+
05 1000 1002
10+
05 1003 1004
11+
05 1003 1005
12+
99 0000 0000
13+
14+
.enter 25 20 31 0x8000000004 0x8000000002 1234

samples/mm-2_max_of_2.mmach

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.cpu mm-2
2+
3+
; ввести два числа, вывести максимум
4+
.input 0x101, 0x102
5+
.output 0x103
6+
7+
.code
8+
00 0103 0101 ; по умолчанию максимум — 0101
9+
05 0101 0102 ; comp 0101 0102 — команда сравнения
10+
86 0000 0004 ; если 0101 и вправду больше, перейти на 0004
11+
00 0103 0102 ; иначе максимум — 0103
12+
99 0000 0000 ;
13+
14+
.enter 723 234

samples/mm-3_add.mmach

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.cpu mm-3
2+
.input 0x0100, 0x0101
3+
.output 0x0102
4+
5+
.code
6+
01 0100 0101 0102
7+
99 0000 0000 0000
8+
9+
.enter 1234 3232

samples/mm-3_denominator.mmach

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.cpu mm-3
2+
3+
.input 0x100, 0x101
4+
.output 0x104
5+
6+
.code
7+
04 0100 0101 0102; 0
8+
81 0103 0006 0004; 1
9+
00 0006 0000 0104; 2
10+
99 0000 0000 0000; 3
11+
00 0007 0000 0104; 4
12+
99 0000 0000 0000; 5
13+
00000000000000; 6 =0
14+
00000000000001; 7 =1
15+
16+
.enter 10 3

samples/mm-3_discr.mmach

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.cpu mm-3
2+
; a,b,c и d разместим по адресам 010a, 010b, 010c и 010d
3+
.input 0x010a, 0x010b, 0x010c
4+
.output 0x010d
5+
6+
.code
7+
03 010b 010b 0100 ; b*b (умножение со знаком), результат в ячейке 0100
8+
03 010a 010c 0101 ; a*c, результат в 0101
9+
03 0101 0005 0101 ; ac*4, результат в 0101
10+
02 0100 0101 010d ; b²-4ac
11+
99 0000 0000 0000
12+
00 0000 0000 0004 ; константа 4
13+
14+
.enter 5 8 3

samples/mm-3_discr_const.mmach

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.cpu mm-3
2+
; a,b,c и d разместим по адресам 010a, 010b, 010c и 010d
3+
.input 0x010a, 0x010b, 0x010c
4+
.output 0x010d
5+
6+
.code
7+
03 010b 010b 0100 ; b*b (умножение со знаком), результат в ячейке 0100
8+
03 010a 010c 0101 ; a*c, результат в 0101
9+
03 0101 0102 0101 ; ac*4, результат в 0101
10+
02 0100 0101 010d ; b²-4ac
11+
99 0000 0000 0000
12+
.code 0x102
13+
00 0000 0000 0004 ; константа 4
14+
15+
.enter 5 8 3
16+

0 commit comments

Comments
 (0)