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

61 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
namespace Lost.JIT.AMD64
{
public sealed class Pop: ProcessorInstruction
{
public Pop(InstructionOperand dest)
{
Dest = dest;
}
public InstructionOperand Dest
{
get;
set;
}
public override int? Size
{
get { throw new NotImplementedException(); }
}
public override void Compile(Stream destStream)
{
if (Dest is MemoryOperand)
{
var dest = Dest as MemoryOperand;
Rex rex = NeedsRex(dest);
if (rex != Rex.None) destStream.WriteByte((byte)rex);
destStream.WriteByte(0x8F);
WriteOperand(0, dest, destStream);
return;
}
if (Dest is GeneralPurposeRegister)
{
var dest = Dest as GeneralPurposeRegister;
if (dest.Size != 8) throw new NotSupportedException();
if (dest.Register.IsNew()) destStream.WriteByte((byte)Rex.NewRegOpcode);
destStream.WriteByte(0x58 + dest.Register.GetIndex());
return;
//destStream.WriteByte(ModRM(0, dest.Register, Registers.None));
}
throw new InvalidProgramException();
}
public override string OpCodeFASM
{
get { return "pop"; }
}
public override string ToFASM()
{
return string.Format(Dest is MemoryOperand? "pop qword {0}":"pop {0}", Dest);
}
}
}