]> mj.ucw.cz Git - minsk.git/blob - INSTRUCTIONS
readme.html: Fixed link to Po Drátě
[minsk.git] / INSTRUCTIONS
1 MINSK-2/MINSK-22 INSTRUCTION SET
2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 Data format:
4
5         The memory of the Minsk-2 machine consists of 4096 37-bit words (the topmost bit
6         is always used as a sign). The 0th memory cell is hard-wired to 0, writes
7         have no effect.
8
9         The Minsk-22 machine has 2 banks of 4096 37-bit words each.
10
11         Fixed-point numbers: sign and 36 significant bits
12
13         Binary floating-point numbers (from top to bottom bit):
14
15                 sign of mantissa
16                 28 bits of mantissa
17                 1 bit unused
18                 sign of exponent
19                 6 bits of exponent
20
21         Decimal floating-point numbers (used only for printing):
22
23                 sign of mantissa
24                 28 bits of mantissa (7 decimal digits in BCD)
25                 1 bit unused
26                 sign of exponent
27                 1 bit unused
28                 5 bits of exponent (2 decimal digits in BCD, the former one truncated to 1 bit)
29
30
31 Registers:
32
33 Minsk-2/Minsk-22 has 3 registers:
34
35         accumulator     usually keeps the result of the previous arithmetic operation
36         R1              usually copies one of the operand of the instruction
37         R2              contains the value of acc
38
39 (most programs use only the accumulator)
40
41
42 Generic instruction format:  (by octal digits; some instructions deviate)
43
44 sop mm xxxx yyyy
45  |   |   |    |
46  |   |   |    +--- operand2
47  |   |   +----- operand1
48  |   +------ indexing mode
49  +------- signed operation code
50
51
52 Indexing mode bits:
53
54   aa iiii
55    |   |
56    |   +---- index register: when non-zero, lower 12 bits of the memory
57    |         cell #iiii are added to yyyy, next 12 bits are added to xxxx
58    +----- address extension (supported only on Minsk-22)
59
60
61 Address extension:
62
63         In Minsk-22 mode, the address extension bits can be used to access the second
64         bank of memory in the machine. Each of the bits selects the memory bank 
65         (either 0 or 1) that one of the operands operate on:
66          
67                 The first (high) bit selects the memory bank for operand1 (x)
68                 The second (low) bit selects the memory bank for operand2 (y)
69
70         The instruction pointer always operates on bank 0. This extends to situations 
71         where a (jump) instruction sets the instruction pointer to either x or y; the 
72         address extension bits are effectively ignored in those cases.
73
74         Similarly, the indexing word is always read from bank 0.
75
76         In Minsk-2 mode, setting the address extension bits to anything but 0 is an
77         error in all cases.
78
79
80 For arithmetic instructions, the lower 2 bits of <sop> encode addressing mode:
81
82         0?: arg_a = mem[y], arg_b = mem[x]
83         1?: arg_a = previous value of accumulator, arg_b = mem[x]
84         ?0: store result to accumulator
85         ?1: store result to both accumulator and mem[y]
86
87
88 Instructions:
89
90 +00             NOP
91 +04-07          a^b
92 +10-13          Fixed-point a+b
93 +14-17          Floating-point a+b
94 +20-23          Fixed-point a-b
95 +24-27          Floating-point a-b
96 +30-33          Fixed-point a*b
97 +34-37          Floating-point a*b
98 +40-43          Fixed-point a/b
99 +44-47          Floating-point a/b
100 +50-53          Fixed-point abs(a)-abs(b)
101 +54-57          Floating-point abs(a)-abs(b)
102 +60-63          a << b  (b may be negative)
103 +64-67          a << b  (b may be negative)
104 +70-73          a&b
105 +74-77          a|b
106 -00             HALT, store x to R1 and y to accumulator
107 -03             Magnetic tape I/O -- NOTIMP
108 -04             Disable rounding -- NOTIMP
109 -05             Enable rounding -- NOTIMP
110 -06             Interrupt control -- NOTIMP
111 -07             Reverse tape -- NOTIMP
112 -10             Move: mem[y] = acc = mem[x]
113 -11             Move negative: mem[y] = acc = -mem[x]
114 -12             Move absolute: mem[y] = acc = abs(mem[x])
115 -13             Read from keyboard -- NOTIMP
116 -14             Copy sign of mem[x] to mem[y]
117 -15             Read code from R1 (obscure) -- NOTIMP
118 -16             Copy exponent of mem[x] to mem[y]
119 -17             Teletype I/O -- NOTIMP
120 -20             Loop: uses the index register mem[i] for loop control:
121                 mem[i] is divided to 3 12-bit fields nnnn pppp qqqq,
122                 mem[y] is likewise diveded to fields rrrr ssss tttt.
123                 If n=0, the instruction does nothing
124                 otherwise, mem[i] is written back with:
125                         n' = n-1
126                         p' = p+s mod 4096
127                         q' = q+t mod 4096
128                 and jump to address x.
129 -30             Jump: mem[y]=acc and jump to address x
130 -31             Jump to subroutine at address x, store backward jump instruction to mem[y]
131 -32             Jump by sign: if acc>=0, jump to x, else jump to y
132 -33             Jump by overflow: if overflow, jump to y, else jump to x
133                 (we always halt on overflow, so this is rather trivial)
134 -34             Jump by zero: if acc==0, jump to y, else jump to x
135 -35             Jump by keypress: if key pressed, jump to x, else jump to y
136                 (no keys are emulated)
137 -36             Interrupt masking -- NOTIMP
138 -37             Tape I/O -- NOTIMP
139 -40-47          Various I/O -- NOTIMP
140 -60-61          Various I/O -- NOTIMP
141 -62             Printing instructions, depending on x:
142                         0aaa    put decimal float mem[y] at position aaa in the buffer
143                         1aaa    put octal integer mem[y]
144                         2aaa    put decimal integer mem[y]
145                         3aaa    put decimal integer mem[y], leading zeroes changed to spaces
146                         4aaa    put one Russian symbol stored in 6 topmost bits of mem[y]
147                         5aaa    put Russian text in mem[y] (6 6-bit characters)
148                         6aaa    put one Latin symbol stored in 6 topmost bits of mem[y]
149                         7aaa    put Latin text in mem[y] (6 6-bit characters)
150                         z400    print contents of the buffer
151                                         bit 0 of z: perform line feed afterwards
152                                         bit 1 of z: clear buffer afterwards
153                                         bit 2 of z: if 0, nothing is printed
154                                 Hence, 2400 just clears the buffer, 5400 is a linefeed with
155                                 no effect on the contents of the buffer etc.
156 -63             I/O -- NOTIMP
157 -70             Fixed-point a*b, take bottom part; result always to acc
158                 (what is the sign? the book is silent...)
159 -71             acc = a%b
160 -72             Add exponent of mem[x] to mem[y], copy mem[y] to acc
161 -73             Sub exponent of mem[x] from mem[y], copy mem[y] to acc
162 -74             Addition in one's complement: mem[y] = mem[x] + mem[y]
163 -75             Normalization: convert fixed-point mem[x] to floating-point mem[y]
164 -76             Population count: set mem[y] to number of bits in mem[x]