mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-29 12:20:36 +00:00
45 lines
No EOL
1.2 KiB
C#
45 lines
No EOL
1.2 KiB
C#
using System;
|
|
using Mono.Cecil;
|
|
using Mono.Cecil.Cil;
|
|
using CPUx86 = Indy.IL2CPU.Assembler.X86;
|
|
|
|
namespace Indy.IL2CPU.IL.X86 {
|
|
[OpCode(Code.Stsfld)]
|
|
public class Stsfld: Op {
|
|
private string mDataName;
|
|
private int mSize;
|
|
|
|
public Stsfld(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
|
|
: base(aInstruction, aMethodInfo) {
|
|
FieldReference xField = (FieldReference)aInstruction.Operand;
|
|
mSize = Engine.GetFieldStorageSize(xField.FieldType);
|
|
Engine.QueueStaticField(xField, out mDataName);
|
|
}
|
|
|
|
public override void DoAssemble() {
|
|
for (int i = 1; i <= (mSize / 4); i++) {
|
|
new CPUx86.Pop(CPUx86.Registers.EAX);
|
|
new CPUx86.Move("dword [" + mDataName + " + 0x" + (mSize - (i * 4)).ToString("X") + "]", "eax");
|
|
}
|
|
switch (mSize % 4) {
|
|
case 1: {
|
|
new CPUx86.Pop(CPUx86.Registers.EAX);
|
|
new CPUx86.Move("byte [" + mDataName + "]", "al");
|
|
break;
|
|
}
|
|
case 2: {
|
|
new CPUx86.Pop(CPUx86.Registers.EAX);
|
|
new CPUx86.Move("word [" + mDataName + "]", "ax");
|
|
break;
|
|
}
|
|
case 0: {
|
|
break;
|
|
}
|
|
default:
|
|
throw new Exception("Remainder size " + (mSize % 4) + " not supported!");
|
|
|
|
}
|
|
Assembler.StackSizes.Pop();
|
|
}
|
|
}
|
|
} |