Changeset 218 for branches/CpuSingleSize


Ignore:
Timestamp:
Oct 14, 2020, 7:51:40 PM (4 years ago)
Author:
chronos
Message:
  • Added: Support for indirect instruction parameters used mailny for LD, ST, IN and OUT.
Location:
branches/CpuSingleSize
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/CpuSingleSize/Sample.asm

    r217 r218  
    1      DB   Start, KeyInterrupt
     1     DB   Start, KeyInterrupt, 'ABC', 123
    22     NOP
    33     NOP
     
    1919    ;SET  R0, 6
    2020LOOP2:
    21     SET  R0, HELLO
     21    SET  R0, Hello
    2222    SET  R1, 12
    23     CALL WRITESTR
     23    CALL WriteStr
    2424   
    2525;    SET  R0, 0
     
    4444    PUSH R3
    4545LDIR_LOOP:
    46     LD   R3, R0
    47     ST   R1, R3
     46    LD   R3, (R0)
     47    ST   (R1), R3
    4848    INC  R0
    4949    INC  R1
     
    5454   
    5555SETR:
    56     ST   R0, R2
     56    ST   (R0), R2
    5757    INC  R0
    5858    DEC  R1
     
    6060    RET
    6161
    62 WRITESTR:
     62WriteStr:
    6363    PUSH R2
    6464    PUSH R3
    6565    SET  R3, 0
    66 WRITESTR_LOOP:
    67     LD   R2, R0   
    68     OUT  R3, R2
     66WriteStrLoop:
     67    LD   R2, (R0)
     68    OUT  (R3), R2
    6969    INC  R0
    7070    DEC  R1
    71     JNZ  R1, WRITESTR_LOOP
     71    JNZ  R1, WriteStrLoop
    7272    POP  R3
    7373    POP  R2
     
    8080    SET  R0, 1
    8181    SET  R1, 0 
    82     OUT  R0, R1
     82    OUT  (R0), R1
    8383    SET  R0, 3
    84     IN   R1, R0
     84    IN   R1, (R0)
    8585    SET  R0, 4
    86     IN   R2, R0
     86    IN   R2, (R0)
    8787    MUL  R2, R1
    8888    SET  R0, 2
    8989    SET  R1, 120
    9090ClearScreenLoop:
    91     OUT  R0, R1
     91    OUT  (R0), R1
    9292    DEC  R2
    9393    JNZ  R2, ClearScreenLoop
     
    9797    RET
    9898   
    99 HELLO:
     99Hello:
    100100    DB   'Hello friend'
    101101
     
    105105    PUSH R2
    106106    SET  R3, 0
    107     IN   R2, R3
    108     OUT  R3, R2
     107    IN   R2, (R3)
     108    OUT  (R3), R2
    109109    POP  R2
    110110    POP  R3
  • branches/CpuSingleSize/UAssembler.pas

    r217 r218  
    162162  Token: TToken;
    163163  LastPos: TParserPos;
     164  Number: Integer;
    164165begin
    165166  Result := False;
     
    173174      if I > 0 then
    174175        Parser.Expect(tkSpecialSymbol, ',');
    175       Token := Parser.ReadNext;
    176176      if InstructionInfo.Params[I] = ptReg then begin
    177         if (Token.Value <> '') and (Token.Value[1] = 'R') then
    178           Token.Value := Copy(Token.Value, 2, MaxInt)
    179           else Error('Expected register name.', Token.Pos);
    180         Memory.Write(StrToInt(Token.Value));
     177        Token := Parser.ReadNext;
     178        if (Token.Value <> '') and (Token.Value[1] = 'R') then begin
     179          Token.Value := Copy(Token.Value, 2, MaxInt);
     180          if TryStrToInt(Token.Value, Number) then
     181            Memory.Write(Number)
     182            else Error('Expected numeric register index error', Token.Pos);
     183        end else Error('Expected register name starting with R character.', Token.Pos);
     184      end else
     185      if InstructionInfo.Params[I] = ptRegIndirect then begin
     186        Parser.Expect(tkSpecialSymbol, '(');
     187        Token := Parser.ReadNext;
     188        if (Token.Value <> '') and (Token.Value[1] = 'R') then begin
     189          Token.Value := Copy(Token.Value, 2, MaxInt);
     190          if TryStrToInt(Token.Value, Number) then
     191            Memory.Write(Number)
     192            else Error('Expected numeric register index error', Token.Pos);
     193        end else Error('Expected register name starting with R character.', Token.Pos);
     194        Parser.Expect(tkSpecialSymbol, ')');
    181195      end else
    182196      if InstructionInfo.Params[I] = ptNumber then begin
     197        Token := Parser.ReadNext;
    183198        ParseNumParam(Token);
    184199      end;
  • branches/CpuSingleSize/UDisassembler.pas

    r216 r218  
    5555            InstText := InstText + 'R' + IntToStr(Value);
    5656          end else
     57          if InstructionInfo.Params[J] = ptRegIndirect then begin
     58            InstText := InstText + '(R' + IntToStr(Value) + ')';
     59          end else
    5760          if InstructionInfo.Params[J] = ptNumber then begin
    5861            InstText := InstText + IntToHex(Value, 8);
  • branches/CpuSingleSize/UInstructions.pas

    r216 r218  
    99
    1010type
    11   TParamType = (ptNone, ptNumber, ptReg);
     11  TParamType = (ptNone, ptNumber, ptReg, ptRegIndirect);
    1212  TParamTypeArray = array of TParamType;
     13
    1314  TInstructionInfo = class
    1415    Instruction: TInstruction;
     
    7778  AddNew(inInc, 'INC', [ptReg], 'Increments value in specified register.');
    7879  AddNew(inDec, 'DEC', [ptReg], 'Decrements value in specified register.');
    79   AddNew(inLoad, 'LD', [ptReg, ptReg], 'Loads value from memory to register.');
    80   AddNew(inStore, 'ST', [ptReg, ptReg], 'Stores value from register to memory.');
     80  AddNew(inLoad, 'LD', [ptReg, ptRegIndirect], 'Loads value from memory to register.');
     81  AddNew(inStore, 'ST', [ptRegIndirect, ptReg], 'Stores value from register to memory.');
    8182  AddNew(inAdd, 'ADD', [ptReg, ptReg], 'Adds second register to first register.');
    8283  AddNew(inSub, 'SUB', [ptReg, ptReg], 'Subtracts second register from first register.');
    83   AddNew(inIn, 'IN', [ptReg, ptReg], 'Reads value from input port to register.');
    84   AddNew(inOut, 'OUT', [ptReg, ptReg], 'Writes value from register to output port.');
     84  AddNew(inIn, 'IN', [ptReg, ptRegIndirect], 'Reads value from input port to register.');
     85  AddNew(inOut, 'OUT', [ptRegIndirect, ptReg], 'Writes value from register to output port.');
    8586  AddNew(inJumpZero, 'JZ', [ptReg, ptNumber], 'Jumps to given address if value of register is zero');
    8687  AddNew(inJumpNotZero, 'JNZ', [ptReg, ptNumber], 'Jumps to given address if value of register is not zero');
  • branches/CpuSingleSize/UParser.pas

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