implemented spec change: now cell 127 always return 1

This commit is contained in:
Luxferre
2025-04-30 11:04:43 +03:00
parent 0a3361f8ab
commit c4af5dec42
7 changed files with 37 additions and 30 deletions
+7 -5
View File
@@ -14,8 +14,8 @@ programs and data. The only available data type is a floating point number,
although some implementations may use fixed point numbers instead. although some implementations may use fixed point numbers instead.
Unlike 808UL, mu808 strictly defines support of up to 16384 data cells and Unlike 808UL, mu808 strictly defines support of up to 16384 data cells and
up to 16383 program steps, with the program step 0 being unavailable and the up to 16383 program steps, with the program step 0 being unavailable, the
data cell 0 always returning 0. data cell 0 always returning 0 and the data cell 127 always returning 1.
On the machine start, both memory areas are initialized with zeroes and the On the machine start, both memory areas are initialized with zeroes and the
interactive mode is entered which accepts instructions from the platform's interactive mode is entered which accepts instructions from the platform's
@@ -27,7 +27,8 @@ standard input.
* ability to enter integer commands (positive and negative) into program memory; * ability to enter integer commands (positive and negative) into program memory;
* ability to enter floating (or fixed) point numbers (positive and negative) at * ability to enter floating (or fixed) point numbers (positive and negative) at
program runtime; program runtime;
* immutability of the data address 0 (must always return 0 when accessed). * immutability of the data address 0 (must always return 0 when accessed);
* immutability of the data address 127 (must always return 1 when accessed).
The following things are implementation-dependent: The following things are implementation-dependent:
@@ -191,6 +192,7 @@ The shortcut mnemonics for other operations are as follows:
* `dca` is a shortcut to `cpy 0` (direct constant assignment) * `dca` is a shortcut to `cpy 0` (direct constant assignment)
* `dva` is a shortcut to `cpy 1` (direct value assignment) * `dva` is a shortcut to `cpy 1` (direct value assignment)
* `iva` is a shortcut to `cpy 2` (indirect value assignment) * `iva` is a shortcut to `cpy 2` (indirect value assignment)
* `inc` is a shortcut to `fma 127 127` (increment)
* `mul` is a shortcut to `fma 0` (multiplication) * `mul` is a shortcut to `fma 0` (multiplication)
* `exp` is a shortcut to `nel 0` (natural exponent) * `exp` is a shortcut to `nel 0` (natural exponent)
* `log` is a shortcut to `nel 1` (natural logarithm) * `log` is a shortcut to `nel 1` (natural logarithm)
@@ -475,8 +477,8 @@ to store a constant 1 into some unused location, like 99. You can do this e.g.
with the `set 1 0 99` operation. Then, let's go with three cases (assuming we with the `set 1 0 99` operation. Then, let's go with three cases (assuming we
have stored 1 into the data memory location 99): have stored 1 into the data memory location 99):
1. Incrementing a memory location is as easy as `fma 99 99 [loc]`. 1. Incrementing a memory location is as easy as `fma 127 127 [loc]`.
2. Adding two numbers at loc1 and loc2 into loc2: `fma [loc1] 99 [loc2]`. 2. Adding two numbers at loc1 and loc2 into loc2: `fma [loc1] 127 [loc2]`.
3. Multiplying two numbers at loc1 and loc2 into loc2: `fma 0 [loc1] [loc2]`. 3. Multiplying two numbers at loc1 and loc2 into loc2: `fma 0 [loc1] [loc2]`.
The only inconvenience with the FMA operation is that you need to sacrifice one The only inconvenience with the FMA operation is that you need to sacrifice one
+1
View File
@@ -27,6 +27,7 @@ function ilexec(lno, cmd, x, y, z, halt, data_override, bcheck, i, v1, v2, v3)
while(halt == 0) { while(halt == 0) {
if(traceflag) printf("PC: %hu INSTR: %hu %hu %hu %hu\n", lno, cmd, x, y, z) if(traceflag) printf("PC: %hu INSTR: %hu %hu %hu %hu\n", lno, cmd, x, y, z)
DMEM[0] = data_override = 0 # force the value at 0 to be always 0 DMEM[0] = data_override = 0 # force the value at 0 to be always 0
DMEM[127] = 1 # force the value at 127 to always be 1
bcheck = (x < MEMLIMIT) && (y < MEMLIMIT) && (z < MEMLIMIT) bcheck = (x < MEMLIMIT) && (y < MEMLIMIT) && (z < MEMLIMIT)
if(bcheck) { if(bcheck) {
v1 = DMEM[x]; v2 = DMEM[y]; v3 = DMEM[z] # prefetch the memory values v1 = DMEM[x]; v2 = DMEM[y]; v3 = DMEM[z] # prefetch the memory values
+1 -1
View File
@@ -12,7 +12,7 @@
210 IF IAT=1 THEN 220 ELSE 230 210 IF IAT=1 THEN 220 ELSE 230
220 X=INT(V1):Y=INT(V2):Z=INT(V3):IAT=0:GOTO 240 220 X=INT(V1):Y=INT(V2):Z=INT(V3):IAT=0:GOTO 240
230 X=A-CMD*10000:Y=INT(B/10000):Z=B-Y*10000 230 X=A-CMD*10000:Y=INT(B/10000):Z=B-Y*10000
240 V1,V2,V3,DMEM(0)=0 240 V1,V2,V3,DMEM(0)=0:DMEM(127)=1
250 IF CMD=5 THEN DMEM(Z)=X+(Y/10000):GOTO 180 250 IF CMD=5 THEN DMEM(Z)=X+(Y/10000):GOTO 180
260 V1=DMEM(X):V2=DMEM(Y):V3=DMEM(Z) 260 V1=DMEM(X):V2=DMEM(Y):V3=DMEM(Z)
270 IF CMD=1 THEN 280 ELSE 420 270 IF CMD=1 THEN 280 ELSE 420
+1
View File
@@ -76,6 +76,7 @@ void ilexec(ushort lno, ushort cmd, ushort x, ushort y, ushort z) {
while(halt == 0) { while(halt == 0) {
if(traceflag) printf("PC: %hu INSTR: %hu %hu %hu %hu" NLC, lno, cmd, x, y, z); if(traceflag) printf("PC: %hu INSTR: %hu %hu %hu %hu" NLC, lno, cmd, x, y, z);
DMEM[0] = data_override = 0; /* force the value at 0 to be always 0 */ DMEM[0] = data_override = 0; /* force the value at 0 to be always 0 */
DMEM[127] = 1; /* force the value at 127 to always be 1 */
bcheck = (x < MEMLIMIT) && (y < MEMLIMIT) && (z < MEMLIMIT); bcheck = (x < MEMLIMIT) && (y < MEMLIMIT) && (z < MEMLIMIT);
if(bcheck) { if(bcheck) {
v1 = DMEM[x]; v2 = DMEM[y]; v3 = DMEM[z]; /* prefetch the memory values */ v1 = DMEM[x]; v2 = DMEM[y]; v3 = DMEM[z]; /* prefetch the memory values */
+1
View File
@@ -62,6 +62,7 @@ def ilexec(lno:int, cmd:int=0, x:int=0, y:int=0, z:int=0):
if traceflag: if traceflag:
print(f'PC: {lno} INSTR: {cmd} {x} {y} {z}') print(f'PC: {lno} INSTR: {cmd} {x} {y} {z}')
DMEM[0] = 0.0 # force the value at 0 to always be 0 DMEM[0] = 0.0 # force the value at 0 to always be 0
DMEM[127] = 1.0 # force the value at 127 to always be 1
data_override = False data_override = False
# perform a boundary check and prefetch the memory values # perform a boundary check and prefetch the memory values
bcheck = True bcheck = True
+25 -24
View File
@@ -19,30 +19,31 @@ mnemos = ['nop', 'jmp', 'iat', 'out', 'inp', 'set', 'cpy', 'fma',
# mu808 jump/function shortcuts # mu808 jump/function shortcuts
jmpfunc_shorts = { jmpfunc_shorts = {
'nnn': 'nop 0 0 0', # alias for nop 'nnn': 'nop 0 0 0', # alias for nop
'ige': 'jmp 10', # indirect jump if greater than or equals to zero 'ige': 'jmp 10', # indirect jump if greater than or equals to zero
'ile': 'jmp 11', # indirect jump if less than or equals to zero 'ile': 'jmp 11', # indirect jump if less than or equals to zero
'ine': 'jmp 12', # indirect jump if not equals to zero 'ine': 'jmp 12', # indirect jump if not equals to zero
'iuc': 'jmp 13 0', # indirect unconditional jump 'iuc': 'jmp 13 0', # indirect unconditional jump
'jeq': 'jmp 0', # direct jump if equals to zero 'jeq': 'jmp 0', # direct jump if equals to zero
'jgt': 'jmp 1', # direct jump if greater than zero 'jgt': 'jmp 1', # direct jump if greater than zero
'jlt': 'jmp 2', # direct jump if less than zero 'jlt': 'jmp 2', # direct jump if less than zero
'jge': 'jmp 3', # direct jump if greater than or equals to zero 'jge': 'jmp 3', # direct jump if greater than or equals to zero
'jle': 'jmp 4', # direct jump if less than or equals to zero 'jle': 'jmp 4', # direct jump if less than or equals to zero
'jne': 'jmp 5', # direct jump if not equals to zero 'jne': 'jmp 5', # direct jump if not equals to zero
'juc': 'jmp 6 0', # direct unconditional jump 'juc': 'jmp 6 0', # direct unconditional jump
'ieq': 'jmp 7', # indirect jump if equals to zero 'ieq': 'jmp 7', # indirect jump if equals to zero
'igt': 'jmp 8', # indirect jump if greater than zero 'igt': 'jmp 8', # indirect jump if greater than zero
'ilt': 'jmp 9', # indirect jump if less than zero 'ilt': 'jmp 9', # indirect jump if less than zero
'dca': 'cpy 0', # direct constant assignment 'dca': 'cpy 0', # direct constant assignment
'dva': 'cpy 1', # direct value assignment 'dva': 'cpy 1', # direct value assignment
'iva': 'cpy 2', # indirect value assignment 'iva': 'cpy 2', # indirect value assignment
'mul': 'fma 0', # multiplication 'inc': 'fma 127 127', # increment
'exp': 'nel 0', # natural exponent 'mul': 'fma 0', # multiplication
'log': 'nel 1', # natural logarithm 'exp': 'nel 0', # natural exponent
'sin': 'tri 0', # sine 'log': 'nel 1', # natural logarithm
'cos': 'tri 1', # cosine 'sin': 'tri 0', # sine
'atn': 'tri 2' # arctangent 'cos': 'tri 1', # cosine
'atn': 'tri 2' # arctangent
} }
# converts the MU8A source code to the plaintext machine code representation # converts the MU8A source code to the plaintext machine code representation
+1
View File
@@ -42,6 +42,7 @@ function createmu808(lineOut, charOut, lineIn) {
var halt = 0, data_override = 0, bcheck, i, v1, v2, v3 var halt = 0, data_override = 0, bcheck, i, v1, v2, v3
while(halt == 0) { while(halt == 0) {
v1 = v2 = v3 = data_override = DMEM[0] = 0 /* force the value at 0 to be always 0 */ v1 = v2 = v3 = data_override = DMEM[0] = 0 /* force the value at 0 to be always 0 */
DMEM[127] = 1 /* force the value at 127 to be always 1 */
if(lno == 0) halt = 1 /* immediate instruction */ if(lno == 0) halt = 1 /* immediate instruction */
if(runlimit > 0 && runcount > runlimit) { if(runlimit > 0 && runcount > runlimit) {
halt = 1 halt = 1