Changeset 168 for branches/virtcpu fixed int/UMachine.pas
- Timestamp:
- Oct 16, 2018, 11:03:59 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virtcpu fixed int/UMachine.pas
r166 r168 5 5 {$DEFINE EXT_ARITHMETIC} 6 6 {$DEFINE EXT_CONDITIONAL} 7 //{$DEFINE EXT_LOGICAL}8 //{$DEFINE EXT_STACK}9 //{$DEFINE EXT_SUBROUTINE}10 //{$DEFINE EXT_ROTATION}11 //{$DEFINE EXT_MULTIPLICATION}12 //{$DEFINE EXT_SHIFT}13 //{$DEFINE EXT_BLOCK}14 //{$DEFINE EXT_GENERAL}15 //{$DEFINE EXT_BIT}16 //{$DEFINE EXT_REL_JUMP}7 {$DEFINE EXT_LOGICAL} 8 {$DEFINE EXT_STACK} 9 {$DEFINE EXT_SUBROUTINE} 10 {$DEFINE EXT_ROTATION} 11 {$DEFINE EXT_MULTIPLICATION} 12 {$DEFINE EXT_SHIFT} 13 {$DEFINE EXT_BLOCK} 14 {$DEFINE EXT_GENERAL} 15 {$DEFINE EXT_BIT} 16 {$DEFINE EXT_REL_JUMP} 17 17 18 18 // Extension dependencies … … 50 50 {$IFDEF EXT_STACK}opPush, opPop,{$ENDIF} 51 51 {$IFDEF EXT_CONDITIONAL} 52 {$IFDEF EXT_REL_JUMP}opJumpRel Cond,{$ENDIF}53 opJump Cond, opTestEqual, opTestNotEqual, opTestLess,52 {$IFDEF EXT_REL_JUMP}opJumpRelZero, opJumpRelNotZero,{$ENDIF} 53 opJumpZero, opJumpNotZero, opTestEqual, opTestNotEqual, opTestLess, 54 54 opTestLessEqual, opTestGreater, opTestGreaterEqual, 55 55 {$ENDIF} … … 97 97 procedure OpcodeTestLessEqual; 98 98 procedure OpcodeTestLess; 99 procedure OpcodeJumpCond; 99 procedure OpcodeJumpCondNotZero; 100 procedure OpcodeJumpCondZero; 100 101 {$IFDEF EXT_REL_JUMP} 101 procedure OpcodeJumpRelCond; 102 procedure OpcodeJumpRelCondNotZero; 103 procedure OpcodeJumpRelCondZero; 102 104 {$ENDIF} 103 105 {$ENDIF} … … 141 143 Registers: array of T; 142 144 IP: T; 143 {$IFDEF EXT_CONDITIONAL}144 Condition: Boolean;145 {$ENDIF}146 145 {$IFDEF EXT_STACK} 147 146 SP: T; … … 149 148 Memory: array of T; 150 149 Terminated: Boolean; 150 Ticks: Integer; 151 151 procedure Start; 152 152 procedure Stop; … … 255 255 {$IFDEF EXT_CONDITIONAL} 256 256 procedure TCPU.OpcodeTestEqual; 257 begin 258 Condition := ReadNext = ReadNext; 257 var 258 P1, P2: T; 259 begin 260 P1 := ReadNext; 261 P2 := ReadNext; 262 if Registers[P1] = Registers[P2] then Registers[P1] := 1 263 else Registers[P1] := 0; 259 264 end; 260 265 261 266 procedure TCPU.OpcodeTestNotEqual; 262 begin 263 Condition := ReadNext <> ReadNext; 267 var 268 P1, P2: T; 269 begin 270 P1 := ReadNext; 271 P2 := ReadNext; 272 if Registers[P1] <> Registers[P2] then Registers[P1] := 1 273 else Registers[P1] := 0; 264 274 end; 265 275 266 276 procedure TCPU.OpcodeTestGreatEqual; 267 begin 268 Condition := ReadNext >= ReadNext; 277 var 278 P1, P2: T; 279 begin 280 P1 := ReadNext; 281 P2 := ReadNext; 282 if Registers[P1] >= Registers[P2] then Registers[P1] := 1 283 else Registers[P1] := 0; 269 284 end; 270 285 271 286 procedure TCPU.OpcodeTestGreat; 272 begin 273 Condition := ReadNext > ReadNext; 287 var 288 P1, P2: T; 289 begin 290 P1 := ReadNext; 291 P2 := ReadNext; 292 if Registers[P1] > Registers[P2] then Registers[P1] := 1 293 else Registers[P1] := 0; 274 294 end; 275 295 276 296 procedure TCPU.OpcodeTestLessEqual; 277 begin 278 Condition := ReadNext <= ReadNext; 297 var 298 P1, P2: T; 299 begin 300 P1 := ReadNext; 301 P2 := ReadNext; 302 if Registers[P1] <= Registers[P2] then Registers[P1] := 1 303 else Registers[P1] := 0; 279 304 end; 280 305 281 306 procedure TCPU.OpcodeTestLess; 282 begin 283 Condition := ReadNext < ReadNext; 284 end; 285 286 procedure TCPU.OpcodeJumpCond; 287 begin 288 if Condition then IP := ReadNext; 289 end; 290 307 var 308 P1, P2: T; 309 begin 310 P1 := ReadNext; 311 P2 := ReadNext; 312 if Registers[P1] < Registers[P2] then Registers[P1] := 1 313 else Registers[P1] := 0; 314 end; 315 316 procedure TCPU.OpcodeJumpCondNotZero; 317 var 318 P1, P2: T; 319 begin 320 P1 := ReadNext; 321 P2 := ReadNext; 322 if Registers[P1] <> 0 then IP := P2; 323 end; 324 325 procedure TCPU.OpcodeJumpCondZero; 326 var 327 P1, P2: T; 328 begin 329 P1 := ReadNext; 330 P2 := ReadNext; 331 if Registers[P1] = 0 then IP := P2; 332 end; 291 333 292 334 {$IFDEF EXT_REL_JUMP} 293 procedure TCPU.OpcodeJumpRelCond; 294 begin 295 if Condition then IP := IP + ReadNext; 335 procedure TCPU.OpcodeJumpRelCondZero; 336 var 337 P1, P2: T; 338 begin 339 P1 := ReadNext; 340 P2 := ReadNext; 341 if P1 = 0 then IP := IP + P2; 342 end; 343 344 procedure TCPU.OpcodeJumpRelCondNotZero; 345 var 346 P1, P2: T; 347 begin 348 P1 := ReadNext; 349 P2 := ReadNext; 350 if P1 <> 0 then IP := IP + P2; 296 351 end; 297 352 {$ENDIF} … … 503 558 Terminated := False; 504 559 IP := 0; 560 Ticks := 0; 505 561 {$IFDEF EXT_STACK} 506 562 SP := Length(Memory); … … 511 567 OpcodeHandlers[TOpcode(Opcode)] 512 568 else raise Exception.Create(Format('Unsupported instruction %d', [Opcode])); 569 Inc(Ticks); 513 570 end; 514 571 end; … … 575 632 {$ENDIF} 576 633 {$IFDEF EXT_CONDITIONAL} 577 OpcodeHandlers[opJumpCond] := OpcodeJumpCond; 634 OpcodeHandlers[opJumpZero] := OpcodeJumpCondZero; 635 OpcodeHandlers[opJumpNotZero] := OpcodeJumpCondNotZero; 578 636 {$IFDEF EXT_REL_JUMP} 579 OpcodeHandlers[opJumpRelCond] := OpcodeJumpRelCond; 637 OpcodeHandlers[opJumpRelZero] := OpcodeJumpRelCondZero; 638 OpcodeHandlers[opJumpRelNotZero] := OpcodeJumpRelCondNotZero; 580 639 {$ENDIF} 581 640 OpcodeHandlers[opTestEqual] := OpcodeTestEqual;
Note:
See TracChangeset
for help on using the changeset viewer.