Cosmos/source/Lost/Assembler/JIT/AMD64/Jump.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

60 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Lost.JIT.AMD64
{
[Serializable]
public sealed class Jump: ProcessorInstruction
{
public Jump(InstructionOperand operand)
{
Dest = operand;
}
public InstructionOperand Dest { get; set; }
public override int? Size
{
get { throw new NotImplementedException(); }
}
public override void Compile(Stream destStream)
{
if (Dest is ImmediateOperand)
{
var dest = Dest as ImmediateOperand;
if (dest.Value.FitsInSByte())
{
destStream.WriteByte(0xEB);
destStream.WriteSByte(dest.Value);
} else
{
destStream.WriteByte(0xE9);
destStream.WriteInt(dest.Value);
}
return;
}
throw new NotImplementedException();
}
public override string OpCodeFASM
{
get { return "jmp"; }
}
public override string ToFASM()
{
if (Dest is ImmediateOperand)
{
var dest = Dest as ImmediateOperand;
return string.Format("jmp {0}", dest.Value + (dest.Value.FitsInSByte()? 2: 5));
}
throw new NotImplementedException();
}
}
}