Esempio n. 1
0
        private void Ror(string[] operands)
        {
            if (operands.Length == 2)
            {
                if (RegisterSyntax.TryParse(operands[0], out var register) && NumberSyntax.TryParse(operands[1], out byte number))
                {
                    if (number < 16)
                    {
                        _bytes.Add(((byte)Opcode.Ror, register.Index).Combine(), _currentLineNumber);
                        _bytes.Add(((byte)0x0, number).Combine(), _currentLineNumber);
                        return;
                    }
                    else
                    {
                        throw new AssemblyException("Number cannot be larger than 15.", _currentLineNumber);
                    }
                }
            }

            throw new AssemblyException("Invalid operands for ror instruction.", _currentLineNumber);
        }
Esempio n. 2
0
        private void Org(string[] operands)
        {
            bool invalidSyntax = false;

            if (operands.Length != 1)
            {
                invalidSyntax = true;
            }
            else if (NumberSyntax.TryParse(operands[0], out byte number))
            {
                _bytes.OriginAddress = number;
            }
            else
            {
                invalidSyntax = true;
            }

            if (invalidSyntax)
            {
                throw new AssemblyException("Expected a single number.", _currentLineNumber);
            }
        }
Esempio n. 3
0
        private void DataByte(string[] operands)
        {
            bool invalidSyntax = false;

            if (operands.Length == 0)
            {
                invalidSyntax = true;
            }
            else
            {
                foreach (string operand in operands)
                {
                    if (NumberSyntax.TryParse(operand, out byte number))
                    {
                        _bytes.Add(number, _currentLineNumber);
                    }
                    else if (StringLiteralSyntax.TryParse(operand, out string stringLiteral))
                    {
                        foreach (char c in stringLiteral)
                        {
                            _bytes.Add((byte)c, _currentLineNumber);
                        }
                    }
                    else
                    {
                        invalidSyntax = true;
                        break;
                    }
                }
            }

            if (invalidSyntax)
            {
                throw new AssemblyException("Expected a number or string literal.", _currentLineNumber);
            }
        }