Changeset 12 for branches/bigint
- Timestamp:
- Apr 24, 2025, 10:12:32 PM (2 weeks ago)
- Location:
- branches/bigint
- Files:
-
- 4 added
- 2 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bigint/BigIntVM.lpi
r8 r12 24 24 <SearchPaths> 25 25 <IncludeFiles Value="$(ProjOutDir)"/> 26 <OtherUnitFiles Value="Forms "/>26 <OtherUnitFiles Value="Forms;Devices"/> 27 27 <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)-$(BuildMode)"/> 28 28 </SearchPaths> … … 60 60 </Item> 61 61 <SharedMatrixOptions Count="2"> 62 <Item1 Targets="Common" Modes="Debug" Value="-g -gl -gh -CirotR -O1"/>62 <Item1 ID="496997618487" Targets="Common" Modes="Debug" Value="-g -gl -gh -CirotR -O1"/> 63 63 <Item2 ID="202440807568" Targets="Common" Modes="Release" Value="-CX -XX -O3"/> 64 64 </SharedMatrixOptions> … … 113 113 </Unit> 114 114 <Unit> 115 <Filename Value=" Screen.pas"/>116 <IsPartOfProject Value="True"/> 117 </Unit> 118 <Unit> 119 <Filename Value=" Console.pas"/>115 <Filename Value="Devices/Screen.pas"/> 116 <IsPartOfProject Value="True"/> 117 </Unit> 118 <Unit> 119 <Filename Value="Devices/Console.pas"/> 120 120 <IsPartOfProject Value="True"/> 121 121 </Unit> … … 158 158 <IsPartOfProject Value="True"/> 159 159 <ComponentName Value="FormMemory"/> 160 </Unit> 161 <Unit> 162 <Filename Value="Devices/Mouse.pas"/> 163 <IsPartOfProject Value="True"/> 160 164 </Unit> 161 165 </Units> … … 168 172 <SearchPaths> 169 173 <IncludeFiles Value="$(ProjOutDir)"/> 170 <OtherUnitFiles Value="Forms "/>174 <OtherUnitFiles Value="Forms;Devices"/> 171 175 <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)-$(BuildMode)"/> 172 176 </SearchPaths> -
branches/bigint/BigIntVM.lpr
r8 r12 11 11 Forms, FormMain, FormDisassembler, FormMemory, Cpu, IntMemory, Int, Machine, 12 12 DeviceManager, Screen, Console, Device, Assembler, Instructions, Parser, 13 Message, Disassembler, CommonPackage 13 Message, Disassembler, CommonPackage, Mouse 14 14 { you can add units after this }; 15 15 -
branches/bigint/Cpu.pas
r7 r12 10 10 11 11 TInstruction = (inNop, inHalt, inLoad, inLoadConst, inInput, inOutput, 12 inJump, inJumpZero, inJumpNotZero, inInc, inDec, inLoadIndex, inPush, inPop, 13 inCall, inRet, inLoadMem, inStoreMem); 12 inJump, inJumpZero, inJumpNotZero, inIncrement, inDecrement, inLoadIndex, 13 inPush, inPop, inCall, inReturn, inLoadMem, inStoreMem, inAdd, inSubtract, 14 inAnd, inOr, inXor, inShiftLeft, inShiftRight, inJumpRel, inJumpRelZero, 15 inJumpRelNotZero, inBitSet, inBitReset, inBitTest, inGetMaxInt, inGetMinInt); 14 16 15 17 { TCpu } … … 36 38 procedure InstructionJumpZero; 37 39 procedure InstructionJumpNotZero; 40 procedure InstructionJumpRel; 41 procedure InstructionJumpRelZero; 42 procedure InstructionJumpRelNotZero; 38 43 procedure InstructionPush; 39 44 procedure InstructionPop; 40 45 procedure InstructionCall; 41 46 procedure InstructionRet; 47 procedure InstructionAdd; 48 procedure InstructionSub; 49 procedure InstructionAnd; 50 procedure InstructionOr; 51 procedure InstructionXor; 52 procedure InstructionShl; 53 procedure InstructionShr; 54 procedure InstructionBitSet; 55 procedure InstructionBitReset; 56 procedure InstructionBitTest; 57 procedure InstructionGetMaxInt; 58 procedure InstructionGetMinInt; 42 59 procedure WriteMem(Address, Data: TInt); 43 60 function ReadMem(Address: TInt): TInt; … … 180 197 end; 181 198 199 procedure TCpu.InstructionJumpRel; 200 var 201 Addr: TInt; 202 begin 203 Addr := ReadMemPc; 204 PC := PC + Addr; 205 end; 206 207 procedure TCpu.InstructionJumpRelZero; 208 var 209 Condition: TInt; 210 Addr: TInt; 211 begin 212 Condition := ReadMemPc; 213 Addr := ReadMemPc; 214 if ReadMem(Condition) = 0 then PC := PC + Addr; 215 end; 216 217 procedure TCpu.InstructionJumpRelNotZero; 218 var 219 Condition: TInt; 220 Addr: TInt; 221 begin 222 Condition := ReadMemPc; 223 Addr := ReadMemPc; 224 if ReadMem(Condition) <> 0 then PC := PC + Addr; 225 end; 226 182 227 procedure TCpu.InstructionPush; 183 228 begin … … 202 247 begin 203 248 PC := Pop; 249 end; 250 251 procedure TCpu.InstructionAdd; 252 var 253 Dst, Src1, Src2: TInt; 254 begin 255 Dst := ReadMemPc; 256 Src1 := ReadMemPc; 257 Src2 := ReadMemPc; 258 WriteMem(Dst, ReadMem(Src1) + ReadMem(Src2)); 259 end; 260 261 procedure TCpu.InstructionSub; 262 var 263 Dst, Src1, Src2: TInt; 264 begin 265 Dst := ReadMemPc; 266 Src1 := ReadMemPc; 267 Src2 := ReadMemPc; 268 WriteMem(Dst, ReadMem(Src1) - ReadMem(Src2)); 269 end; 270 271 procedure TCpu.InstructionAnd; 272 var 273 Dst, Src1, Src2: TInt; 274 begin 275 Dst := ReadMemPc; 276 Src1 := ReadMemPc; 277 Src2 := ReadMemPc; 278 WriteMem(Dst, ReadMem(Src1) and ReadMem(Src2)); 279 end; 280 281 procedure TCpu.InstructionOr; 282 var 283 Dst, Src1, Src2: TInt; 284 begin 285 Dst := ReadMemPc; 286 Src1 := ReadMemPc; 287 Src2 := ReadMemPc; 288 WriteMem(Dst, ReadMem(Src1) or ReadMem(Src2)); 289 end; 290 291 procedure TCpu.InstructionXor; 292 var 293 Dst, Src1, Src2: TInt; 294 begin 295 Dst := ReadMemPc; 296 Src1 := ReadMemPc; 297 Src2 := ReadMemPc; 298 WriteMem(Dst, ReadMem(Src1) xor ReadMem(Src2)); 299 end; 300 301 procedure TCpu.InstructionShl; 302 var 303 Dst, Src, Shift: TInt; 304 begin 305 Dst := ReadMemPc; 306 Src := ReadMemPc; 307 Shift := ReadMemPc; 308 WriteMem(Dst, ReadMem(Src) shl ReadMem(Shift)); 309 end; 310 311 procedure TCpu.InstructionShr; 312 var 313 Dst, Src, Shift: TInt; 314 begin 315 Dst := ReadMemPc; 316 Src := ReadMemPc; 317 Shift := ReadMemPc; 318 WriteMem(Dst, ReadMem(Src) shr ReadMem(Shift)); 319 end; 320 321 procedure TCpu.InstructionBitSet; 322 var 323 Dst, Src, Bit: TInt; 324 begin 325 Dst := ReadMemPc; 326 Src := ReadMemPc; 327 Bit := ReadMemPc; 328 WriteMem(Dst, ReadMem(Src) or (1 << ReadMem(Bit))); 329 end; 330 331 procedure TCpu.InstructionBitReset; 332 var 333 Dst, Src, Bit: TInt; 334 begin 335 Dst := ReadMemPc; 336 Src := ReadMemPc; 337 Bit := ReadMemPc; 338 WriteMem(Dst, ReadMem(Src) and (-1 xor (1 << ReadMem(Bit)))); 339 end; 340 341 procedure TCpu.InstructionBitTest; 342 var 343 Dst, Src, Bit: TInt; 344 begin 345 Dst := ReadMemPc; 346 Src := ReadMemPc; 347 Bit := ReadMemPc; 348 WriteMem(Dst, (ReadMem(Src) >> ReadMem(Bit)) and 1); 349 end; 350 351 procedure TCpu.InstructionGetMaxInt; 352 var 353 Dst: TInt; 354 begin 355 Dst := ReadMemPc; 356 WriteMem(Dst, SizeOf(TInt) * 8); 357 end; 358 359 procedure TCpu.InstructionGetMinInt; 360 var 361 Dst: TInt; 362 begin 363 Dst := ReadMemPc; 364 // WriteMem(Dst, SizeOf(TInt) * 8); 204 365 end; 205 366 … … 281 442 Instructions[inJumpZero] := InstructionJumpZero; 282 443 Instructions[inJumpNotZero] := InstructionJumpNotZero; 283 Instructions[inInc] := InstructionInc; 284 Instructions[inDec] := InstructionDec; 444 Instructions[inJumpRel] := InstructionJumpRel; 445 Instructions[inJumpRelZero] := InstructionJumpRelZero; 446 Instructions[inJumpRelNotZero] := InstructionJumpRelNotZero; 447 Instructions[inIncrement] := InstructionInc; 448 Instructions[inDecrement] := InstructionDec; 285 449 Instructions[inPush] := InstructionPush; 286 450 Instructions[inPop] := InstructionPop; 287 451 Instructions[inCall] := InstructionCall; 288 Instructions[inRet] := InstructionRet; 452 Instructions[inReturn] := InstructionRet; 453 Instructions[inAdd] := InstructionAdd; 454 Instructions[inSubtract] := InstructionSub; 455 Instructions[inAnd] := InstructionAnd; 456 Instructions[inOr] := InstructionOr; 457 Instructions[inXor] := InstructionXor; 458 Instructions[inShiftLeft] := InstructionShl; 459 Instructions[inShiftRight] := InstructionShr; 460 Instructions[inBitSet] := InstructionBitSet; 461 Instructions[inBitReset] := InstructionBitReset; 462 Instructions[inBitTest] := InstructionBitTest; 463 Instructions[inGetMaxInt] := InstructionGetMaxInt; 464 Instructions[inGetMinInt] := InstructionGetMinInt; 289 465 end; 290 466 -
branches/bigint/Example.asm
r7 r12 1 VAR Count, 30 2 1 3 LDC (1000), Text 2 4 CALL PrintText -
branches/bigint/Forms/FormMain.lfm
r6 r12 11 11 OnDestroy = FormDestroy 12 12 OnShow = FormShow 13 LCLVersion = '3. 4.0.0'13 LCLVersion = '3.6.0.0' 14 14 object Memo1: TMemo 15 15 Left = 0 -
branches/bigint/Forms/FormMain.pas
r8 r12 18 18 private 19 19 procedure ConsoleWrite(Sender: TObject); 20 function MouseGetPosition: TPoint; 20 21 public 21 22 SubFormDisassembler: TFormDisassembler; … … 38 39 Machine := TMachine.Create; 39 40 Machine.Console.OnWrite := ConsoleWrite; 41 Machine.Mouse.OnGetPosition := MouseGetPosition; 40 42 end; 41 43 … … 81 83 end; 82 84 85 function TFormMain.MouseGetPosition: TPoint; 86 begin 87 Result := Mouse.CursorPos; 88 end; 89 83 90 end. 84 91 -
branches/bigint/Instructions.pas
r7 r12 78 78 AddNew(inLoadMem, 'LDM', [ptIndirect, ptIndirect2], 'Loads value from one indirect memory location to another.'); 79 79 AddNew(inStoreMem, 'STM', [ptIndirect2, ptIndirect], 'Stotes value to indirect memory location from source location.'); 80 AddNew(inInc , 'INC', [ptIndirect], 'Increments value in specified register.');81 AddNew(inDec , 'DEC', [ptIndirect], 'Decrements value in specified register.');80 AddNew(inIncrement, 'INC', [ptIndirect], 'Increments value in specified register.'); 81 AddNew(inDecrement, 'DEC', [ptIndirect], 'Decrements value in specified register.'); 82 82 AddNew(inInput, 'IN', [ptIndirect, ptIndirect], 'Reads value from input port to register.'); 83 83 AddNew(inOutput, 'OUT', [ptIndirect, ptIndirect], 'Writes value from register to output port.'); 84 84 AddNew(inJump, 'JP', [ptNumber], 'Unconditional absolute jump to defined address.'); 85 AddNew(inJumpZero, 'JPZ', [ptIndirect, ptNumber], 'Jumps to given address if value of register is zero'); 86 AddNew(inJumpNotZero, 'JPNZ', [ptIndirect, ptNumber], 'Jumps to given address if value of register is not zero'); 85 AddNew(inJumpZero, 'JPZ', [ptIndirect, ptNumber], 'Jumps to absolute address if value of register is zero'); 86 AddNew(inJumpNotZero, 'JPNZ', [ptIndirect, ptNumber], 'Jumps to absolute address if value of register is not zero'); 87 AddNew(inJumpRel, 'JR', [ptNumber], 'Unconditional relative jump to defined address.'); 88 AddNew(inJumpRelZero, 'JRZ', [ptIndirect, ptNumber], 'Jumps to relative address if value of register is zero'); 89 AddNew(inJumpRelNotZero, 'JRNZ', [ptIndirect, ptNumber], 'Jumps to relative address if value of register is not zero'); 87 90 AddNew(inPush, 'PUSH', [ptIndirect], 'Push memory location onto stack.'); 88 91 AddNew(inPop, 'POP', [ptIndirect], 'Pop item from stack and store it into memory location.'); 89 92 AddNew(inCall, 'CALL', [ptNumber], 'Call subroutine.'); 90 AddNew(inRet, 'RET', [], 'Return from subrotine.'); 93 AddNew(inReturn, 'RET', [], 'Return from subrotine.'); 94 AddNew(inAdd, 'ADD', [ptIndirect, ptIndirect, ptIndirect], 'Addition of two numbers.'); 95 AddNew(inSubtract, 'Sub', [ptIndirect, ptIndirect, ptIndirect], 'Subtraction of two numbers.'); 96 AddNew(inAnd, 'AND', [ptIndirect, ptIndirect, ptIndirect], 'Logical AND operation.'); 97 AddNew(inOr, 'OR', [ptIndirect, ptIndirect, ptIndirect], 'Logical OR operation.'); 98 AddNew(inXor, 'XOR', [ptIndirect, ptIndirect, ptIndirect], 'Logical XOR operation.'); 99 AddNew(inShiftLeft, 'SHL', [ptIndirect, ptIndirect, ptIndirect], 'Bitwise shift to the left.'); 100 AddNew(inShiftRight, 'SHR', [ptIndirect, ptIndirect, ptIndirect], 'Bitwise shift to the right.'); 101 AddNew(inBitSet, 'SET', [ptIndirect, ptIndirect, ptIndirect], 'Set specific bit.'); 102 AddNew(inBitReset, 'RES', [ptIndirect, ptIndirect, ptIndirect], 'Reset specific bit.'); 103 AddNew(inBitTest, 'BIT', [ptIndirect, ptIndirect, ptIndirect], 'Test of specific bit.'); 91 104 end; 92 105 -
branches/bigint/Machine.pas
r8 r12 4 4 5 5 uses 6 Classes, SysUtils, Cpu, IntMemory, Console, DeviceManager ;6 Classes, SysUtils, Cpu, IntMemory, Console, DeviceManager, Mouse; 7 7 8 8 type … … 11 11 12 12 TMachine = class 13 public 13 14 Cpu: TCpu; 14 15 Memory: TIntMemory; 15 16 Console: TConsole; 17 Mouse: TMouse; 16 18 DeviceManager: TDeviceManager; 17 19 constructor Create; … … 29 31 Memory.Size := 10000; 30 32 Console := TConsole.Create; 33 Mouse := TMouse.Create; 31 34 DeviceManager := TDeviceManager.Create; 32 35 DeviceManager.RegisterDevice(Console); 36 DeviceManager.RegisterDevice(Mouse); 33 37 Cpu := TCpu.Create; 34 38 Cpu.OnWriteMem := Memory.Write; … … 44 48 FreeAndNil(DeviceManager); 45 49 FreeAndNil(Console); 50 FreeAndNil(Mouse); 46 51 inherited; 47 52 end;
Note:
See TracChangeset
for help on using the changeset viewer.