Changeset 188
- Timestamp:
- May 7, 2019, 6:12:15 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virtualcpu4/UCompilerPascal.pas
r187 r188 71 71 function GetRegister(Index: Byte; BitWidth: TBitWidth): string; 72 72 function GetMemory(Offset: string; BitWidth: TBitWidth): string; 73 function GetJump(LabelName: string): string; 73 74 public 74 75 Reader: TInstructionReader; … … 124 125 procedure TCompilerPascal.InstJump; 125 126 begin 126 AddLine( 'GotoAddr(@L' + IntToStr(Reader.ReadAddress) + ');');127 AddLine(GetJump('L' + IntToStr(Reader.ReadAddress))); 127 128 end; 128 129 129 130 procedure TCompilerPascal.InstJumpZero; 130 131 begin 131 AddLine('if Zero then GotoAddr(@L' + IntToStr(Reader.ReadAddress) + ');');132 AddLine('if Zero then ' + GetJump('L' + IntToStr(Reader.ReadAddress))); 132 133 end; 133 134 134 135 procedure TCompilerPascal.InstJumpNotZero; 135 136 begin 136 AddLine('if not Zero then GotoAddr(@L' + IntToStr(Reader.ReadAddress) + ');');137 AddLine('if not Zero then ' + GetJump('L' + IntToStr(Reader.ReadAddress))); 137 138 end; 138 139 … … 142 143 begin 143 144 Addr := Reader.ReadAddressSigned; 144 AddLine( 'GotoAddr(@L' + IntToStr(Reader.IP + Addr) + ');');145 AddLine(GetJump('L' + IntToStr(Reader.IP + Addr))); 145 146 end; 146 147 … … 150 151 begin 151 152 Addr := Reader.ReadAddressSigned; 152 AddLine('if Zero then GotoAddr(@L' + IntToStr(Reader.IP + Addr) + ');');153 AddLine('if Zero then ' + GetJump('L' + IntToStr(Reader.IP + Addr))); 153 154 end; 154 155 … … 158 159 begin 159 160 Addr := Reader.ReadAddressSigned; 160 AddLine('if not Zero then GotoAddr(@L' + IntToStr(Reader.IP + Addr) + ');');161 AddLine('if not Zero then ' + GetJump('L' + IntToStr(Reader.IP + Addr))); 161 162 end; 162 163 … … 240 241 Addr := Reader.ReadAddress; 241 242 AddLine('Dec(SP, ' + IntToStr(BitWidthBytes[Reader.AddrSize]) + ');'); 242 AddLine(GetMemory('SP', Reader.AddrSize) + ' := ' + IntToStr(Reader.IP) + ';');243 AddLine( 'GotoAddr(@L' + IntToStr(Addr) + ');');243 AddLine(GetMemory('SP', Reader.AddrSize) + ' := LongWord(@L' + IntToStr(Reader.IP) + ');'); 244 AddLine(GetJump('L' + IntToStr(Addr))); 244 245 end; 245 246 … … 248 249 AddLine('TempAddr := Pointer(' + GetMemory('SP', Reader.AddrSize) + ');'); 249 250 AddLine('Inc(SP, ' + IntToStr(BitWidthBytes[Reader.AddrSize]) + ');'); 250 AddLine( 'GotoAddr(TempAddr);');251 AddLine(GetJump('TempAddr')); 251 252 end; 252 253 … … 551 552 end; 552 553 554 function TCompilerPascal.GetJump(LabelName: string): string; 555 begin 556 Result := 'asm jmp ' + LabelName + ' end;'; 557 end; 558 553 559 procedure TCompilerPascal.Compile; 554 560 var … … 607 613 AddLine(' TempAddr: Pointer;'); 608 614 AddLine(''); 609 AddLine('procedure GotoAddr(P: Pointer); inline; assembler;');610 AddLine('asm');611 AddLine(' jmp P;');612 AddLine('end;');613 AddLine('');614 615 LabelsText := ''; 615 616 for I := 0 to Labels.Count - 1 do begin
Note:
See TracChangeset
for help on using the changeset viewer.