Cosmos/source/Lost/Assembler/JIT/AMD64/ConditionalJumpInstruction.cs
LostTheBlack_cp 3060b02e0c AMD64 assembler:
[-] some unnecessary overloads
[+] overloaded operators in order to allow defining memory operands easily
[+] overloaded automatic conversions to allow operands
[+] Labels support
[+] code generator based on F# started
2008-05-09 11:29:38 +00:00

47 lines
1,017 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Lost.JIT.AMD64
{
[Serializable]
public abstract class ConditionalJumpInstruction: ProcessorInstruction
{
public ConditionalJumpInstruction(int targetOffset)
{
TargetOffset = targetOffset;
}
public int TargetOffset { get; set; }
public override int? Size
{
get { throw new NotImplementedException(); }
}
public override void Compile(Stream destStream)
{
if (TargetOffset.FitsInSByte())
{
destStream.WriteByte(OpcodeBase);
destStream.WriteSByte(TargetOffset);
return;
} else
{
destStream.WriteByte(0x0F);
destStream.WriteByte(OpcodeBase + 0x10);
destStream.WriteInt(TargetOffset);
}
}
protected abstract int OpcodeBase { get; }
public override string ToFASM()
{
return string.Format("{0} {1}", OpCodeFASM,
TargetOffset + (TargetOffset.FitsInSByte() ? 2 : 6));
}
}
}