Exemplo n.º 1
0
        public override void Interpret(SourceCrawler sourceCrawler, BinaryWriter output, bool isLabelScan)
        {
            // Eat whitespace to right of mnemonic
            sourceCrawler.EatWhitespace();

            // Peek to make sure next character is a register delimiter, otherwise we return
            if (sourceCrawler.Peek() == CompilerSettings.LabelDelimiter)
            {
                // Pass over the register delimiter
                sourceCrawler.CurrentNdx++;
                // Read the register
                uint location = sourceCrawler.ReadLabelLocation();


                // This instruction is 1 byte for instruction, and 1 word for location
                sourceCrawler.AssemblyLength += (uint)(1 + CompilerSettings.WORD_LENGTH);

                // If this is not a label scanning pass, write to output
                if (!isLabelScan)
                {
                    output.Write(ByteCodes[0]); // 0x0C
                    output.Write(location);
                }
            }
            else if (sourceCrawler.Peek() == CompilerSettings.LiteralDelimiter)
            {
                // Pass over the register delimiter
                sourceCrawler.CurrentNdx++;
                // Read the register
                uint location = sourceCrawler.ReadWordValue();

                // This instruction is 1 byte for instruction, and 1 word for location
                sourceCrawler.AssemblyLength += (uint)(1 + CompilerSettings.WORD_LENGTH);

                // If this is not a label scanning pass, write to output
                if (!isLabelScan)
                {
                    output.Write(ByteCodes[0]); // 0x0C
                    output.Write(location);
                }
            }
            else
            if (sourceCrawler.Peek() == CompilerSettings.RegisterDelimiter)
            {
                // Pass over the register delimiter
                sourceCrawler.CurrentNdx++;
                // Read the register
                RegisterAddress sourceRegister = sourceCrawler.ReadRegister();

                // This instruction is 1 byte for instruction, and 1 word for location
                sourceCrawler.AssemblyLength += (uint)(1 + 1);

                // If this is not a label scanning pass, write to output
                if (!isLabelScan)
                {
                    output.Write(ByteCodes[1]); // 0x4C
                    output.Write((byte)sourceRegister);
                }
            }
        }
        public void FIX3_is_supported()
        {
            var bytes = new Span <byte>(new byte[]
            {
                0, 0, 24, 242
            }).ToArray();

            var modbusConnection = Substitute.For <IModbusConnection>();

            modbusConnection.Read(Arg.Any <byte>(), Arg.Any <ushort>()).Returns(bytes);

            var factory = Substitute.For <IModbusConnectionFactory>();

            factory.GetConnection().Returns(modbusConnection);

            var address = new RegisterAddress(12345, RegisterAddressType.S32, RegisterAddressFormat.FIX3,
                                              new RegisterDescription(Language.English, "Description"));

            Connector.ModbusConnectionFactory = factory;
            var connector = new Connector();

            connector.TryRegisterDevice(1, IPAddress.Any, out var id);

            var result = connector.GetDataForAddress(id, address);

            result.Value.GetType().Should().Be(typeof(double));
            result.Value.Should().Be(6.386);
        }
Exemplo n.º 3
0
        /// <summary>Sets a parameter to the passed in value</summary>
        /// <param name="param">Parameter to set</param>
        /// <param name="value">Value to set</param>
        public void SetParam(RegisterAddress param, uint value)
        {
            this.WriteByte((byte)((byte)Command.SetParam | (byte)param));

            switch (param)
            {
            case RegisterAddress.AbsPos:
            case RegisterAddress.Mark:
            case RegisterAddress.Speed:
                this.WriteByte((byte)(value >> 16));
                this.WriteByte((byte)(value >> 8));
                this.WriteByte((byte)value);

                break;

            case RegisterAddress.Acc:
            case RegisterAddress.Dec:
            case RegisterAddress.MaxSpeed:
            case RegisterAddress.MinSpeed:
            case RegisterAddress.FsSpd:
            case RegisterAddress.IntSpd:
            case RegisterAddress.Config:
            case RegisterAddress.Status:
                this.WriteByte((byte)(value >> 8));
                this.WriteByte((byte)value);

                break;

            default:
                this.WriteByte((byte)value);

                break;
            }
        }
Exemplo n.º 4
0
        /// <summary>Get a value for a given parameter</summary>
        /// <param name="param">Parameter to retrieve</param>
        /// <returns></returns>
        public uint GetParam(RegisterAddress param)
        {
            uint rx = (uint)this.WriteByte((byte)((byte)Command.GetParam | (byte)param)) << 24;

            switch (param)
            {
            case RegisterAddress.AbsPos:
            case RegisterAddress.Mark:
            case RegisterAddress.Speed:
                rx |= (uint)((this.WriteByte(0x00) << 16) | (this.WriteByte(0x00) << 8) | this.WriteByte(0x00));

                break;

            case RegisterAddress.Acc:
            case RegisterAddress.Dec:
            case RegisterAddress.MaxSpeed:
            case RegisterAddress.MinSpeed:
            case RegisterAddress.FsSpd:
            case RegisterAddress.IntSpd:
            case RegisterAddress.Config:
            case RegisterAddress.Status:
                rx |= (uint)((this.WriteByte(0x00) << 8) | this.WriteByte(0x00));

                break;

            default:
                rx |= (uint)this.WriteByte(0x00);

                break;
            }

            return(rx);
        }
Exemplo n.º 5
0
        public override void Interpret(SourceCrawler sourceCrawler, BinaryWriter output, bool isLabelScan)
        {
            // Eat whitespace to right of mnemonic
            sourceCrawler.EatWhitespace();

            // Peek to make sure next character is a register delimiter, otherwise we return
            if (sourceCrawler.Peek() == CompilerSettings.RegisterDelimiter)
            {
                // Pass over the register delimiter
                sourceCrawler.CurrentNdx++;
                // Read the register
                RegisterAddress targetRegister = sourceCrawler.ReadRegister();
                // Eat the whitespace leading to next parameter
                sourceCrawler.EatWhitespace();

                if (sourceCrawler.Peek() == CompilerSettings.RegisterDelimiter)
                {
                    // Pass over delimiter
                    sourceCrawler.CurrentNdx++;
                    // Read register
                    RegisterAddress sourceRegister = sourceCrawler.ReadRegister();

                    // This instruction is 3 bytes wide
                    sourceCrawler.AssemblyLength += 3;

                    // If this is not a label scanning pass, write to output
                    if (!isLabelScan)
                    {
                        output.Write(ByteCodes[0]); // 0x37
                        output.Write((byte)targetRegister);
                        output.Write((byte)sourceRegister);
                    }
                }
            }
        }
        The_result_contains_the_description_in_the_first_available_language_if_the_preferred_language_is_missing()
        {
            var bytes = new Span <byte>(new byte[]
            {
                0, 0, 1, 187
            }).ToArray();

            var modbusConnection = Substitute.For <IModbusConnection>();

            modbusConnection.Read(3, 12345).Returns(bytes);

            var factory = Substitute.For <IModbusConnectionFactory>();

            factory.GetConnection().Returns(modbusConnection);

            Connector.ModbusConnectionFactory = factory;

            // In german
            var connector = new Connector {
                PreferedDescriptionLanguage = Language.German
            };

            connector.TryRegisterDevice(3, IPAddress.Parse("192.168.1.1"), out var id);

            var registerAddress = new RegisterAddress(12345, RegisterAddressType.S32, RegisterAddressFormat.FIX0,
                                                      new RegisterDescription(Language.English, "Description"));

            var result = connector.GetDataForAddress(id, registerAddress);

            result.FriendlyDescription.Should().Be("Description (12345) = 443");
        }
Exemplo n.º 7
0
        internal Result(Guid id, RegisterAddress registerAddress, Language language, object value)
        {
            Id = id;
            RegisterAddress = registerAddress;
            Value           = value;

            SetFriendlyDescription(language);
        }
Exemplo n.º 8
0
        public override void Interpret(SourceCrawler sourceCrawler, BinaryWriter output, bool isLabelScan)
        {
            // Eat whitespace to right of mnemonic
            sourceCrawler.EatWhitespace();

            // Peek to make sure next character is a register delimiter, otherwise we return
            if (sourceCrawler.Peek() == CompilerSettings.RegisterDelimiter)
            {
                // Pass over the register delimiter
                sourceCrawler.CurrentNdx++;
                // Read the register
                RegisterAddress targetRegister = sourceCrawler.ReadRegister();
                // Eat the whitespace leading to next parameter
                sourceCrawler.EatWhitespace();

                // Peek at the next character, if it is a literal delimiter, we parse a literal, otherwise we parse a register
                if (sourceCrawler.Peek() == CompilerSettings.LiteralDelimiter)
                {
                    // Pass over delimiter
                    sourceCrawler.CurrentNdx++;
                    // Read hard-coded location
                    uint location = sourceCrawler.ReadWordValue();

                    // Add the correct size to the assembly length
                    sourceCrawler.AssemblyLength += (uint)(1 + 1 + CompilerSettings.WORD_LENGTH);

                    // If this is not a label scanning pass, write to output
                    if (!isLabelScan)
                    {
                        output.Write(ByteCodes[0]); // 0x18
                        output.Write((byte)targetRegister);
                        output.Write(location);
                    }
                }
                // This is not a literal location, check for register
                else if (sourceCrawler.Peek() == CompilerSettings.RegisterDelimiter)
                {
                    // Pass over delimiter
                    sourceCrawler.CurrentNdx++;
                    // Read register
                    RegisterAddress sourceRegister = sourceCrawler.ReadRegister();

                    // This instruction is 3 bytes wide
                    sourceCrawler.AssemblyLength += 3;

                    // If this is not a label scanning pass, write to output
                    if (!isLabelScan)
                    {
                        output.Write(ByteCodes[1]); // 0x19
                        output.Write((byte)targetRegister);
                        output.Write((byte)sourceRegister);
                    }
                }
            }
        }
        /// <summary>
        /// Executes this instruction on a machine.
        /// </summary>
        /// <param name="machine">The machine to execute the instruction on</param>
        /// <returns>The machine after the instruction was applied.</returns>
        public Machine Apply(Machine machine)
        {
            if (machine.Memory.Read(RegisterAddress.FromInt(0)) == 0)
            {
                machine.JumpToInstruction(Target.GetIndex() - 1);
            }
            else
            {
                machine.NextInstruction();
            }

            return(machine);
        }
Exemplo n.º 10
0
        public dynamic Register(RegisterAddress vm)
        {
            if (!Uri.TryCreate(vm.Address, UriKind.Absolute, out var uri))
            {
                return(BadRequest("Address is not well formed URI"));
            }

            blockchain.Register(uri);

            return(Ok(new
            {
                message = "New node has been added",
                total_nodes = blockchain.Nodes
            }));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Parses a single instruction.
        /// </summary>
        /// <param name="context">The Parsing sub-context</param>
        /// <returns>The Instruction wrapped in an IToken</returns>
        protected static IToken ParseInstruction(ParseContext context)
        {
            var tokens          = context.Source.Split(' ', ',');
            var instructionName = tokens[0];

            switch (instructionName)
            {
            case "MOV":
                if (Register.IsRegister(tokens[1]))
                {
                    return(InstructionToToken(new CopyMoveInstruction(RegisterAddress.FromString(tokens[1]), RegisterAddress.FromString(tokens[2]))));
                }
                else
                {
                    return(InstructionToToken(new StoreMoveInstruction(uint.Parse(tokens[1]), RegisterAddress.FromString(tokens[2]))));
                }

            case "ADD":
                return(InstructionToToken(new AddInstruction(RegisterAddress.FromString(tokens[1]), RegisterAddress.FromString(tokens[2]))));

            case "DEC":
                return(InstructionToToken(new DecrementInstruction(RegisterAddress.FromString(tokens[1]))));

            case "INC":
                return(InstructionToToken(new IncrementInstruction(RegisterAddress.FromString(tokens[1]))));

            case "INV":
                return(InstructionToToken(new InverseInstruction(RegisterAddress.FromString(tokens[1]))));

            case "JMP":
                var jumpIndex = int.Parse(tokens[1]);
                return(InstructionToToken(new JumpInstruction(RegisterAddress.FromInt(jumpIndex))));

            case "JZ":
                var jumpZeroIndex = int.Parse(tokens[1]);
                return(InstructionToToken(new JumpZeroInstruction(RegisterAddress.FromInt(jumpZeroIndex))));

            case "CALL":
                return(new CallToken(ParseLabelName(context.Source)));

            case "NOP":
                return(InstructionToToken(new NoOperationInstruction()));

            default:
                throw new Exception($"FATAL: Unknown instruction '{instructionName}'");
            }
        }
Exemplo n.º 12
0
        public async Task <IActionResult> AddAddress(
            [FromServices] ICommandHandlerResolver bus,
            [FromServices] AddressCrabEditClient editClient,
            [FromServices] Func <IAddresses> getAddresses,
            [FromBody] AddAddressRequest request,
            CancellationToken cancellationToken)
        {
            // TODO: Turn this into proper VBR API Validation
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var crabAddAddress = await AddToCrab(editClient, request, cancellationToken);

            var addressId = crabAddAddress.Result;

            // todo: add command implementation for BoxNumber
            var command = new RegisterAddress(
                addressId,
                StreetNameId.CreateForPersistentId(request.StreetNameId.AsIdentifier().Map(IdentifierMappings.StreetNameId)),
                PostalCode.CreateForPersistentId(request.PostalCode.AsIdentifier().Map(IdentifierMappings.PostalCode)),
                new HouseNumber(request.HouseNumber),
                new BoxNumber(request.BoxNumber));

            var position = await bus.Dispatch(
                Guid.NewGuid(),
                command,
                GetMetadata(),
                cancellationToken);

            // Because we don't use the addressId as an identifier, we are stuck with the mess of retrieving our aggregate
            // and getting the surrogate identifier from it.... PersistentLocalIdentifier
            var addresses = getAddresses();

            var address = await addresses.GetOptionalAsync(addressId, cancellationToken);

            if (!address.HasValue)
            {
                throw new ApiException("Er is een fout opgetreden.", StatusCodes.Status500InternalServerError);
            }

            return(CreatedWithPosition(
                       $"/v1/adressen/{address.Value.PersistentLocalId}",
                       position,
                       crabAddAddress.ExecutionTime));
        }
Exemplo n.º 13
0
        public Result GetDataForAddress(Guid deviceId, RegisterAddress registerAddress)
        {
            WriteLineToConsole($"Get data for register {registerAddress.Register} for device {deviceId} ...");

            if (!registerAddress.Descriptions.Any())
            {
                throw new MissingDescriptionAttributeException();
            }

            var deviceFound = Devices.TryGetValue(deviceId, out var deviceRegistration);

            if (!deviceFound)
            {
                WriteLineToConsole("\tDevice not found. Use TryRegisterDevice to add a device.");
                throw new DeviceNotFoundException();
            }

            Result result;

            switch (registerAddress.Type)
            {
            case RegisterAddressType.S32:
                var s32Result =
                    deviceRegistration.ReaderReader.ReadS32(deviceRegistration.Unit, registerAddress.Register);
                var s32Value = ParseResultForValue(s32Result, registerAddress.Format);
                result = new Result(deviceId, registerAddress, PreferedDescriptionLanguage, s32Value);
                break;

            case RegisterAddressType.U32:
                var u32Result =
                    deviceRegistration.ReaderReader.ReadU32(deviceRegistration.Unit, registerAddress.Register);
                var u32Value = ParseResultForValue(u32Result, registerAddress.Format);
                result = new Result(deviceId, registerAddress, PreferedDescriptionLanguage, u32Value);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            WriteLineToConsole("");
            WriteLineToConsole(result.ToString());
            WriteLineToConsole("");

            return(result);
        }
Exemplo n.º 14
0
        public RegisterAddress ReadRegister()
        {
            RegisterAddress result = RegisterAddress.Unknown;

            string str = "";

            while (!char.IsWhiteSpace(Peek()))
            {
                str += Get();
            }

            if (REGISTER_NAMES.Contains(str))
            {
                result = (RegisterAddress)Enum.Parse(typeof(RegisterAddress), str);
            }

            return(result);
        }
Exemplo n.º 15
0
        public override void Interpret(SourceCrawler sourceCrawler, BinaryWriter output, bool isLabelScan)
        {
            // Eat whitespace to right of mnemonic
            sourceCrawler.EatWhitespace();

            // Peek to make sure next character is a register delimiter, otherwise we return
            if (sourceCrawler.Peek() == CompilerSettings.RegisterDelimiter)
            {
                // Pass over the register delimiter
                sourceCrawler.CurrentNdx++;
                // Read the register
                RegisterAddress targetRegister = sourceCrawler.ReadRegister();

                // Add the correct size to the assembly length
                sourceCrawler.AssemblyLength += (uint)(1 + 1);

                // If this is not a label scanning pass, write to output
                if (!isLabelScan)
                {
                    output.Write(ByteCodes[0]); // 0x17
                    output.Write((byte)targetRegister);
                }
            }
        }
Exemplo n.º 16
0
        public override void Interpret(SourceCrawler sourceCrawler, BinaryWriter output, bool isLabelScan)
        {
            // Eat whitespace to right of mnemonic
            sourceCrawler.EatWhitespace();

            if (sourceCrawler.Peek() == CompilerSettings.RegisterDelimiter)
            {
                // Pass over delimiter
                sourceCrawler.CurrentNdx++;
                // Read register
                RegisterAddress destinationRegister = sourceCrawler.ReadRegister();


                // This instruction is 3 bytes wide
                sourceCrawler.AssemblyLength += (1 + 1);

                // If this is not a label scanning pass, write to output
                if (!isLabelScan)
                {
                    output.Write(ByteCodes[0]); // 0x35
                    output.Write((byte)destinationRegister);
                }
            }
        }
Exemplo n.º 17
0
 /// <summary>
 /// Constructs a Inverse Instruction
 /// </summary>
 /// <param name="target">The address of the value that should be inverted</param>
 public InverseInstruction(RegisterAddress target)
 {
     Target = target;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Constructs a Register.
 /// </summary>
 /// <param name="address">The address of the Register.</param>
 /// <param name="value">The value of the Register</param>
 public Register(RegisterAddress address, uint value)
 {
     Address = address;
     Value   = value;
 }
Exemplo n.º 19
0
 /// <summary>
 /// Constructs a Jump Instruction
 /// </summary>
 /// <param name="target">The address of the index that should be jumped to.</param>
 public JumpInstruction(RegisterAddress target)
 {
     Target = target;
 }
Exemplo n.º 20
0
        public override void Interpret(SourceCrawler sourceCrawler, BinaryWriter output, bool isLabelScan)
        {
            // Eat whitespace to right of mnemonic
            sourceCrawler.EatWhitespace();

            // Peek to make sure next character is a register delimiter, otherwise we return
            if (sourceCrawler.Peek() == CompilerSettings.RegisterDelimiter)
            {
                // Pass over the register delimiter
                sourceCrawler.CurrentNdx++;
                // Read the register
                RegisterAddress targetRegister = sourceCrawler.ReadRegister();
                // Eat the whitespace leading to next parameter
                sourceCrawler.EatWhitespace();

                // Peek at the next character, if it is a literal delimiter, we parse a literal, otherwise we parse a register
                if (sourceCrawler.Peek() == CompilerSettings.LiteralDelimiter)
                {
                    // Pass over delimiter
                    sourceCrawler.CurrentNdx++;
                    // Read hard-coded location
                    uint value = sourceCrawler.ReadWordValue();

                    // Eat whitepace to next delimiter
                    sourceCrawler.EatWhitespace();

                    // Make sure we have a target register
                    if (sourceCrawler.Peek() == CompilerSettings.RegisterDelimiter)
                    {
                        sourceCrawler.CurrentNdx++;
                        RegisterAddress destinationRegister = sourceCrawler.ReadRegister();

                        // Add the correct size to the assembly length
                        sourceCrawler.AssemblyLength += (uint)(1 + 1 + CompilerSettings.WORD_LENGTH + 1);

                        // If this is not a label scanning pass, write to output
                        if (!isLabelScan)
                        {
                            output.Write(ByteCodes[0]); // 0x20
                            output.Write((byte)targetRegister);
                            output.Write(value);
                            output.Write((byte)destinationRegister);
                        }
                    }
                }
                // This is not a literal location, check for register
                else if (sourceCrawler.Peek() == CompilerSettings.RegisterDelimiter)
                {
                    // Pass over delimiter
                    sourceCrawler.CurrentNdx++;
                    // Read register
                    RegisterAddress sourceRegister = sourceCrawler.ReadRegister();
                    sourceCrawler.EatWhitespace();

                    // Make sure we have a target register
                    if (sourceCrawler.Peek() == CompilerSettings.RegisterDelimiter)
                    {
                        sourceCrawler.CurrentNdx++;
                        RegisterAddress destinationRegister = sourceCrawler.ReadRegister();

                        // This instruction is 3 bytes wide
                        sourceCrawler.AssemblyLength += (1 + 1 + 1 + 1);

                        // If this is not a label scanning pass, write to output
                        if (!isLabelScan)
                        {
                            output.Write(ByteCodes[1]); // 0x21
                            output.Write((byte)targetRegister);
                            output.Write((byte)sourceRegister);
                            output.Write((byte)destinationRegister);
                        }
                    }
                }
                else
                {
                    throw new InvalidDataException("Bad bytecode at line {0}, arguments should be ADDS ,X ,Y ,Z or ADDS ,X #val ,Y");
                }
            }
        }
Exemplo n.º 21
0
 private byte ReadFromRegister(RegisterAddress address)
 {
     return(ReadFromRegister((byte)(((byte)address) << 4), 1)[0]);
 }
Exemplo n.º 22
0
 /// <summary>
 /// Constructs a Store-Move Instruction.
 /// </summary>
 /// <param name="value">The value to be stored.</param>
 /// <param name="target">The address where the value should be stored at.</param>
 public StoreMoveInstruction(uint value, RegisterAddress target)
 {
     Value  = value;
     Target = target;
 }
 /// <summary>
 /// Constructs a Decrement Instruction
 /// </summary>
 /// <param name="target">The target address to decrement</param>
 public DecrementInstruction(RegisterAddress target)
 {
     Target = target;
 }
Exemplo n.º 24
0
        public override void Interpret(SourceCrawler sourceCrawler, BinaryWriter output, bool isLabelScan)
        {
            // Eat whitespace to right of mnemonic
            sourceCrawler.EatWhitespace();

            // Peek to make sure next character is a register delimiter, otherwise we return
            if (sourceCrawler.Peek() == CompilerSettings.RegisterDelimiter)
            {
                // Pass over the register delimiter
                sourceCrawler.CurrentNdx++;
                // Read the register
                RegisterAddress sourceRegister = sourceCrawler.ReadRegister();
                // Eat the whitespace leading to next parameter
                sourceCrawler.EatWhitespace();

                // Peek at the next character, if it is a literal delimiter, we parse a literal, otherwise we parse a register
                if (sourceCrawler.Peek() == CompilerSettings.LiteralDelimiter)
                {
                    // Pass over delimiter
                    sourceCrawler.CurrentNdx++;
                    // Read hard-coded location
                    byte deviceId = sourceCrawler.ReadByteValue();

                    // Add the correct size to the assembly length
                    sourceCrawler.AssemblyLength += (uint)(1 + 1 + 1);

                    // If this is not a label scanning pass, write to output
                    if (!isLabelScan)
                    {
                        output.Write(ByteCodes[0]); // 0x32
                        output.Write((byte)sourceRegister);
                        output.Write(deviceId);
                    }
                }
                // This is not a literal location, check for register
                else if (sourceCrawler.Peek() == CompilerSettings.RegisterDelimiter)
                {
                    // Pass over delimiter
                    sourceCrawler.CurrentNdx++;
                    // Read register
                    RegisterAddress destinationRegister = sourceCrawler.ReadRegister();

                    // This instruction is 3 bytes wide
                    sourceCrawler.AssemblyLength += (uint)(1 + 1 + 1);

                    // If this is not a label scanning pass, write to output
                    if (!isLabelScan)
                    {
                        output.Write(ByteCodes[1]); // 0x33
                        output.Write((byte)sourceRegister);
                        output.Write((byte)destinationRegister);
                    }
                }
            }
            // Well it didn't start with a register, so we must be comparing a value
            else if (sourceCrawler.Peek() == CompilerSettings.LiteralDelimiter)
            {
                // Pass over the register delimiter
                sourceCrawler.CurrentNdx++;
                // Read the value
                uint value = sourceCrawler.ReadWordValue();
                // Eat the whitespace leading to next parameter
                sourceCrawler.EatWhitespace();

                // Peek at the next character, if it is a literal delimiter, we parse a literal, otherwise we parse a register
                if (sourceCrawler.Peek() == CompilerSettings.LiteralDelimiter)
                {
                    // Pass over delimiter
                    sourceCrawler.CurrentNdx++;
                    // Read hard-coded location
                    byte deviceId = sourceCrawler.ReadByteValue();

                    // Add the correct size to the assembly length
                    sourceCrawler.AssemblyLength += (uint)(1 + CompilerSettings.WORD_LENGTH + 1);

                    // If this is not a label scanning pass, write to output
                    if (!isLabelScan)
                    {
                        output.Write(ByteCodes[2]); // 0x30
                        output.Write(value);
                        output.Write(deviceId);
                    }
                }
                // This is not a literal location, check for register
                else if (sourceCrawler.Peek() == CompilerSettings.RegisterDelimiter)
                {
                    // Pass over delimiter
                    sourceCrawler.CurrentNdx++;
                    // Read register
                    RegisterAddress destinationRegister = sourceCrawler.ReadRegister();

                    // This instruction is 3 bytes wide
                    sourceCrawler.AssemblyLength += (uint)(1 + CompilerSettings.WORD_LENGTH + 1);

                    // If this is not a label scanning pass, write to output
                    if (!isLabelScan)
                    {
                        output.Write(ByteCodes[3]); // 0x31
                        output.Write(value);
                        output.Write((byte)destinationRegister);
                    }
                }
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// Constructs a Copy-Move Instruction.
 /// </summary>
 /// <param name="from">The address from where to copy.</param>
 /// <param name="to">The address to where the value should be copied to.</param>
 public CopyMoveInstruction(RegisterAddress from, RegisterAddress to)
 {
     From = from;
     To   = to;
 }
Exemplo n.º 26
0
 private void WriteToRegister(RegisterAddress address, byte value)
 {
     Write((byte)(((byte)address) << 4), value);
 }
Exemplo n.º 27
0
 /// <summary>
 /// Constructs a Add Instruction
 /// </summary>
 /// <param name="a">The first address of a memory cell that should be added.</param>
 /// <param name="b">The second address of a memory cell that should be added.</param>
 public AddInstruction(RegisterAddress a, RegisterAddress b)
 {
     A = a;
     B = b;
 }
Exemplo n.º 28
0
        public override void Interpret(SourceCrawler sourceCrawler, BinaryWriter output, bool isLabelScan)
        {
            // Eat whitespace to right of mnemonic
            sourceCrawler.EatWhitespace();

            // Peek at the next character, if it is a literal delimiter, we parse a literal, otherwise we parse a register
            if (sourceCrawler.Peek() == CompilerSettings.LiteralDelimiter)
            {
                // Pass over delimiter
                sourceCrawler.CurrentNdx++;
                // Read hard-coded location
                uint value = sourceCrawler.ReadWordValue();

                // Add the correct size to the assembly length
                sourceCrawler.AssemblyLength += (uint)(1 + CompilerSettings.WORD_LENGTH);

                // If this is not a label scanning pass, write to output
                if (!isLabelScan)
                {
                    output.Write(ByteCodes[0]); // 0x34
                    output.Write(value);
                }
            }
            // This is not a literal location, check for register
            else if (sourceCrawler.Peek() == CompilerSettings.RegisterDelimiter)
            {
                // Pass over delimiter
                sourceCrawler.CurrentNdx++;
                // Read register
                RegisterAddress sourceRegister = sourceCrawler.ReadRegister();

                // This instruction is 3 bytes wide
                sourceCrawler.AssemblyLength += (1 + 1);

                // If this is not a label scanning pass, write to output
                if (!isLabelScan)
                {
                    output.Write(ByteCodes[1]); // 0x35
                    output.Write((byte)sourceRegister);
                }
            }
            else if (sourceCrawler.Peek() == CompilerSettings.ConstantDelimiter)
            {
                string constant = "";

                while (!char.IsWhiteSpace(sourceCrawler.Peek()))
                {
                    constant += sourceCrawler.Get();
                }

                if (constant.Equals("_ret_addr_"))
                {
                    sourceCrawler.AssemblyLength += 1 + 1;

                    if (!isLabelScan)
                    {
                        output.Write(ByteCodes[1]); // 0x35
                        output.Write((byte)0xF0);
                    }
                }
            }
        }