Changeset 219 for branches/CpuSingleSize


Ignore:
Timestamp:
Oct 14, 2020, 8:04:25 PM (4 years ago)
Author:
chronos
Message:
  • Added: New LDI and STI instruction for indexed access to memory.
Location:
branches/CpuSingleSize
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/CpuSingleSize/Sample.asm

    r218 r219  
    110110    POP  R3
    111111    RET
     112
     113Test:
     114     LDI R0, (R1 + 1)
     115     STI (R1 + 12), R2
  • branches/CpuSingleSize/UAssembler.pas

    r218 r219  
    174174      if I > 0 then
    175175        Parser.Expect(tkSpecialSymbol, ',');
     176      if InstructionInfo.Params[I] = ptNumber then begin
     177        Token := Parser.ReadNext;
     178        ParseNumParam(Token);
     179      end else
    176180      if InstructionInfo.Params[I] = ptReg then begin
    177181        Token := Parser.ReadNext;
     
    194198        Parser.Expect(tkSpecialSymbol, ')');
    195199      end else
    196       if InstructionInfo.Params[I] = ptNumber then begin
    197         Token := Parser.ReadNext;
    198         ParseNumParam(Token);
    199       end;
     200      if InstructionInfo.Params[I] = ptRegIndirectIndex then begin
     201        Parser.Expect(tkSpecialSymbol, '(');
     202        Token := Parser.ReadNext;
     203        if (Token.Value <> '') and (Token.Value[1] = 'R') then begin
     204          Token.Value := Copy(Token.Value, 2, MaxInt);
     205          if TryStrToInt(Token.Value, Number) then begin
     206            Memory.Write(Number);
     207            Parser.Expect(tkSpecialSymbol, '+');
     208            Token := Parser.ReadNext;
     209            ParseNumParam(Token);
     210          end else Error('Expected numeric register index error', Token.Pos);
     211        end else Error('Expected register name starting with R character.', Token.Pos);
     212        Parser.Expect(tkSpecialSymbol, ')');
     213      end else
    200214    end;
    201215  end;
  • branches/CpuSingleSize/UCpu.pas

    r216 r219  
    1212    inAdd, inSub, inIn, inOut, inJump, inJumpZero, inJumpNotZero, inPush, inPop,
    1313    inCall, inRet, inAnd, inOr, inXor, inShl, inShr, inMul, inDiv, inMod,
    14     inJumpRel);
     14    inJumpRel, inLoadIndex, inStoreIndex);
    1515
    1616  TInteger = Integer;
     
    114114  Index: TInteger;
    115115  Port: TInteger;
     116  Dest: TInteger;
    116117begin
    117118  Instruction := TInstruction(ReadNext);
     
    207208      R[Index] := R[Index] mod R[ReadNext];
    208209    end;
     210    inLoadIndex: R[ReadNext] := Data[R[ReadNext] + ReadNext];
     211    inStoreIndex: Data[R[ReadNext] + ReadNext] := R[ReadNext];
    209212  end;
    210213  Inc(Ticks);
  • branches/CpuSingleSize/UDisassembler.pas

    r218 r219  
    5252            InstText := InstText + ', ' else
    5353            InstText := InstText + ' ';
     54          if InstructionInfo.Params[J] = ptNumber then begin
     55            InstText := InstText + IntToHex(Value, 8);
     56          end else
    5457          if InstructionInfo.Params[J] = ptReg then begin
    5558            InstText := InstText + 'R' + IntToStr(Value);
     
    5861            InstText := InstText + '(R' + IntToStr(Value) + ')';
    5962          end else
    60           if InstructionInfo.Params[J] = ptNumber then begin
    61             InstText := InstText + IntToHex(Value, 8);
     63          if InstructionInfo.Params[J] = ptRegIndirectIndex then begin
     64            InstText := InstText + '(R' + IntToStr(Value);
     65            Value := Memory.Read;
     66            InstBytes := InstBytes + IntToHex(Value, 2) + ' ';
     67            InstText := InstText + ' + ' + IntToStr(Value) + ')';
    6268          end;
    6369        end;
    64         InstBytes := InstBytes + DupeString(' ', 10 - Length(InstBytes));
     70        InstBytes := InstBytes + DupeString(' ', 13 - Length(InstBytes));
    6571      end;
    6672    end;
  • branches/CpuSingleSize/UInstructions.pas

    r218 r219  
    99
    1010type
    11   TParamType = (ptNone, ptNumber, ptReg, ptRegIndirect);
     11  TParamType = (ptNone, ptNumber, ptReg, ptRegIndirect, ptRegIndirectIndex);
    1212  TParamTypeArray = array of TParamType;
    1313
     
    100100  AddNew(inJump, 'JP', [ptNumber], 'Unconditional absolute jump to defined address.');
    101101  AddNew(inJumpRel, 'JR', [ptNumber], 'Unconditional relative jump to defined address.');
     102  AddNew(inLoadIndex, 'LDI', [ptReg, ptRegIndirectIndex], 'Loads value from memory with numeric index to register.');
     103  AddNew(inStoreIndex, 'STI', [ptRegIndirectIndex, ptReg], 'Stores value from register to memory with numeric index .');
    102104end;
    103105
  • branches/CpuSingleSize/UParser.pas

    r218 r219  
    8787function TParser.IsSpecialSymbol(C: Char): Boolean;
    8888begin
    89   Result := (C = ':') or (C = ',') or (C = '(') or (C = ')');
     89  Result := (C = ':') or (C = ',') or (C = '(') or (C = ')') or (C = '+');
    9090end;
    9191
Note: See TracChangeset for help on using the changeset viewer.