ECE 372 Microcontroller Design Assembly Programming Arrays. ECE 372 Microcontroller Design Assembly Programming Arrays

Similar documents
ECE 372 Microcontroller Design Basic Assembly Programming. ECE 372 Microcontroller Design Basic Assembly Programming

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

MACHINE LEVEL REPRESENTATION OF DATA

COMP2611: Computer Organization. Data Representation

CHW 261: Logic Design

Introduction to Computers and Programming. Numeric Values

Number System. Introduction. Decimal Numbers

COMP Overview of Tutorial #2

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

Digital Fundamentals

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

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

COMP2121: Microprocessors and Interfacing. Number Systems

CS 101: Computer Programming and Utilization

Number representations

Number Systems. Both numbers are positive

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

CMPE223/CMSE222 Digital Logic Design. Positional representation

Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

Moodle WILLINGDON COLLEGE SANGLI. ELECTRONICS (B. Sc.-I) Introduction to Number System

Chapter 3: Arithmetic for Computers

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

M1 Computers and Data

The type of all data used in a C++ program must be specified

Inf2C - Computer Systems Lecture 2 Data Representation

Module 2: Computer Arithmetic

Floating Point Arithmetic

Introduction to Computer Science-103. Midterm

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

EE 3170 Microcontroller Applications

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

BINARY SYSTEM. Binary system is used in digital systems because it is:

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

Chapter 1 Review of Number Systems

Chapter 2 Data Representations

World Inside a Computer is Binary

Introduction to Numbering Systems

Recap from Last Time. CSE 2021: Computer Organization. It s All about Numbers! 5/12/2011. Text Pictures Video clips Audio

Integers and Floating Point

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Computer Organization

Data Representations & Arithmetic Operations

CS & IT Conversions. Magnitude 10,000 1,

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

LECTURE #21: G-CPU & Assembly Code EEL 3701: Digital Logic and Computer Systems Based on lecture notes by Dr. Eric M. Schwartz

Final Labs and Tutors

Objectives. Connecting with Computer Science 2

IBM 370 Basic Data Types

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

Chapter Three. Arithmetic

Numeric Encodings Prof. James L. Frankel Harvard University

Harry H. Porter, 2006

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

The type of all data used in a C (or C++) program must be specified

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

Number Systems CHAPTER Positional Number Systems

ECE 3120 Computer Systems Arithmetic Programming

Lecture 2: Number Systems

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

Exam I Review February 2017

Numbering systems. Dr Abu Arqoub

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

What is an Addressing Mode?

2) [ 2 marks] Both of the following statements cause the value $0300 to be stored in location $1000, but at different times. Explain the difference.

Computer Organisation CS303

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

HC11 Instruction Set Architecture

Chapter 2 Bits, Data Types, and Operations

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

HC11 Instruction Set Architecture

Number Systems Base r

ECE331: Hardware Organization and Design

UNIT 7A Data Representation: Numbers and Text. Digital Data

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

Number Systems and Their Representations

Chapter 2. Data Representation in Computer Systems

Organisasi Sistem Komputer

data within a computer system are stored in one of 2 physical states (hence the use of binary digits)

Divide: Paper & Pencil

Level ISA3: Information Representation

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

ECOM 2325 Computer Organization and Assembly Language. Instructor: Ruba A.Salamah INTRODUCTION

Numeral Systems. -Numeral System -Positional systems -Decimal -Binary -Octal. Subjects:

Chapter 2 Bits, Data Types, and Operations

The. Binary. Number System

Chapter 2: Number Systems

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

Transcription:

Assembly Programming Arrays Assembly Programming Arrays Array For Loop Example: unsigned short a[]; for(j=; j<; j++) { if(a[j]==) PORTT=x; else PORTT=x; } Programming Steps: Initialize J Compare J to If Not Less than, End Loop Else Load a[j] If a[j] == PORT T = Else PORT T = Increment J Repeat Loop (Step ) Array For Loop Example: unsigned short a[]; for(j=; j<; j++) { if(a[j]==) PORTT=x; else PORTT=x; } Programming Steps: Initialize J Compare J to If Not Less than, End Loop Else Load a[j] If a[j] == PORT T = Else PORT T = Increment J Repeat Loop (Step ) Assembly Code: ldaa # ; Initialize J ldx #$ ; Initialize index to A[] Loop: cmpa # ; Compare J to bge EndLoop ; Else!(J<) ldd,x ; load A[J] cpd # ; Compare J to bne Else ; Else!(A[J]==) ldab # ; Value to write to PORT T bra EndIf Else: ldab # ; Value to write to PORT T EndIf:stab PTT ; Write value to PORT T adda # ; Increment J inx ; Increment A[J] inx ; Need to increment by bra Loop ; Repeat Loop EndLoop: ; do something else Will this code work? NO! ldd overwrite value of J How can we correct this? Assembly Programming Arrays Array For Loop Example: unsigned short a[]; for(j=; j<; j++) { if(a[j]==) PORTT=x; else PORTT=x; } Programming Steps: Initialize J Compare J to If Not Less than, End Loop Else Load a[j] If a[j] == PORT T = Else PORT T = Increment J Repeat Loop (Step ) Assembly Code: ldaa # ; Initialize J ldx #$ ; Initialize index to A[] Loop: cmpa # ; Compare J to bge EndLoop ; Else!(J<) staa $ ; Store J to RAM ldd,x ; load A[J] cpd # ; Compare J to bne Else ; Else!(A[J]==) ldab # ; Value to write to PORT T bra EndIf Else: ldab # ; Value to write to PORT T EndIf:stab PTT ; Write value to PORT T ldaa $ ; Read J from RAM adda # ; Increment J inx ; Increment A[J] inx ; Need to increment by bra Loop ; Repeat Loop EndLoop: ; do something else We need to store value of J to memory and reload it when needed Time for Fun (or maybe not?) Gallon Gallon Gallon

Humor There are types of people in the world: Those who get binary and those who don t Information Information vs Data An abstract description of facts, processes or perceptions How can we represent information? How can we represent changing information? We need to associate different values with different events Data Individual fact value or set of facts or values Measurement or storage September th October, $ Trillion Information vs Data Information vs Data Information is data with context or meaning Data Representation Data Representation The same data can be represented with: Different symbols English, Cyrillic, Arabic Different numeric bases Binary, Octal, Hexadecimal, Decimal Different formats Little Endian, Big Endian, Binary Coded Decimal International Talk Like a Pirate Day: Date of your first ECE midterm: How much Bill Gates earns per second: Number of pennies to fill Empire State Building September th October, $ Trillion

Decimal Numbers Uses the ten numbers from to Each column represents a power of Thousands ( ) column Hundreds ( ) column Tens ( ) column Ones ( ) column Binary Numbers Uses the two numbers from to Every column represents a power of Eights ( ) column Fours ( ) column Twos ( ) column Ones ( ) column = x + x + x + x = x + x + x + x Binary Numbers Convert the following value from binary (zero s and one s) to a decimal value: = * + * + * + * + * + * + * + * = * + * + * + * + * + * + * + * = Choose your answer: A), B) C) D)

Converting from Decimal to Binary: Divide decimal number by and insert remainder into new binary number Continue dividing quotient by until the quotient is Example: Convert decimal number to binary Decimal Number divide by - insert remainder Binary Number Continue dividing since quotient () is greater than divide by - insert remainder Example: Convert decimal number to binary (cont) Decimal Number Binary Number divide by - insert remainder Continue dividing since quotient () is greater than divide by - insert remainder Since quotient is, we can conclude that is in binary Continue dividing since quotient () is greater than Convert the following decimal value to a binary (zero s and one s) value: Choose your answer: A) B) C) D) Generally, a number can be converted from one base to another by Converting the number to base Then, converting the base ten number to the desired base using the divide-by-n method May not always be the easiest way

Hexadecimal Numbers Uses the ten numbers from to and six letter A to F Each column represents a power of A C Binary Decimal Hexadecimal A B C D EF?? A C = A* + * + C* + * = * + * + * + * =, Hexadecimal Numbers Each position actually represents four base two positions Used as compact means to write binary numbers Often called just hex F Binary Decimal Hexadecimal A B C D EF?? Convert the following hexadecimal value to a binary (zero s and one s) value: CAB Choose your answer: A) B) C) D)

Big vs Little Endian Big Endian MSB (Most Significant Byte) is at lowest address, MIPS, Sparc, HC Little Endian LSB (Least Significant Byte is at lowest address x, DEC $FFFE lower address $FFFF higher address MSB LSB Bit $ $ $ $ $ $ $CC LDD immediate addressing $ MSB of value to be stored in D $ LSB of value to be stored in D $C CPD immediate addressing $ Compare to Value $E Positive vs Negative Numbers Negative numbers are common How can we represent negative numbers in binary? Signed-magnitude Use leftmost bit for sign bit So - would be: One s Complement Invert all bits for negative numbers So - would be: Positive vs Negative Numbers Positive vs Negative Numbers Two s Complement Allows us to perform subtraction using addition No need for dedicated subtractor within CPU s ALU Two s complement of a number added to the number itself will equal zero So - would be: + = (with carry of, ignored) Invert all bits and add to get complement of a number Fast conversion: find first from right, invert after Decimal + + + + - Signed- Magnitude - One s Two s Complement Complement - - - () + (-) () - - - - Are we missing a value?

Positive vs Negative Numbers Data Ranges Unsigned to n - Signed-Magnitude - n- - to n- - One s Complement - n- - to n- - Two s Complement - n- to n- - Positive vs Negative Numbers Determine the two s complement representation for the following decimal numbers (assume we are using -bit binary numbers): - - - - Overflow Overflow Occurs then a result cannot be represented with given number of bits Either the result is too large magnitude of positive or negative Overflow Detecting Overflow Can detect overflow by detecting when the two numbers sign bits are the same but the result s sign bit is different If the two numbers sign bits are different, overflow is impossible Adding a positive and negative can t exceed largest magnitude positive or negative + + + overflow overflow no overflow

Overflow Binary Coded Decimal Binary Coded Decimal Each digit of a decimal number is represented as a -bit binary number Often used for -segment displays RBI RBO LT A A A A +V +V CC a b c d e f g Common-anode LED display a b c d e f g dp dp +V Binary Undefined Undefined Undefined Undefined Undefined Undefined BCD } = (BCD) ASCII Characters Real Numbers A B C D E F Real Numbers How can we represent a real number (ie numbers that contain a fractional part)? Fixed Point Numbers Note: our C compiler already has built-in routines to deal with real numbers However the computational needs will be significant Control characters Printable characters ()

Fixed Point Numbers Fixed Point Numbers Real number with fixed number of digits before and after radix point N-bits used to represent integer part M-bits used to represent fractional part Unsigned range: to M + / N - - - - Fixed Point Numbers = * + * + * + * + - - - - * - + * - + * - + * - = * + * + * + * + / / / / * + * + * + * = Fixed Point Numbers = * + * + * + * + - - - - * - + * - + * - + * - = * + * + * + * + / / / / * + * + * + * = Fixed Point Numbers () + () = * + * + * + * + - - - - * - + * - + * - + * - = * + * + * + * + / / / / * + * + * + * =

Floating Point Numbers Floating Point Numbers Real number representation similar to scientific notation Real number representation similar to scientific notation x = M * B E x = M * E Base (B) Base of the numbering systems considered Binary () for computer based implementations We will assume base of for remaining description Mantissa (M) Digits corresponding to the magnitude Stored in a normalized form, where the first bit is assumed to be is the only possible non-zero number in binary Remaining bits correspond to fraction values (similar to fixed point) Sign (S) Indicating positive of negative number Positive, Negative - - - - - - Floating Point Numbers Floating Point Numbers Real number representation similar to scientific notation x = M * E Exponent (E) Needs to represent both positive and negative values Stored exponent is adjust using the exponent bias Exponent bias = N- -, where N is the number of bits in the exponent E Actual = E Stored E Bias Example, -bit exponent: E Bias = - - = E Stored = = E Actual = - = Example: Convert the value to floating point representation Determine sign bit: - is negative, S = Convert to binary: = Normalize number = * Determine exponent E Stored = E Actual + E Bias Mantissa E Stored = + = =

Floating Point Numbers Real number representation similar to scientific notation Zero x = M * E Due to assuming a leading in the mantissa, we cannot directly represent the value using floating point Defined special case for value of Define special case: Exponent and mantissa of all s corresponds to the value Other special cases exist: +/- Infinity Demoralized value Not a Number Floating Point Numbers IEEE Standard for Binary Floating-Point Arithmetic (IEEE ) Single Precision Floating Point Double Precision Floating Point Data vs Information What does the bit pattern mean: Unsigned: decimal Sign-Magnitude: - decimal s complement: - decimal s complement: - decimal Fixed point bitbit: decimal BCD: =B (Undefined) = ASCII: HC Opcode: $ = ADCA (Add with Carry to A, Ext Addressing) Information Representation Text Page page letter x inches, x point characters ASCII bit: xx = bits Kbytes Fax Page Scan Fax low resolution x dots/inch xxx = dots Kbytes (B/W) DVD Mbit/sec hours xxx = Mbit Approximately Gbytes

Information Representation Humor Digital Audio khz sampling rate bit/channel =^ Stereo How many seconds of sound fit in kbyte EPROM mono? Mbyte floppy mono? Mbyte CD Rom stereo?