CMSC 3833 Lecture 37

Similar documents
Notes: The Marie Simulator

Computer Organization II CMSC 3833 Lecture 33

Department of Computer and Mathematical Sciences. Lab 4: Introduction to MARIE

CDA 3103 Computer Organization Homework #7 Solution Set

Problem Points Your Points Total 80

Computer Systems and Networks. ECPE 170 Jeff Shafer University of the Pacific. Introduc>on to MARIE

CSE100 Lecture03 Machines, Instructions, and Programs Introduction to Computer Systems

CC312: Computer Organization

The MARIE Architecture

Chapter 4. MARIE: An Introduction to a Simple Computer. Chapter 4 Objectives. 4.1 Introduction. 4.2 CPU Basics

Computer Systems and Networks. ECPE 170 Jeff Shafer University of the Pacific. MARIE Simulator

CS311 Lecture: The Architecture of a Simple Computer

2.2 THE MARIE Instruction Set Architecture

Chapter 4. MARIE: An Introduction to a Simple Computer

Chapter 4. Chapter 4 Objectives. MARIE: An Introduction to a Simple Computer

MARIE: An Introduction to a Simple Computer

MARIE: An Introduction to a Simple Computer

Chapter 4. Chapter 4 Objectives

Instruc=on Set Architecture

Examples of attributes: values of evaluated subtrees, type information, source file coordinates,

A Simple Syntax-Directed Translator

Instruc=on Set Architecture

Program Analysis ( 软件源代码分析技术 ) ZHENG LI ( 李征 )

The Assembly Language of the Boz 5

a number of pencil-and-paper(-and-calculator) questions two Intel assembly programming questions

Computer Architecture /

MIPS History. ISA MIPS Registers

Part 1 (70% of grade for homework 2): MIPS Programming: Simulating a simple computer

Computer Architecture. CSE 1019Y Week 16. Introduc>on to MARIE

Chapter 3. Z80 Instructions & Assembly Language. Von Neumann Architecture. Memory. instructions. program. data

CHAPTER 5 A Closer Look at Instruction Set Architectures

1 Lexical Considerations

Processor design - MIPS

JUMP, LOOP AND CALL INSTRUCTIONS

Unsigned Binary Integers

Unsigned Binary Integers

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Lexical Considerations

2.2 Syntax Definition

bits 5..0 the sub-function of opcode 0, 32 for the add instruction

11. A Computing Machine

3. Instruction Set Architecture The MIPS architecture

Sparse Notes on an MIPS Processor s Architecture and its Assembly Language

Translator Design CRN Test 3 Revision 1 CMSC 4173 Spring 2012

Five classic components

PSIM: Processor SIMulator (version 4.2)

Programming Using C Homework 5

Lexical Considerations

OSIAC Read OSIAC 5362 posted on the course website

CHAPTER 5 A Closer Look at Instruction Set Architectures

Computer Systems and Networks. ECPE 170 Jeff Shafer University of the Pacific. Exam Review

Chapter. Computer Architecture

Understand the factors involved in instruction set

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

A simple syntax-directed

17. Instruction Sets: Characteristics and Functions

COMP1917 Computing 1 Written Exam Sample Questions

CHAPTER 5 A Closer Look at Instruction Set Architectures

Chapter 1 Preliminaries

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

Week 2: Syntax Specification, Grammars

Wednesday, February 4, Chapter 4

Context-Free Grammar. Concepts Introduced in Chapter 2. Parse Trees. Example Grammar and Derivation

Address Modes effective address

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

2.1. Basic Assembler Functions:

Assembler. Lecture 8 CS301

2010 Summer Answers [OS I]

ECE331: Hardware Organization and Design

UNIT-II. Part-2: CENTRAL PROCESSING UNIT

Five classic components

Assembly Language Programming of 8085

Microcontroller Systems

SOEN228, Winter Revision 1.2 Date: October 25,

Chapter 3: part 3 Binary Subtraction

ORG ; TWO. Assembly Language Programming

8051 Microcontroller Assembly Programming

Copyright 2000 N. AYDIN. All rights reserved. 1

Course Administration

JME Language Reference Manual

Levels of Programming. Registers

the SAP-2 I. Intro cmpt-150-arc Sections 8-8, 8-9, 9-4, 9-5, 9.6, We ll do this in bits and pieces, doing the beginning of each section first.

Y = (A + C) (A + B) (B + C)

Lecture 4: Instruction Set Architecture

Introduction to Assembler Language Programming

Context-Free Grammars

ECE331: Hardware Organization and Design

... Executing conditional instructions

EE 361 University of Hawaii Fall

CSE 401 Midterm Exam 11/5/10

HC11 Instruction Set Architecture

Chapter 4. The Processor

Chapter 2: Assembly Language Fundamentals. Oregon State University School of Electrical Engineering and Computer Science.

Microprocessors & Assembly Language Lab 1 (Introduction to 8086 Programming)

CS 2630 Computer Organization. Meeting 4: Intro to Architecture (specifically, MIPS) Brandon Myers University of Iowa

I. instruction J. instruction register K. label L. load M. load/store machine N. location counter (loc) O. MAR P. MDR

Introduction to Computer Organization. Final Exam Summer 2017

HC11 Instruction Set Architecture

The Universal Machine Macro Assembler

Generalized Constant Expressions

Transcription:

Programming language grammars are employed to specify a programming language. An assembly language is programming language Context free grammars: A context-free grammar has four components: 1. A set of tokens, known as terminal symbols. 2. A set of nonterminal symbols or nonterminals. 3. A set of productions, or rules, where each production consists of a nonterminal symbol, called the left side or the production, an arrow, and a sequence of tokens and nonterminal symbols, called the right side of the production. 4. A designation of one of the nonterminal symbols as the start symbol. Notation: 1. Terminal symbols are expressed in bold print. 2. Nonterminal symbols are italicized. Example 1: Write a grammar for an arbitrarily long expression consisting of single digs separated by either the plus sign or the minus sign. left side right side 1 list list + digit 2 list list - digit 3 list digit 4 digit 0 5 digit 1 6 digit 2 7 digit 3 8 digit 4 9 digit 5 10 digit 6 11 digit 7 12 digit 8 13 digit 9 Table 1. PP, the set of productions For this grammar, 1. TT, the set of terminal symbols, called tokens, TT = {+,, 00, 11, 22, 33, 44, 55, 66, 77, 88, 99} 2. NN, the set of nonterminal symbol, NN = {llllllll, dddddddddd} 3. PP, the set of productions. Refer to Table 1. 4. The starting nonterminal symbol is list. 1

Example 2: Write a grammar for arithmetic expressions. left side right side 1 expression expression + term 2 expression expression - term 3 expression term 4 term term * factor 5 term term / factor 6 term factor 7 factor ( expression ) 8 factor id Table 2. Set of productions for expressions For this grammar, 1. TT, the set of terminal symbols, called tokens, TT = {+,,,/, (, ),id} 2. NN, the set of nonterminal symbol, NN ={expression,term,factor} 3. PP, the set of productions. Refer to Table 2. 4. The starting nonterminal symbol is expression. Example 3: Perform left-most derivation of the arithmetic expression id 1+id 2*id 3 String of terminals and nonterminals Rule used to reduce a handle of the string id 1+id 2*id 3 Terminal string factor+ id 2*id 3 8 factor id term+ id 2*id 3 6 term factor expression+ id 2*id 3 3 expression term expression+ factor*id 3 8 factor id expression+ term*id 3 6 term factor expression+ term*factor 8 factor id expression+ term 4 term term * factor expression 1 expression expression + term 2

Grammar for MARIE Rule Left Side Right Side 1 program statement-list 2 statement-list statement 3 statement-list statement-list statement 4 statement directive 5 statement labeled-item 6 statement item 7 directive org hexlit 8 labeled-item label item 9 label identifier, 10 item instruction 11 item data-definition 12 instruction JnS operand 13 instruction Load operand 14 instruction Store operand 15 instruction Add operand 16 instruction Subt operand 17 instruction Input 18 instruction Output 19 instruction Halt 20 instruction Skipcond operand 21 instruction Jump operand 22 instruction Clear 23 instruction AddI operand 24 instruction JumpI operand 25 instruction LoadI operand 26 instruction StoreI operand 27 instruction END 28 operand hexlit 29 operand identifier 30 data-definition HEX hexlit 31 data-definition DEC hexlit 3

Token Definition identifier [a-za-z][a-za-z0-9]* intlit [1-9][0-9]* hexlit [0][0-9a-fA-F]* Rule Left Side Right Side Action 1 program statement-list Write the memory image to file source.mex. 2 statement-list statement 3 statement-list statement-list statement 4 statement directive 5 statement labeled-item 6 statement item 7 directive org hexlit Convert the integer to 16-bit two s complement form. Assign the integer to the initial address. Assign the integer to the current address. 8 labeled-item label item 9 label identifier, Define the identifier in the Label Table by assigning the current address to the identifier. 10 item instruction Increment the current address 11 item data-definition Increment the current address 12 instruction JnS operand Create 16-bit instruction. Bits 15-12 are operator. Assign the JnS opcode (0000) to the operator field of the instruction. Assign the to 13 instruction Load operand Create 16-bit instruction. Bits 15-12 are operator. Assign the Load opcode (0001) to the operator field of the instruction. Assign the to 14 instruction Store operand Create 16-bit instruction. Bits 15-12 are operator. Assign the Store opcode (0010) to the to 15 instruction Add operand Create 16-bit instruction. Bits 15-12 are operator. Assign the Add opcode (0011) to the operator field of the instruction. Assign the to 4

Rule Left Side Right Side Action 16 instruction Subt operand Create 16-bit instruction. Bits 15-12 are operator. Assign the Subt opcode (0100) to the 17 instruction Input Create 16-bit instruction. Bits 15-12 are operator. Assign the Input opcode (0101) to the 0x000 to the remaining 12 bits of the 18 instruction Output Create 16-bit instruction. Bits 15-12 are operator. Assign the Output opcode (0110) to the operator field of the instruction. Assign the 0x000 to the remaining 12 bits of the instruction, bits 11-0. Assign the instruction to the current address in memory. 19 instruction Halt Create 16-bit instruction. Bits 15-12 are operator. Assign the Halt opcode (0111) to the 0x000 to the remaining 12 bits of the 20 instruction Skipcond operand Create 16-bit instruction. Bits 15-12 are operator. Assign the Skipcond opcode (1000) to the operator field of the instruction. Assign the operand to the remaining 12 bits of the instruction, bits 11-0. Assign the instruction to the current address in memory. 21 instruction Jump operand Create 16-bit instruction. Bits 15-12 are operator. Assign the Jump opcode (1001) to the 22 instruction Clear Create 16-bit instruction. Bits 15-12 are operator. Assign the Clear opcode (1010) to the 0x000 to the remaining 12 bits of the 5

Rule Left Side Right Side Action 23 instruction AddI operand Create 16-bit instruction. Bits 15-12 are operator. Assign the AddI opcode (1011) to the 24 instruction JumpI operand Create 16-bit instruction. Bits 15-12 are operator. Assign the JumpI opcode (1100) to the operator field of the instruction. Assign the operand to the remaining 12 bits of the instruction, bits 11-0. Assign the instruction to the current address in memory. 25 instruction LoadI operand Create 16-bit instruction. Bits 15-12 are operator. Assign the LoadI opcode (1101) to the 26 instruction StoreI operand Create 16-bit instruction. Bits 15-12 are operator. Assign the StoreI opcode (1110) to the operator field of the instruction. Assign the operand to the remaining 12 bits of the instruction, bits 11-0. Assign the instruction to the current address in memory. 27 Instruction END 28 operand hexlit Convert the hexlit to a 16-bit two s complement integer. 29 operand identifier Reference the identifier in the Label Table by assigning the current address to the identifier s reference list. 30 data-definition hex hexlit Convert the hexlit to a 16-bit two s complement integer. 31 data-definition dec intlit Convert the intlit to a 16-bit two s complement integer. 6