public override OperatorOutput GenerateBinary(AssemblerState assemblerState, AsmLine asmLine) { if (string.IsNullOrWhiteSpace(asmLine.Label)) { assemblerState.RaiseError("IS must have a label."); } else { // TODO only integer constants and register substitutions are supported // register if (TryParseRegister(asmLine.Expr, out byte registerRef)) { assemblerState.DefineVariable(asmLine.Label, new RegisterCompilerVariable(registerRef)); } // constant else if (int.TryParse(asmLine.Expr, out int constant)) { assemblerState.DefineVariable(asmLine.Label, new ByteConstantAssemblerVariable((byte)constant)); } else { assemblerState.RaiseError($"IS expression, '{asmLine.Expr}' must be a constant integer or register reference."); } } return(new OperatorOutput()); }
public override OperatorOutput GenerateBinary(AssemblerState assemblerState, AsmLine asmLine) { List <byte> bytes = new List <byte>(); string[] args = new[] { asmLine.X, asmLine.Y, asmLine.Z }; foreach (var arg in args) { if (TryParseConstant(arg, out byte b)) { bytes.Add(b); } else if (arg.StartsWith('"') && arg.EndsWith('"')) { bytes.AddRange(Encoding.ASCII.GetBytes(arg.Trim('"'))); } else if (string.IsNullOrEmpty(arg)) { // do nothing } else { throw new Exception($"Unable to generate byte string. Unknown argument format: '{arg}'."); } } if (!string.IsNullOrEmpty(asmLine.Label)) { assemblerState.DefineVariable(asmLine.Label, new OctaConstantAssemblerVariable(assemblerState.ProgramCounter)); } return(new OperatorOutput() { Output = bytes.ToArray() }); }