- Timestamp:
- Nov 16, 2023, 2:01:59 PM (12 months ago)
- Location:
- branches/ByteArray
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ByteArray/BigInt.pas
r51 r52 47 47 class operator GreaterThanOrEqual(A, B: TBigInt): Boolean; 48 48 procedure Shrink; 49 function IsNegative: Boolean; 50 function IsZero: Boolean; 51 function IsPositive: Boolean; 49 52 procedure SetByteArray(AData: TArrayOfByte; ASize: TBigIntSize); 50 53 procedure GetByteArray(var AData: TArrayOfByte; ASize: TBigIntSize); 51 54 function Copy(Size: TBigIntSize): TBigInt; 52 property Size: Byte read GetSize write SetSize;55 property Size: TBigIntSize read GetSize write SetSize; 53 56 property Data[Index: TBigIntSize]: Byte read GetData write SetData; 54 57 end; … … 85 88 procedure TBigInt.SetData(Index: TBigIntSize; AValue: Byte); 86 89 begin 87 if Index > Size- 1 then Size := Index + 1;90 if Index > Integer(Size) - 1 then Size := Index + 1; 88 91 FData[Index] := AValue; 89 92 end; … … 241 244 Carry: Byte; 242 245 begin 243 Result.Size := A.Size;246 Result.Size := Max(A.Size, B.Size); 244 247 Carry := 0; 245 248 I := 0; … … 259 262 begin 260 263 Result := A.Size = B.Size; 264 if not Result then Exit; 261 265 for I := 0 to A.Size - 1 do 262 266 if A.FData[I] <> B.FData[I] then begin … … 271 275 begin 272 276 Result := A.Size = B.Size; 277 if not Result then Exit; 273 278 for I := 0 to A.Size - 1 do 274 279 if A.FData[I] <> B.FData[I] then begin … … 280 285 281 286 class operator TBigInt.LessThan(A, B: TBigInt): Boolean; 282 begin 283 287 var 288 Temp: TBigInt; 289 begin 290 Temp := A - B; 291 Result := Temp.IsNegative; 284 292 end; 285 293 286 294 class operator TBigInt.LessThanOrEqual(A, B: TBigInt): Boolean; 287 begin 288 295 var 296 Temp: TBigInt; 297 begin 298 Temp := A - B; 299 Result := Temp.IsNegative or Temp.IsZero; 289 300 end; 290 301 291 302 class operator TBigInt.GreaterThan(A, B: TBigInt): Boolean; 292 begin 293 303 var 304 Temp: TBigInt; 305 begin 306 Temp := A - B; 307 Result := Temp.IsPositive and not Temp.IsZero; 294 308 end; 295 309 296 310 class operator TBigInt.GreaterThanOrEqual(A, B: TBigInt): Boolean; 297 begin 298 311 var 312 Temp: TBigInt; 313 begin 314 Temp := A - B; 315 Result := Temp.IsPositive; 299 316 end; 300 317 … … 307 324 Dec(I); 308 325 Size := I + 1; 326 end; 327 328 function TBigInt.IsNegative: Boolean; 329 begin 330 Result := (FData[Size - 1] and $80) = $80; 331 end; 332 333 function TBigInt.IsZero: Boolean; 334 var 335 I: TBigIntSize; 336 begin 337 Result := True; 338 for I := 0 to Size - 1 do 339 if FData[I] <> 0 then begin 340 Result := False; 341 Break; 342 end; 343 end; 344 345 function TBigInt.IsPositive: Boolean; 346 begin 347 Result := (FData[Size - 1] and $80) = 0; 309 348 end; 310 349 … … 329 368 4: PDWord(@Result.FData[0])^ := PDWord(@FData[0])^; 330 369 8: PQWord(@Result.FData[0])^ := PQWord(@FData[0])^; 370 else Move(PByte(@FData[0])^, PByte(@Result.FData[0])^, Size); 331 371 end; 332 372 end; -
branches/ByteArray/Cpu.pas
r50 r52 101 101 IO: TChannel; 102 102 function Read(Size: TBigIntSize): TBigInt; 103 function ReadSize: TBigIntSize; 103 104 function ReadRegIndex: TRegIndex; 104 105 procedure Write(Size: TBigIntSize; Value: TBigInt); … … 173 174 DataSize: TBigIntSize; 174 175 begin 175 DataSize := Read (SizeOf(TBigIntSize));176 DataSize := ReadSize; 176 177 RegIndex := ReadRegIndex; 177 178 Regs[RegIndex] := Read(DataSize); … … 194 195 RegIndex2: TRegIndex; 195 196 begin 196 DataSize := Read (SizeOf(TBigIntSize));197 DataSize := ReadSize; 197 198 RegIndex := ReadRegIndex; 198 199 RegIndex2 := ReadRegIndex; … … 217 218 RegIndex: TRegIndex; 218 219 begin 219 DataSize := Read (SizeOf(TBigIntSize));220 DataSize := ReadSize; 220 221 AddressSize := Read(SizeOf(TBigIntSize)); 221 222 RegIndex := ReadRegIndex; … … 241 242 RegIndex: TRegIndex; 242 243 begin 243 DataSize := Read (SizeOf(TBigIntSize));244 DataSize := ReadSize; 244 245 AddressSize := Read(SizeOf(TBigIntSize)); 245 246 Address := Read(AddressSize); … … 279 280 AddressSize: TBigIntSize; 280 281 begin 281 DataSize := Read (SizeOf(TBigIntSize));282 DataSize := ReadSize; 282 283 AddressSize := Read(SizeOf(TBigIntSize)); 283 284 RegIndex := ReadRegIndex; … … 305 306 AddressSize: TBigIntSize; 306 307 begin 307 DataSize := Read (SizeOf(TBigIntSize));308 DataSize := ReadSize; 308 309 AddressSize := Read(SizeOf(TBigIntSize)); 309 310 RegIndex := ReadRegIndex; … … 322 323 AddressSize: TBigIntSize; 323 324 begin 324 AddressSize := Read (SizeOf(TBigIntSize));325 AddressSize := ReadSize; 325 326 PC := PC + Read(AddressSize); 326 327 end; … … 336 337 AddressSize: TBigIntSize; 337 338 begin 338 AddressSize := Read (SizeOf(TBigIntSize));339 AddressSize := ReadSize; 339 340 Push(PC, AddressSize); 340 341 PC := Read(AddressSize); … … 350 351 AddressSize: TBigIntSize; 351 352 begin 352 AddressSize := Read (SizeOf(TBigIntSize));353 AddressSize := ReadSize; 353 354 PC := Pop(AddressSize); 354 355 end; … … 367 368 RegIndex: TRegIndex; 368 369 begin 369 DataSize := Read (SizeOf(TBigIntSize));370 DataSize := ReadSize; 370 371 RegIndex := ReadRegIndex; 371 372 Push(Regs[RegIndex], DataSize); … … 385 386 RegIndex: TRegIndex; 386 387 begin 387 DataSize := Read (SizeOf(TBigIntSize));388 DataSize := ReadSize; 388 389 RegIndex := ReadRegIndex; 389 390 Regs[RegIndex] := Pop(DataSize); … … 406 407 DataSize: TBigIntSize; 407 408 begin 408 DataSize := Read (SizeOf(TBigIntSize));409 DataSize := ReadSize; 409 410 RegIndex := ReadRegIndex; 410 411 RegIndex2 := ReadRegIndex; … … 428 429 DataSize: TBigIntSize; 429 430 begin 430 DataSize := Read (SizeOf(TBigIntSize));431 DataSize := ReadSize; 431 432 RegIndex := ReadRegIndex; 432 433 RegIndex2 := ReadRegIndex; … … 447 448 DataSize: TBigIntSize; 448 449 begin 449 DataSize := Read (SizeOf(TBigIntSize));450 DataSize := ReadSize; 450 451 RegIndex := ReadRegIndex; 451 452 Regs[RegIndex] := Regs[RegIndex].Copy(DataSize) + 1; … … 465 466 DataSize: TBigIntSize; 466 467 begin 467 DataSize := Read (SizeOf(TBigIntSize));468 DataSize := ReadSize; 468 469 RegIndex := ReadRegIndex; 469 470 Regs[RegIndex] := Regs[RegIndex].Copy(DataSize) - 1; … … 519 520 Result := Memory.Read(PC, Size); 520 521 PC := PC + Size; 522 end; 523 524 function TCpu.ReadSize: TBigIntSize; 525 begin 526 Result := Read(SizeOf(TBigIntSize)); 521 527 end; 522 528 -
branches/ByteArray/Disassembler.pas
r46 r52 114 114 end; 115 115 116 117 116 end. 118 117
Note:
See TracChangeset
for help on using the changeset viewer.