ECE 3120 Computer Systems Arithmetic Programming

Similar documents
Lecture 11: Advanced Arithmetic Instructions

Lecture 5 Assembly Programming: Arithmetic

Chapter 2: HCS12 Assembly Programming. EE383: Introduction to Embedded Systems University of Kentucky. Samir Rawashdeh

EE4390 Microprocessors

Chapter 2 HCS12 Assembly Language

Reading Assignment. 68HC12 Instruction Set. M68HC12 Instruction Set Categories. Some Tips. Endianness (Byte Order) Load and Store Instructions

Table 1: Mnemonics Operations Dictionary. Add Accumulators Add B to Y. Add with carry to B. Add Memory to B. Add 16-bit to D And B with Memory

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-470/570: Microprocessor-Based System Design Fall 2014.

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

The Motorola 68HC11 Instruc5on Set

ECE3120: Computer Systems Hardware & Software Development Tools

Programming the Motorola MC68HC11 Microcontroller

HC 11 Instructions! From Alex Hollowayʼs notes with! many thanks!

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

CMPEN 472 Sample EXAM II

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

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

EE 3170 Microcontroller Applications

HC11 Instruction Set

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

MIGRATING TO THE 68HC12 IN C

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Addressing Mode Description Addressing Mode Source Format Abbrev. Description

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Lecture 8: Addition, Multiplication & Division

538 Lecture Notes Week 2

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

ME4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 7

CPS 104 Computer Organization and Programming

Exam I Review February 2017

Most of the HC12 s instructions access data in memory There are several ways for the HC12 to determine which address to access

9 Multiplication and Division

Menu Computer Organization Programming Model for the an example microprocessors (the G-CPU & Motorola 68HC11) Assembly Programming Look into my...

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

MC9S12 Assembler Directives A Summary of MC9S12 Instructions Disassembly of MC9S12 op codes. Summary of HCS12 addressing modes ADDRESSING MODES

COMP 303 Computer Architecture Lecture 6

CHW 261: Logic Design

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.

Microcontrollers. 2IN60: Real-time Architectures (for automotive systems) Mike Holenderski,

carry in carry 1101 carry carry

1. Memory Mapped Systems 2. Adding Unsigned Numbers

Module 2: Computer Arithmetic

Sample Problem Set #1

It translates (converts) assembly language to machine code.

CHAPTER 2 (b) : AND CODES

Numbering systems. Dr Abu Arqoub

Timing for Ripple Carry Adder

Integer Multiplication and Division

Ryerson University Department of Electrical and Computer Engineering ELE 538 Microprocessor Systems Final Examination December 8, 2003

Mnem. Meaning Format Operation Flags affected ADD Addition ADD D,S (D) (S)+(D) (CF) Carry ADC Add with ADC D,C (D) (S)+(D)+(CF) O,S,Z,A,P,C

Department of Computer Science and Engineering

Homework 3. Assigned on 02/15 Due time: midnight on 02/21 (1 WEEK only!) B.2 B.11 B.14 (hint: use multiplexors) CSCI 402: Computer Architectures

Introduction to the 9S12 Microcontroller

Signed number Arithmetic. Negative number is represented as

Octal & Hexadecimal Number Systems. Digital Electronics

Lecture 2: Number Systems

Adding Binary Integers. Part 4. Negative Binary. Integers. Adding Base 10 Numbers. Adding Binary Example = 10. Arithmetic Logic Unit

Lecture 9 Subroutines

COE 202: Digital Logic Design Number Systems Part 2. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

EEM336 Microprocessors I. Arithmetic and Logic Instructions

NUMBER OPERATIONS. Mahdi Nazm Bojnordi. CS/ECE 3810: Computer Organization. Assistant Professor School of Computing University of Utah

2. Arithmetic Instructions addition, subtraction, multiplication, divison (HCS12 Core Users Guide, Sections 4.3.4, and ).

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

Disassembly of an HC12 Program It is sometimes useful to be able to convert HC12 op codes into mnemonics. For example, consider the hex code:

538 Lecture Notes Week 3

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

HC11 Instruction Set Architecture

538 Lecture Notes Week 3

HC11 Instruction Set Architecture

More complicated than addition. Let's look at 3 versions based on grade school algorithm (multiplicand) More time and more area

Motorola HC11. Fun with Microcontrollers and Embedded Systems

MACHINE LEVEL REPRESENTATION OF DATA

Adding Binary Integers. Part 5. Adding Base 10 Numbers. Adding 2's Complement. Adding Binary Example = 10. Arithmetic Logic Unit

Coe538 Final Study Guide 2016 (Questions & Answers)

Lab 7: Asynchronous Serial I/O

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

Fast Arithmetic. Philipp Koehn. 19 October 2016

Arithmetic Instructions

Organisasi Sistem Komputer

EC 333 Microprocessor and Interfacing Techniques (3+1)

Number Systems. TA: Mamun. References: Lecture notes of Introduction to Information Technologies (ITEC 1011) by Dr Scott MacKenzie

EE 308 Spring The HCS12 has 6 addressing modes

x= suppose we want to calculate these large values 1) x= ) x= ) x=3 100 * ) x= ) 7) x=100!

SECTION 6 CENTRAL PROCESSING UNIT

Introduction to Embedded Systems. Some Nagging

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-470/570: Microprocessor-Based System Design Fall 2014.

Number Systems and Computer Arithmetic

Chapter 4 Section 2 Operations on Decimals

Chapter 2 Data Representations

Chapter 5: Computer Arithmetic. In this chapter you will learn about:

Chapter 3 DATA REPRESENTATION

ECE260: Fundamentals of Computer Engineering

COMPUTER ORGANIZATION AND. Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers

Using the stack and the stack pointer

ENE 334 Microprocessors

Fri. Aug 25 Announcements

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

CMPE223/CMSE222 Digital Logic Design. Positional representation

N bit is set if result of operation in negative (MSB = 1) Z bit is set if result of operation is zero (All bits = 0)

Transcription:

ECE 3120 Computer Systems Arithmetic Programming Manjeera Jeedigunta http://blogs.cae.tntech.edu/msjeedigun21 Email: msjeedigun21@tntech.edu Tel: 931-372-6181, Prescott Hall 120

Today: Multiplication and Division Examples BCD

Multiplication and Division Table 2.1 Summary of 68HC12 multiply and divide instructions Mnemonic Function Operation EMUL EMULS MUL EDIV EDIVS FDIV IDIV IDIVS unsigned 16 by 16 multiply signed 16 by 16 multiply unsigned 8 by 8 multiply unsigned 32 by 16 divide signed 32 by 16 divide 16 by 16 fractional divide unsigned 16 by 16 integer divide signed 16 by 16 integer divide (D) (Y) Y:D (D) (Y) Y:D (A) (B) A:B (Y:D) (X) quotient Y remainder D (Y:D) (X) quotient Y remainder D (D) (X) X remainder D (D) (X) X remainder D (D) (X) X remainder D

Example 2.10 Write an instruction sequence to multiply the 16-bit numbers stored at $800-$801 and $802-$803 and store the product at $900-$903. Original Operands in Memory Product in Memory D Y 2 st operand LSB 2 st operand MSB 1 st operand LSB 1 st operand MSB $803 $802 $801 $800 emul LSBs MSBs $903 $902 $901 $900 D : Y ldy $800 ;load 1 st operand into Y ldd $802 ;load 2 nd operand into D emul ; Multiplying the numbers assuming unsigned numbers sty $900 ;storing the upper 16 bits std $902 ;storing the lower 16 bits

Example 2.11 Write an instruction sequence to divide the signed 16-bit number stored at $1005-$1006 by the signed 16-bit number stored at $1020-$1021 and store the quotient and remainder at $1030-$1031 and $1032-$1033, respectively. D LSB of Dividend MSB of Dividend $1006 $1005 idivs D LSB of Rem MSB of Rem $1033 $1032 X LSB of Divisor MSB of Divisor $1021 $1020 X LSB of Quotient MSB of Quotient $1031 $1030 ldd $1005 ;load the dividend into D ldx $1020 ;load the divisor into X idivs ; perform signed division stx $1030 ;storing the quotient std $902 ;storing the remainder

Illustration of 32-bit by 32-bit Multiplication - Two 32-bit numbers M and N are divided into two 16-bit halves M = M H M L N = 16-bit 16-bit 16-bit 16-bit Address P ~ P+1 P+2 ~ P+3 P+4 ~ P+5 P+6 ~ P+7 Final product M N msb lsb Note: msb stands for most significant byte and lsb for least significant byte Figure 2.3 Unsigned 32-bit by 32-bit multiplication

Example 2.12 Write a program to multiply two unsigned 32-bit numbers stored at M~M+3 and N~N+3, respectively and store the product at P~P+7. Solution: org $1000 M ds.b 4 ;Multiplicand 4 bytes N ds.b 4 ;Multiplier 4 bytes P ds.b 8 ;Product 8 bytes org $1500 ldd M+2 ;place M L in D ldy N+2 ;place in Y emul ; compute M L sty P+4 std P+6 ldd M ldy N emul Address ; compute M H sty P std P+2 ldd M ldy N+2 emul ; compute M H 16-bit P ~ P+1 P+2 ~ P+3 P+4 ~ P+5 P+6 ~ P+7 msb 16-bit 16-bit 16-bit lsb Final product M N Note: msb stands for most significant byte and lsb for least significant byte Figure 2.3 Unsigned 32-bit by 32-bit multiplication

16-bit 16-bit 16-bit 16-bit Example 2.12 contd ; add M H to memory locations P+2~P+5 addd P+4 std P+4 tfr Y,D adcb P+3 stab P+3 adca P+2 staa P+2 ; propagate carry to the most significant byte ldaa P+1 adca #0 ; add carry to the location at P+1 staa P+1 ; ldaa P ; add carry to the location at P adca #0 ; staa P ; ; compute M L ldd M+2 ldy N emul Address P ~ P+1 P+2 ~ P+3 P+4 ~ P+5 P+6 ~ P+7 msb lsb Final product M N Note: msb stands for most significant byte and lsb for least significant byte Figure 2.3 Unsigned 32-bit by 32-bit multiplication

Example 2.12 contd.. ; add M L to memory locations P+2 ~ P+5 addd P+4 std P+4 tfr Y,D adcb P+3 stab P+3 adca P+2 staa P+2 ; propagate carry to the most significant byte clra adca P+1 staa P+1 ldaa P adca #0 staa P end 16-bit 16-bit 16-bit 16-bit Address P ~ P+1 P+2 ~ P+3 P+4 ~ P+5 P+6 ~ P+7 Final product M N msb lsb Note: msb stands for most significant byte and lsb for least significant byte Figure 2.3 Unsigned 32-bit by 32-bit multiplication

BCD Numbers and Addition - Each digit is encoded by 4 bits - Two digits are packed into one byte - The addition of two BCD numbers is performed by binary addition and an adjust operation using the DAA instruction. - The instruction DAA can be applied after the instructions ADDA, ADCA, and ABA. - Simplifies I/O conversion For example, the instruction sequence LDAA $800 ADDA $801 DAA STAA $802 adds the BCD numbers stored at $800 and $801 and saves the sum at $802.

Example 2.13 Write a program to convert the 16-bit number stored at $800-$801 to BCD format and store the result at $900-$904. Convert each BCD digit into its ASCII code and store it in one byte. Solution: - A binary number can be converted to BCD format by using repeated division by 10. - The largest 16-bit binary number is 65535 which has five decimal digits. - The first division by 10 obtains the least significant digit, the second division by 10 obtains the second least significant digit, and so on. org $800 data dc.w 12345 ; data to be tested org $900 result ds.b 5 ; reserve bytes to store the result org $1000 ldd data ldy #result ldx #10 idiv addb #$30 ; convert the digit into ASCII code stab 4,Y ; save the least significant digit xgdx ldx #10

idiv adcb #$30 stab 3,Y ; save the second to least significant digit xgdx ldx #10 idiv addb #$30 stab 2,Y ; save the middle digit xgdx ldx #10 idiv addb #$30 stab 1,Y ; save the second most significant digit xgdx addb #$30 stab 0,Y ; save the most significant digit end

Next Program Loops Read Chapter 2.6