Changeset 185 for branches/virtualcpu4/UInstructionWriter.pas
- Timestamp:
- May 1, 2019, 9:48:46 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virtualcpu4/UInstructionWriter.pas
r184 r185 25 25 Prefix: Boolean; 26 26 procedure Init; 27 function GetRelativeAddr(BitWidth: TBitWidth; BaseIP, TargetAddr: QWord): Int64; 27 28 procedure Write8(Value: Byte); 28 29 procedure Write16(Value: Word); … … 132 133 end; 133 134 135 function TInstructionWriter.GetRelativeAddr(BitWidth: TBitWidth; BaseIP, TargetAddr: QWord): Int64; 136 begin 137 Result := Int64(TargetAddr) - (BaseIP + 1 + BitWidthBytes[BitWidth]); 138 end; 139 134 140 procedure TInstructionWriter.JumpRel(Addr: QWord); 135 141 var 136 NextIP: QWord;137 begin 138 PrefixBegin; 139 NextIP := IP + 1 + BitWidthBytes[Cpu.AddrSize];142 RelAddr: Int64; 143 begin 144 PrefixBegin; 145 RelAddr := GetRelativeAddr(AddrSize, IP, Addr); 140 146 Write8(Byte(opJumpRel)); 141 WriteAddressSigned( Int64(Addr) - Int64(NextIP));147 WriteAddressSigned(RelAddr); 142 148 PrefixEnd; 143 149 end; … … 145 151 procedure TInstructionWriter.JumpRelNotZero(Addr: QWord); 146 152 var 147 NextIP: QWord;148 begin 149 PrefixBegin; 150 NextIP := IP + 1 + BitWidthBytes[Cpu.AddrSize];153 RelAddr: Int64; 154 begin 155 PrefixBegin; 156 RelAddr := GetRelativeAddr(AddrSize, IP, Addr); 151 157 Write8(Byte(opJumpRelNotZero)); 152 WriteAddressSigned( Int64(Addr) - Int64(NextIP));158 WriteAddressSigned(RelAddr); 153 159 PrefixEnd; 154 160 end; … … 156 162 procedure TInstructionWriter.JumpRelZero(Addr: QWord); 157 163 var 158 NextIP: QWord;159 begin 160 PrefixBegin; 161 NextIP := IP + 1 + BitWidthBytes[Cpu.AddrSize];164 RelAddr: Int64; 165 begin 166 PrefixBegin; 167 RelAddr := GetRelativeAddr(AddrSize, IP, Addr); 162 168 Write8(Byte(opJumpRelZero)); 163 WriteAddressSigned( Int64(Addr) - Int64(NextIP));169 WriteAddressSigned(RelAddr); 164 170 PrefixEnd; 165 171 end; … … 360 366 begin 361 367 case AddrSize of 362 bw8: Write8(Value );363 bw16: Write16(Value );364 bw32: Write32(Value );368 bw8: Write8(Value and $ff); 369 bw16: Write16(Value and $ffff); 370 bw32: Write32(Value and $ffffffff); 365 371 bw64: Write64(Value); 366 372 end; … … 370 376 begin 371 377 case AddrSize of 372 bw8: Write8(Byte(Value ));373 bw16: Write16(Word(Value ));374 bw32: Write32(DWord(Value ));378 bw8: Write8(Byte(Value and $ff)); 379 bw16: Write16(Word(Value and $ffff)); 380 bw32: Write32(DWord(Value and $ffffffff)); 375 381 bw64: Write64(QWord(Value)); 376 382 end; … … 380 386 begin 381 387 case DataSize of 382 bw8: Write8(Value );383 bw16: Write16(Value );384 bw32: Write32(Value );388 bw8: Write8(Value and $ff); 389 bw16: Write16(Value and $ffff); 390 bw32: Write32(Value and $ffffffff); 385 391 bw64: Write64(Value); 386 392 end;
Note:
See TracChangeset
for help on using the changeset viewer.