From c4af5dec42888b215599c7b47821efde11e934bc Mon Sep 17 00:00:00 2001 From: Luxferre Date: Wed, 30 Apr 2025 11:04:43 +0300 Subject: [PATCH] implemented spec change: now cell 127 always return 1 --- README.md | 12 ++++++----- mu808.awk | 1 + mu808.b74 | 2 +- mu808.c | 1 + mu808.py | 1 + mu808asm.py | 49 ++++++++++++++++++++++---------------------- mu8web/mu808-core.js | 1 + 7 files changed, 37 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 6a98ea5..988b39d 100644 --- a/README.md +++ b/README.md @@ -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. 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 -data cell 0 always returning 0. +up to 16383 program steps, with the program step 0 being unavailable, the +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 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 floating (or fixed) point numbers (positive and negative) at 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: @@ -191,6 +192,7 @@ The shortcut mnemonics for other operations are as follows: * `dca` is a shortcut to `cpy 0` (direct constant assignment) * `dva` is a shortcut to `cpy 1` (direct 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) * `exp` is a shortcut to `nel 0` (natural exponent) * `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 have stored 1 into the data memory location 99): -1. Incrementing a memory location is as easy as `fma 99 99 [loc]`. -2. Adding two numbers at loc1 and loc2 into loc2: `fma [loc1] 99 [loc2]`. +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] 127 [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 diff --git a/mu808.awk b/mu808.awk index ca4c2ee..0e0e541 100644 --- a/mu808.awk +++ b/mu808.awk @@ -27,6 +27,7 @@ function ilexec(lno, cmd, x, y, z, halt, data_override, bcheck, i, v1, v2, v3) while(halt == 0) { 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[127] = 1 # force the value at 127 to always be 1 bcheck = (x < MEMLIMIT) && (y < MEMLIMIT) && (z < MEMLIMIT) if(bcheck) { v1 = DMEM[x]; v2 = DMEM[y]; v3 = DMEM[z] # prefetch the memory values diff --git a/mu808.b74 b/mu808.b74 index 5e3db74..dcb1cb4 100644 --- a/mu808.b74 +++ b/mu808.b74 @@ -12,7 +12,7 @@ 210 IF IAT=1 THEN 220 ELSE 230 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 -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 260 V1=DMEM(X):V2=DMEM(Y):V3=DMEM(Z) 270 IF CMD=1 THEN 280 ELSE 420 diff --git a/mu808.c b/mu808.c index 885796f..6714771 100644 --- a/mu808.c +++ b/mu808.c @@ -76,6 +76,7 @@ void ilexec(ushort lno, ushort cmd, ushort x, ushort y, ushort z) { while(halt == 0) { 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[127] = 1; /* force the value at 127 to always be 1 */ bcheck = (x < MEMLIMIT) && (y < MEMLIMIT) && (z < MEMLIMIT); if(bcheck) { v1 = DMEM[x]; v2 = DMEM[y]; v3 = DMEM[z]; /* prefetch the memory values */ diff --git a/mu808.py b/mu808.py index 5a0b62d..95aeb56 100755 --- a/mu808.py +++ b/mu808.py @@ -62,6 +62,7 @@ def ilexec(lno:int, cmd:int=0, x:int=0, y:int=0, z:int=0): if traceflag: print(f'PC: {lno} INSTR: {cmd} {x} {y} {z}') 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 # perform a boundary check and prefetch the memory values bcheck = True diff --git a/mu808asm.py b/mu808asm.py index 7c5e634..aa4f28f 100755 --- a/mu808asm.py +++ b/mu808asm.py @@ -19,30 +19,31 @@ mnemos = ['nop', 'jmp', 'iat', 'out', 'inp', 'set', 'cpy', 'fma', # mu808 jump/function shortcuts jmpfunc_shorts = { - 'nnn': 'nop 0 0 0', # alias for nop - 'ige': 'jmp 10', # indirect jump if greater 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 - 'iuc': 'jmp 13 0', # indirect unconditional jump - 'jeq': 'jmp 0', # direct jump if equals to zero - 'jgt': 'jmp 1', # direct jump if greater than zero - 'jlt': 'jmp 2', # direct jump if less than 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 - 'jne': 'jmp 5', # direct jump if not equals to zero - 'juc': 'jmp 6 0', # direct unconditional jump - 'ieq': 'jmp 7', # indirect jump if equals to zero - 'igt': 'jmp 8', # indirect jump if greater than zero - 'ilt': 'jmp 9', # indirect jump if less than zero - 'dca': 'cpy 0', # direct constant assignment - 'dva': 'cpy 1', # direct value assignment - 'iva': 'cpy 2', # indirect value assignment - 'mul': 'fma 0', # multiplication - 'exp': 'nel 0', # natural exponent - 'log': 'nel 1', # natural logarithm - 'sin': 'tri 0', # sine - 'cos': 'tri 1', # cosine - 'atn': 'tri 2' # arctangent + 'nnn': 'nop 0 0 0', # alias for nop + 'ige': 'jmp 10', # indirect jump if greater 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 + 'iuc': 'jmp 13 0', # indirect unconditional jump + 'jeq': 'jmp 0', # direct jump if equals to zero + 'jgt': 'jmp 1', # direct jump if greater than zero + 'jlt': 'jmp 2', # direct jump if less than 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 + 'jne': 'jmp 5', # direct jump if not equals to zero + 'juc': 'jmp 6 0', # direct unconditional jump + 'ieq': 'jmp 7', # indirect jump if equals to zero + 'igt': 'jmp 8', # indirect jump if greater than zero + 'ilt': 'jmp 9', # indirect jump if less than zero + 'dca': 'cpy 0', # direct constant assignment + 'dva': 'cpy 1', # direct value assignment + 'iva': 'cpy 2', # indirect value assignment + 'inc': 'fma 127 127', # increment + 'mul': 'fma 0', # multiplication + 'exp': 'nel 0', # natural exponent + 'log': 'nel 1', # natural logarithm + 'sin': 'tri 0', # sine + 'cos': 'tri 1', # cosine + 'atn': 'tri 2' # arctangent } # converts the MU8A source code to the plaintext machine code representation diff --git a/mu8web/mu808-core.js b/mu8web/mu808-core.js index 80f36e9..dfa2dff 100644 --- a/mu8web/mu808-core.js +++ b/mu8web/mu808-core.js @@ -42,6 +42,7 @@ function createmu808(lineOut, charOut, lineIn) { var halt = 0, data_override = 0, bcheck, i, v1, v2, v3 while(halt == 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(runlimit > 0 && runcount > runlimit) { halt = 1