Quick Reference Guide

Similar documents
Quick Reference Guide

In Delphi script, when values are assigned to variables, the colon-equal operator is used; :=

DelphiScript Keywords

Flow Control. CSC215 Lecture

DEPARTMENT OF MATHS, MJ COLLEGE

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

UNIT- 3 Introduction to C++

Chapter 12 Variables and Operators

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Information Science 1

Computers Programming Course 6. Iulian Năstac

BASIC ELEMENTS OF A COMPUTER PROGRAM

CS313D: ADVANCED PROGRAMMING LANGUAGE

Lecture 3 Tao Wang 1

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE

A flow chart is a graphical or symbolic representation of a process.

Course Outline Introduction to C-Programming

SECTION II: LANGUAGE BASICS

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

Operators in java Operator operands.

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Operators. Java operators are classified into three categories:

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Chapter 3: Operators, Expressions and Type Conversion

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

The Arithmetic Operators

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

JAVA OPERATORS GENERAL

Operators in C. Staff Incharge: S.Sasirekha

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

TED Language Reference Manual

C - Basics, Bitwise Operator. Zhaoguo Wang

(Not Quite) Minijava

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

More Programming Constructs -- Introduction

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

Outline. Data and Operations. Data Types. Integral Types

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Lecture 3. More About C

Lexical Considerations

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics

Chapter 12 Variables and Operators

C++ INDEX. Introduction: Instructions for use. Basics of C++: Structure of a program Variables. Data Types. Constants Operators Basic Input/Output

Review of the C Programming Language for Principles of Operating Systems

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Programming with C++ Language

Expressions and Precedence. Last updated 12/10/18

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

LICENSE AGREEMENT: By using our products you agree to be bound by all terms of this agreement. Copyright by MikroElektronika

Data Structure Lab. Prepared By Dr. Hanan Ahmed Salman

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

CGS 3066: Spring 2015 JavaScript Reference

Java Basic Programming Constructs

3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

Chapter 12 Variables and Operators

.Net Technologies. Components of.net Framework

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments

C: How to Program. Week /Mar/05

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Computational Physics Operating systems

CHW 469 : Embedded Systems

C Programming Language (Chapter 2 of K&R) Variables and Constants

CA4003 Compiler Construction Assignment Language Definition

Unit-2 (Operators) ANAND KR.SRIVASTAVA

Review of the C Programming Language

Fundamental of Programming (C)

Programming in C++ 5. Integral data types

C Language Programming

Chapter 2 - Introduction to C Programming

1

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

The C++ Language. Arizona State University 1

6.096 Introduction to C++ January (IAP) 2009

Chapter 2: Basic Elements of C++

The Design of C: A Rational Reconstruction: Part 2

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

Darshan Institute of Engineering & Technology for Diploma Studies

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Continued from previous lecture

FIDE Language Reference

Expression and Operator

Arithmetic and Bitwise Operations on Binary Data

Transcription:

SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD mikroelektronika Development tools - Books - Compilers Quick Reference Quick Reference Guide with EXAMPLES for Pascal language This reference guide is intended to quickly introduce users to Pascal language syntax with the aim to easily start programming microcontrollers along with other applications. Why Pascal in the first place? The answer is simple: it is legible, easy-to-learn, structured programming language, with sufficient power and flexibility needed for programming microcontrollers. Whether you had any previous programming experience, you will find that writing programs in Pascal is very easy. Software and Hardware solutions for Embedded World

COMMENTS All text between a left brace and a right brace constitutes a comment. May span multiple lines. { Put your comment here! It may span multiple lines. } Any text between a double-slash and the end of the line constitutes a comment. May span one line only. // Put your comment here! // It may span one line only. LITERALS Character Literals Character literal is one character from the extended ASCII character set, enclosed with apostrophes. 'A' // this is character A String Literals String literal is a sequence of up to 255 characters from the extended ASCII character set, enclosed with apostrophes. 'Hello!' // 6 chars long 'C' // 1 char long KEYWORDS absolute function read and goto record array if repeat asm implementation shl interrupt shr boolean in step break is string case label then char mod to continue not type const or unit div org until do otherwise uses downto print var else procedure while end program with for real xor User can not use keywords for variable or function names. Keywords are reserved only for making pascal language statements. VARIABLES var identifier_list : type; var i, j, k : byte; CONSTANTS const constant_name [: type] = value; const MAX : longint = 10000; MIN = 1000; // compiler will assume word type SWITCH = 'n'; // compiler will assume char type MSG = 'Hello'; // compiler will assume string type 1 making it simple... MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD

LABELS FUNCTIONS label_identifier: statement label loop;... Before marking a statement, you must first loop: Beep; declare the label: goto loop; label label1,..., labeln; function function_nameparameter_list) : return_type; { local declarations } { function body } function adda, b : byte) : byte; result := a + b; // infinite loop // that calls the // Beep procedure We can call it to calculate sum of two numbers: var c : byte; c := add4, 5); Variable c will then be 9. PROCEDURES procedure procedure_nameparameter_list); { local declarations } { procedure body } procedure addvar c, a, b : byte); c := a + b; We can call it to calculate sum of two numbers last two parameters) and place result in first parameter: var c : byte; addc, 4, 5); Variable c will then be 9. SIMPLE TYPES Type Size Range byte 8-bit 0.. 255 char 8-bit 0.. 255 word 16-bit 0.. 6555 short 8-bit - 128.. 127 integer 16-bit -2768.. 2767 longint 2-bit -214748648.. 214748647 real 2-bit ±1.1754945082 * 10-8.. ±6.80564774407 * 10 8 MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD making it simple... 2

ARRAYS array[index_start.. index_end] of type var weekdays : array[1..7] of byte; samples : array[10] of word; // now we can access elements of array variables, for example: if weekdays[2] = 1 then // if it is Tuesday then samples[0] := 20 // order 20 samples with index 0 else samples[] := 10; // else order 10 samples with index CONSTANT ARRAYS // Declare a constant array which holds no. of days // in each month: const MONTHS : array[1..12] of byte = 1,28,1,0,1,0,1,1,0,1,0,1); STRINGS POINTERS string_name string[length] To declare a pointer data type, add a carat prefix ^) before type. For example, if you are creating a pointer to an integer, you would write: ^integer; var msg1 : string[20]; msg2 : string[19]; msg1 := 'First message'; msg2 := 'Second message'; msg1 := msg2; This is ok, but vice versa would be illegal because of strings length). A pointer can be assigned to another pointer. However, note that only the var p : ^word; address, not the value, is copied.... p^ := 5; This will assign the pointed memory location value 5. @ Operator The @ operator returns the address of a variable or routine; that is, @ constructs a pointer to its operand. The following rules apply to @: - If X is a variable, @X returns the address of X. - If F is a routine a function or procedure), @F returns F s entry point RECORDS type recordtypename = record fieldlist1 : type1;... fieldlistn : typen; type TDot = record x, y : real; making it simple... MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD

Memory is allocated when you instantiate the record, like this: var m, n: TDot; Accessing Fields m.x :=.6; m.y := 5; OPERATORS There are four types of operators in mikropascal: - Arithmetic Operators - Bitwise Operators - Boolean Operators - Relational Operators You can commit assignments between complex variables, if they are of the same type: n := m; This will copy values of all fields. Operators Precedence and Associativity Precedence Operands Operators Associativity 4 1 @ not + - right-to-left 2 * / div mod and shl shr left-to-right 2 2 + - or xor left-to-right 1 2 = <> < > <= >= left-to-right Arithmetic Operators Operator Operation Precedence + addition 2 - subtraction 2 * multiplication / division div division, rounds down to nearest integer cannot be used with floating points) mod returns the remainder of integer division cannot be used with floating points) Relational Operators Operator Operation Precedence = equal 1 <> not equal 1 > greater than 1 < less than 1 >= greater than or equal 1 <= less than or equal 1 Use relational operators to test equality or inequality of expressions. All relational operators return TRUE or FALSE. MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD making it simple... 4

Bitwise Operators Operator Operation Precedence and or xor bitwise AND; returns 1 if both bits are 1, otherwise returns 0 bitwise inclusive) OR; returns 1 if either or both bits are 1, otherwise returns 0 bitwise exclusive OR XOR); returns 1 if the bits are complementary, otherwise 0 not bitwise complement unary); inverts each bit 4 shl bitwise shift left; moves the bits to the left, see below shr bitwise shift right; moves the bits to the right, see below Examples: Examples: operand1 : %0001 0010 operand2 : %0101 0110 operand : %0101 0110 ------------------------------ ------------------------------ operator and : %0001 0010 operator not : %1010 1001 operator or : %0101 0110 operator shl : %1010 1100 operator xor : %0100 0100 operator shr : %0010 1011 2 2 With shift left shl), left most bits are discarded, and new bits on the right are assigned zeroes. With shift right shr), right most bits are discarded, and the freed bits on the left are assigned zeroes in case of unsigned operand) or the value of the sign bit in case of signed operand). Boolean Operators Operator and or xor not Operation logical AND logical OR logical exclusive OR logical negation These operators conform to standard Boolean logic. If used in conditional expressions they are compared with TRUE or FALSE. Examples: if %1001 and %0111) = FALSE then LED1 := 1 else LED2 := 1; Because expression %1001 and %0111) gives %0001, when compared with FALSE all zeros) it gives FALSE because they are not equal. It means that else statement will be executed and LED2 will be turned on. If it was written like this: if %1001 and %0111) then LED1 := 1 else LED2 := 1; than expression %1001 and %0111) is compared with TRUE all ones) by default. 5 making it simple... MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD

STATEMENTS asm Statement asm block of assembly instructions Assignment Statements variable := expression; counter := 1; Compound Statements statements In mikropascal, the end. statement the closing statement of every program) acts as an endless loop. i := 0; while i < 5 do temp := a[i]; a[i] := b[i]; b[i] := temp; i := i + 1; end. This code will exchange values of 5 elements from arrays a and b. CONDITIONAL STATEMENTS If Statement if expression then statement1 [else statement2] if movex = 1 then x := x+20 else y := y-10; The else keyword with an alternate statement is optional. Case Statement case selector of value_1 : statement_1;... value_n : statement_n; [else default_statement] case input of 1 : LED1 := 1; 2 : LED2 := 1; : LED := 1 else LED7 := 1; ITERATION STATEMENTS LOOPS) This code will turn on LED depending of input value. If the value is diffrent then ones mentioned in value list in case statement then else statement is executed by default. Semicolon not allowed if followed by else statement applies for whole Pascal). For Statement for counter := initial_value to final_value do statement // or for counter := initial_value downto final_value do statement s := 0; for i := 0 to 4 do s := s + 2; This code will add number 2 to variable s 5 times. At the end s will be 10. MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD making it simple... 6

JUMP STATEMENTS While Statement while expression do statement This code will add number 2 to variable s 6 times. At the end s will be 12. Repeat Statement repeat statement until expression Break Statement Use the break statement within loops to pass control to the first statement following the innermost loop for, while, or repeat block). s := 0; i := 0; while i < 6 do s := s + 2; i := i + 1; s := 0; i := 0; repeat s := s + 2; i := i + 1; until i = 7; This code will add number 2 to variable s 7 times. At the end s will be 14. i := 0; s := 1; // initiate value of counter i and variable s while TRUE do // infinite loop if i = 4 then break; This code will multiply variable s with number 2 s := s * 2; i := i + 1; until counter i becomes equal 4 and break statement executes). At the end s will be 16. Continue Statement You can use the continue statement within loops to skip the rest of the statements and jump to the first statement in loop. i := 0; s := 1; // initiate value of counter i and variable s while TRUE do s := s * 2; i := i + 1; if i <> 4 then continue; break; // infinite loop This code will multiply variable s with number 2 continue statement executes until counter i is not equal 4). At the end s will be 16. Goto Statement goto label_name; label loop;... loop: Beep; goto loop; // infinite loop that // calls the // Beep procedure Exit Statement The exit statement allows you to break out of a routine function or procedure). It passes the control to the first statement following the routine call. procedure Proc1); var error: byte;... // we're doing something here if error = TRUE then exit;... // some code, which won't be... // executed if error is true 7 making it simple... MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD