Expressions. Operands. Operators

Similar documents
COMP3221: Microprocessors and Embedded Systems. Lecture 11: Assembly Lecturer: Hui Wu Session 2, 2005

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

Menu. >Debugging/Simulating in Atmel Studio >Downloading and Debugging/Emulating with the UF-board. Machine Codes 6811: $86 $0A GCPU: $02 $0A

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

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

AVR Assembler Examples

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

Operators. Java operators are classified into three categories:

Expressions and Precedence. Last updated 12/10/18

Operators in C. Staff Incharge: S.Sasirekha

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

Computer Programming CS F111

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

UNIT- 3 Introduction to C++

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

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

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

JAVA OPERATORS GENERAL

Learning the Language - V

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2 Fall 2018

Lecture 3 Tao Wang 1

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2

Operators in java Operator operands.

Beginning C Programming for Engineers

COMP Primitive and Class Types. Yi Hong May 14, 2015

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

Prof. Navrati Saxena TA: Rochak Sachan

Arithmetic and Bitwise Operations on Binary Data

LECTURE 3 C++ Basics Part 2

Arithmetic and Bitwise Operations on Binary Data

Chapter 3: Operators, Expressions and Type Conversion

Information Science 1

Operators & Expressions

CSCI 2212: Intermediate Programming / C Chapter 15

Department of Computer Science

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

Unit-2 (Operators) ANAND KR.SRIVASTAVA

Programming I Lecture 7

Computers Programming Course 6. Iulian Năstac

cast int( x float( x str( x hex( int string int oct( int string int bin( int string int chr( int int ord( ch

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators

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

The Arithmetic Operators

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

Operators. Lecture 3 COP 3014 Spring January 16, 2018

RUBY OPERATORS. Ruby Arithmetic Operators: Ruby Comparison Operators:

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

More Programming Constructs -- Introduction

Advanced Algorithms and Computational Models (module A)

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

Chap 6 - Introduction to HDL (b)

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

Chapter 12 Variables and Operators

Computer Organisation CS303

Expression and Operator

Quick Reference Guide

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

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

Unit 3. Operators. School of Science and Technology INTRODUCTION

EE292: Fundamentals of ECE

Number Systems and Their Representations

CS 33. Data Representation, Part 1. CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

Arithmetic for Computers

Chapter Two MIPS Arithmetic

C expressions. (Reek, Ch. 5) 1 CS 3090: Safety Critical Programming in C

Bits, Words, and Integers

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

Bits, Bytes, and Integers

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Operators and Expressions:

UNIT 3 OPERATORS. [Marks- 12]

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

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

Lecture 3. More About C

SECTION II: LANGUAGE BASICS

Chapter. Computer Architecture

PYTHON- AN INNOVATION

9 Using Equation Networks

Module 2: Computer Arithmetic

Quick Reference Guide

Divide: Paper & Pencil

NAME asm cross-assembler SYNOPSIS

Applied Computer Programming

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

COE 202- Digital Logic. Number Systems II. Dr. Abdulaziz Y. Barnawi COE Department KFUPM. January 23, Abdulaziz Barnawi. COE 202 Logic Design

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

Chapter 4. Operations on Data

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

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators

ECEN 468 Advanced Logic Design

Programming. Elementary Concepts

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

A Java program contains at least one class definition.

Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997

Lecture Notes on Ints

FAQ No. 53. ihost: Logic Points. Roles and Privileges. Adding and removing logic points. Accessing and using the Logic Editor

CSE I-Sem)

Introduction to Computers. Laboratory Manual. Experiment #3. Elementary Programming, II

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

Transcription:

Página 1 de 6 Expressions The Assembler incorporates constant expressions. Expressions can consist of operands, operators and functions. All expressions are internally 32 bits in AVRASM, and 64 bits in AVRASM2. Operands The following operands can be used: User defined labels which are given the value of the location counter at the place they appear. User defined variables defined by the SET directive User defined constants defined by the EQU directive Integer constants: constants can be given in several formats, including Decimal (default): 10, 255 Hexadecimal (two notations): 0x0a, $0a, 0xff, $ff Binary: 0b00001010, 0b11111111 Octal (leading zero): 010, 077 PC - the current value of the Program memory location counter Floating point constants - AVRASM2 only. Operators The Assembler supports a number of operators which are described here. The higher the precedence, the higher the priority. Expressions may be enclosed in parentheses, and such expressions are always evaluated before combined with anything outside the parentheses. The associativity of binary operators indicates the evaluation order of chained operators, left associativity meaning they are evaluated left to right, i.e., 2-3 - 4 is (2-3) - 4, while right associativity would mean 2-3-4 is 2 - (3-4). Some operators are not assoiciative, meaning chaining has no meaning. The following operators are defined: Symbol Description! Logical Not ~ Bitwise Not - Unary Minus * Multiplication / Division % Modulo (AVRASM2 only) + Addition - Subtraction << Shift left >> Shift right < Less than <= Less than or equal > Greater than >= Greater than or equal == Equal

Página 2 de 6!= Not equal & Bitwise And ^ Bitwise Xor Bitwise Or && Logical And Logical Or Conditional operator? (AVRASM2 only) Logical Not Symbol:! Description: Unary operator which returns 1 if the expression was zero, and returns 0 if the expression was nonzero Example: ldi r16,!0xf0 ; Load r16 with 0x00 Bitwise Not Symbol: ~ Description: Unary operator which returns the input expression with all bits inverted Example: ldi r16,~0xf0 ; Load r16 with 0x0f Unary Minus Symbol: - Description: Unary operator which returns the arithmetic negation of an expression Precedence: 14 Example: ldi r16,-2 ; Load -2(0xfe) in r16 Multiplication Symbol: * Description: Binary operator which returns the product of two expressions Precedence: 13 Example: ldi r30,label*2 ; Load r30 with label*2 Division Symbol: / Description: Binary operator which returns the integer quotient of the left expression divided by the right expression Precedence: 13 Example: ldi r30,label/2 ; Load r30 with label/2

Página 3 de 6 Modulo (AVRASM2 Only) Symbol: % Description: Binary operator which returns the integer remainder of the left expression divided by the right expression Precedence: 13 Example: ldi r30,label%2 ; Load r30 with label%2 Addition Symbol: + Description: Binary operator which returns the sum of two expressions Example: ldi r30,c1+c2 ; Load r30 with c1+c2 Subtraction Symbol: - Description: Binary operator which returns the left expression minus the right expression Example: ldi r17,c1-c2 ;Load r17 with c1-c2 Shift left Symbol: << Description: Binary operator which returns the left expression shifted left the number given by the right expression Precedence: 11 Example: ldi r17,1<<bitmask ;Load r17 with 1 shifted left bitmask times Shift right Symbol: >> Description: Binary operator which returns the left expression shifted right the number given by the right expression Precedence: 11 Example: ldi r17,c1>>c2 ;Load r17 with c1 shifted right c2 times Less than Symbol: < left is Less than the signed expression to the right, 0 otherwise Example: ori r18,bitmask*(c1<c2)+1 ;Or r18 with an expression

Página 4 de 6 Less or equal Symbol: <= left is Less than or Equal to the signed expression to the right, 0 otherwise Example: ori r18,bitmask*(c1<=c2)+1 ;Or r18 with an expression Greater than Symbol: > left is Greater than the signed expression to the right, 0 otherwise Example: ori r18,bitmask*(c1>c2)+1 ;Or r18 with an expression Greater or equal Symbol: >= left is Greater than or Equal to the signed expression to the right, 0 otherwise Example: ori r18,bitmask*(c1>=c2)+1 ;Or r18 with an expression Equal Symbol: == left is Equal to the signed expression to the right, 0 otherwise Precedence: 9 Example: andi r19,bitmask*(c1==c2)+1 ;And r19 with an expression Not equal Symbol:!= left is Not Equal to the signed expression to the right, 0 otherwise Precedence: 9 Example:.SET flag=(c1!=c2) ;Set flag to 1 or 0 Bitwise And Symbol: & Description: Binary operator which returns the bitwise And between two expressions Precedence: 8

Página 5 de 6 Example: ldi r18,high(c1&c2) ;Load r18 with an expression Bitwise Xor Symbol: Description: expressions Precedence: 7 ^ Binary operator which returns the bitwise Exclusive Or between two Example: ldi r18,low(c1^c2) ;Load r18 with an expression Bitwise Or Symbol: Description: Binary operator which returns the bitwise Or between two expressions Precedence: 6 Example: ldi r18,low(c1 c2) ;Load r18 with an expression Logical And Symbol: Description: nonzero, 0 otherwise Precedence: 5 && Binary operator which returns 1 if the expressions are both Example: ldi r18,low(c1&&c2) ;Load r18 with an expression Logical Or Symbol: Description: Binary operator which returns 1 if one or both of the expressions are nonzero, 0 otherwise Precedence: 4 Example: ldi r18,low(c1 c2) ;Load r18 with an expression Conditional operator (AVRASM2 only) Symbol:? : Syntax: condtion? expression1 : expression2 Description: Ternary operator which returns expression1 if condition is true, expression2 otherwise. Precedence: 3 Example: ldi r18, a > b? a : b ; Load r18 with the maximum numeric value of a and b. Note: This feature was introduced in AVRASM 2.1 and is not available in 2.0 or earlier versions. Functions The following functions are defined: LOW(expression) returns the low byte of an expression

Página 6 de 6 HIGH(expression) returns the second byte of an expression BYTE2(expression) is the same function as HIGH BYTE3(expression) returns the third byte of an expression BYTE4(expression) returns the fourth byte of an expression LWRD(expression) returns bits 0-15 of an expression HWRD(expression) returns bits 16-31 of an expression PAGE(expression) returns bits 16-21 of an expression EXP2(expression) returns 2 to the power of expression LOG2(expression) returns the integer part of log2(expression) The following functions are only defined in AVRASM2: INT(expression) Truncates a floating point expression to integer (ie discards fractional part) FRAC(expression) Extracts fractional part of a floating point expression (ie discards integer part). Q7(expression) Converts a fractional floating point expression to a form suitable for the FMUL/FMULS/FMULSU instructions. (sign + 7-bit fraction) Q15(expression) Converts a fractional floating point expression to a form suitable for the FMUL/FMULS/FMULSU instructions. (sign +15-bit fraction) ABS() Returns the absolute value of a constant expression. DEFINED(symbol) Returns true if symbol is previously defined using.equ/.set/.def directives. Normally used in conjunction with.if directives (.if defined(foo)), but may be used in any context. It differs from other functions in that parentheses around its argument are not required, and that it only makes sense to use a single symbol as argument. STRLEN(string) returns the length of a string c+onstant, in bytes.