Quick Reference Guide

Similar documents
Quick Reference Guide

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

DEPARTMENT OF MATHS, MJ COLLEGE

Operators in java Operator operands.

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

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

JAVA OPERATORS GENERAL

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

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

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

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

Chapter 3: Operators, Expressions and Type Conversion

UNIT- 3 Introduction to C++

BASIC ELEMENTS OF A COMPUTER PROGRAM

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

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

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

More Programming Constructs -- Introduction

Information Science 1

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE

SECTION II: LANGUAGE BASICS

CS313D: ADVANCED PROGRAMMING LANGUAGE

Operators. Java operators are classified into three categories:

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

Computers Programming Course 6. Iulian Năstac

DelphiScript Keywords

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE

Table of Contents. Preface

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

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

Course Outline Introduction to C-Programming

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

Flow Control. CSC215 Lecture

Lecture 3. More About C

Chapter 12 Variables and Operators

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

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:

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

.Net Technologies. Components of.net Framework

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

Programming in C++ 5. Integral data types

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

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

The Arithmetic Operators

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

Operators in C. Staff Incharge: S.Sasirekha

Unit-2 (Operators) ANAND KR.SRIVASTAVA

Outline. Data and Operations. Data Types. Integral Types

Expressions and Precedence. Last updated 12/10/18

Arithmetic and Bitwise Operations on Binary Data

Informatics Ingeniería en Electrónica y Automática Industrial

Declaration and Memory

CSC 1214: Object-Oriented Programming

Chapter 4. Operations on Data

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

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

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

ISA 563 : Fundamentals of Systems Programming

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

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

C Programming Language. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

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

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Lecture 3 Tao Wang 1

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

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

Java Basic Programming Constructs

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

Chapter 2. C++ Basics

SOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)

TED Language Reference Manual

The Design of C: A Rational Reconstruction: Part 2

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

Continued from previous lecture

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

Computer System and programming in C

CS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started

Prof. Navrati Saxena TA: Rochak Sachan

Operators & Expressions

Java Notes. 10th ICSE. Saravanan Ganesh

Review of the C Programming Language for Principles of Operating Systems

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

6.096 Introduction to C++ January (IAP) 2009

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

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

C - Basics, Bitwise Operator. Zhaoguo Wang

ME 461 C review Session Fall 2009 S. Keres

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

Chapter 2: Basic Elements of C++

Darshan Institute of Engineering & Technology for Diploma Studies

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

C/C++ Programming Lecture 7 Name:

JAVA Programming Fundamentals

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

Fundamental of Programming (C)

RUBY OPERATORS. Ruby Arithmetic Operators: Ruby Comparison Operators:

Transcription:

SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD mikroelektronika Development tools - Books - Compilers Quick Reference Quick Reference Guide with EXAMPLES for Basic language This reference guide is intended to quickly introduce users to BASIC language syntax with the aim to easily start programming microcontrollers along with other applications. Why BASIC 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 BASIC is very easy. Software and Hardware solutions for Embedded World

COMMENTS Any text between an apostrophe 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 by quotes. "A" // this is character A String Literals String literal is a sequence of up to 255 characters from the extended ASCII character set, enclosed by quotes. "Hello!" ' 12 chars long "C" ' 1 char long KEYWORDS absolute float or abs for org and function print array goto procedure asm gosub program begin if read boolean include select case in sub char int step chr integer string clear interrupt switch const is then dim loop to div label until do mod wend double module while else new with end next xor exit not User can not use keywords for variable or function names. Keywords are reserved only for making basic language statements. VARIABLES dim identifier_list as type dim i, j, k as byte CONSTANTS const constant_name [as type] = value const MAX as longint = 10000 const MIN = 1000 ' compiler will assume word type const SWITCH = "n" ' compiler will assume char type const MSG = "Hello" ' compiler will assume string type LABELS label_identifier : statement loop: Beep goto loop infinite loop that calls the Beep procedure 1 making it simple... MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD

SYMBOLS symbol alias = code symbol MAXALLOWED = 216 ' Symbol as alias for numeric value symbol PORT = PORTC ' Symbol as alias for SFR FUNCTIONS AND PROCEDURES Functions sub function function_nameparameter_list) as return_type [ local declarations ] function body end sub sub function adddim a, b as byte) as byte result = a + b end sub We can call it to calculate sum of two numbers: dim c as byte c = add4, 5) Variable c will then be 9. Procedures sub procedure procedure_nameparameter_list) [ local declarations ] procedure body end sub sub procedure adddim byref c as byte, dim a, b as byte) c = a + b end sub When we want the parameter to be changed in function or procedure body then we must declare that parameter with dim byref directive instead with dim directive. If declared with dim directive changes to the parameter will take effect only in that function or procedure. We can call it to calculate sum of two numbers last two parameters) and place result in first parameter: dim c as 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 float 2-bit ±1.1754945082 * 10-8... ±6.80564774407 * 10 8 MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD making it simple... 2

ARRAYS CONSTANT ARRAYS STRINGS POINTERS type[array_length] dim weekdays as byte[7] dim samples as word[10] ' now we can access elements of array variables, for example: samples[0] = 1 if weekdays[1] = 1 then ' if it is Tuesday day with index 1) samples[0] = 20 ' then order 20 samples with index 0 else samples[] = 10 ' else order 10 samples with index ' Declare a constant array which holds no. of days ' in each month: const MONTHS as byte[12] = 1,28,1,0,1,0,1,1,0,1,0,1) string[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 dim msg1 as string[20] dim msg2 as string[19] begin msg1 = "First message" msg2 = "Second message" msg1 = msg2 This is ok, but vice versa would be illegal because length of string msg1 is greater then length of string msg2). A pointer can be assigned to another pointer. However, note that only the dim p as ^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 STRUCTURES structure structname dim member1 as type1... dim membern as typen end structure structure Dot dim x as float dim y as float end structure making it simple... MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD

Memory is allocated when you instantiate the record, like this: dim m as Dot dim n as Dot Accessing Fields m.x =.6 m.y = 5 OPERATORS There are four types of operators in mikrobasic: - Arithmetic Operators - Bitwise Operators - Boolean Operators - Relational Operators Operators Precedence and Associativity Precedence Operands Operators Associativity 4 1 @ not + - right-to-left 2 * / div mod and << >> 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 mod division, rounds down to nearest integer cannot be used with floating points) returns the remainder of integer division cannot be used with floating points) You can commit assignments between complex variables, if they are of the same type: n = m This will copy values of all fields. 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 bitwise AND; returns 1 if both bits are 1, otherwise returns 0 or bitwise inclusive) OR; returns 1 if either or both bits are 1, otherwise returns 0 2 xor bitwise exclusive OR XOR); returns 1 if the bits are complementary, otherwise 0 2 not bitwise complement unary); inverts each bit 4 << bitwise shift left; moves the bits to the left, see below >> bitwise shift right; moves the bits to the right, see below Examples: operand1 : %0001 0010 operand2 : %0101 0110 ------------------------------ operator and : %0001 0010 operator or : %0101 0110 operator xor : %0100 0100 Examples: operand : %0101 0110 ------------------------------ operator not : %1010 1001 operator << : %1010 1100 operator >> : %0010 1011 With shift left <<), left most bits are discarded, and new bits on the right are assigned zeroes. With shift right >>), 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. 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 end asm Assignment Statements variable = expression counter = 1 CONDITIONAL STATEMENTS If Statement if expression then statements [else other statements] if movex = 1 then x = x + 20 else y = y - 10 The else keyword with an alternate statement is optional. Select Case Statement select case selector case value_1 statements_1... case value_n statements_n [case else default_statements] end select select case input case 1 LED1 = 1 case 2 LED2 = 1 case LED = 1 case else LED7 = 1 end select 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. ITERATION STATEMENTS LOOPS) For Statement for counter = initial_value to final_value [step step_value] statements next counter s = 0 for i = 0 to 4 s = s + 2 next i This code will add number 2 to variable s 5 times. At the end s will be 10. step directive is optional. It defines incrementing or decrementing if negative) value of counter after each iteration. Default step value is 1. While Statement while expression statements wend s = 0 i = 0 while i < 6 s = s + 2 i = i + 1 wend This code will add number 2 to variable s 6 times. At the end s will be 12. MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD making it simple... 6

Do Statement s = 0 do i = 0 statements do loop until expression s = s + 2 i = i + 1 loop until i = 7 This code will add number 2 to variable s 7 times. At the end s will be 14. JUMP STATEMENTS Break Statement Use the break statement within loops to pass control to the first statement following the innermost loop for, while, and do). i = 0 ' initiate value of counter i s = 1 ' and variable s while true ' infinite loop if i = 4 then break s = s * 2 This code will multiply variable s with number 2 i = i + 1 until counter i becomes equal 4 and break statement executes). At the end s will be wend 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 ' initiate value of counter i s = 1 ' and variable s while true s = s * 2 i = i + 1 if i <> 4 then continue break wend ' 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 loop: Beep goto loop infinite loop that calls the Beep procedure Goto Statement gosub label_name... label_name:... return 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. sub procedure Proc1) dim error as byte... ' we're doing something here if error = TRUE then exit... ' some code, which won't be end sub ' executed if error is true 7 making it simple... MIKROELEKTRONIKA SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD