Example #1
0
        public Program Assemble(Address addrBase, TextReader reader)
        {
            Assembler = new Pdp11Assembler(arch, addrBase, emitter);
            lexer     = new Lexer(reader);

            // Assemblers are strongly line-oriented.

            while (lexer.Peek().Type != TokenType.EOF)
            {
                ProcessLine();
            }

            //asm.ReportUnresolvedSymbols();
            StartAddress = addrBase;
            return(Assembler.GetImage());
        }
Example #2
0
        public Program Assemble(Address addrBase, TextReader reader)
        {
            arch      = new Pdp11Architecture(new ServiceContainer(), "pdp11", new Dictionary <string, object>());
            Assembler = new Pdp11Assembler(arch, addrBase, emitter);
            lexer     = new Lexer(reader);

            // Assemblers are strongly line-oriented.

            while (lexer.Peek().Type != TokenType.EOF)
            {
                ProcessLine();
            }

            //asm.ReportUnresolvedSymbols();
            StartAddress = addrBase;
            return(Assembler.GetImage());
        }
Example #3
0
        public Program Assemble(Address addrBase, TextReader reader)
        {
            arch = new Pdp11Architecture();
            Assembler = new Pdp11Assembler(arch, addrBase, emitter);
            lexer = new Lexer(reader);

            // Assemblers are strongly line-oriented.

            while (lexer.Peek().Type != TokenType.EOF)
            {
                ProcessLine();
            }

            //asm.ReportUnresolvedSymbols();
            StartAddress = addrBase;
            return Assembler.GetImage();
        }
Example #4
0
        private void ProcessLine()
        {
            if (lexer.PeekAndDiscard(TokenType.EOL))
            {
                return;
            }
            if (lexer.PeekAndDiscard(TokenType._Page))
            {
                return;
            }
            if (lexer.Peek().Type == TokenType.Id)
            {
                var id = (string)lexer.Expect(TokenType.Id);
                if (lexer.PeekAndDiscard(TokenType.Eq))
                {
                    var exp = ParseExpression();
                    Assembler.Equate(id, exp);
                    lexer.PeekAndDiscard(TokenType.EOL);
                    return;
                }
                else if (lexer.PeekAndDiscard(TokenType.Colon))
                {
                    Assembler.Label(id);
                }
                else
                {
                    lexer.Unexpected(lexer.Get());
                }
            }
            switch (lexer.Peek().Type)
            {
            case TokenType.EOL:
                lexer.Get();
                return;

            case TokenType._Word:
                lexer.Get();
                ProcessWords(PrimitiveType.Word16);
                break;

            case TokenType._Dot:
                lexer.Get();
                lexer.Expect(TokenType.Eq);
                lexer.Expect(TokenType._Dot);
                lexer.Expect(TokenType.Plus);
                var delta = (int)ParseExpression();
                emitter.Reserve(delta);
                break;

            case TokenType.ASR: ProcessSingleOperand(Assembler.Asr); break;

            case TokenType.CLR: ProcessSingleOperand(Assembler.Clr); break;

            case TokenType.CLRB: ProcessSingleOperand(Assembler.Clrb); break;

            case TokenType.BEQ: ProcessBranch(Assembler.Beq); break;

            case TokenType.DEC: ProcessSingleOperand(Assembler.Dec); break;

            case TokenType.INC: ProcessSingleOperand(Assembler.Inc); break;

            case TokenType.JSR: lexer.Get(); Assembler.Jsr(ParseOperands()); break;

            case TokenType.MOV: ProcessDoubleOperand(Assembler.Mov); break;

            case TokenType.MOVB: ProcessDoubleOperand(Assembler.Movb); break;

            case TokenType.RESET: lexer.Get(); Assembler.Reset(); break;

            case TokenType.SUB: ProcessDoubleOperand(Assembler.Sub); break;

            default:
                lexer.Unexpected(lexer.Get());
                break;
            }
        }