Multiplies the word length <ea> times the least significant word in Dn. The result is a long word.

Similar documents
68000 Instruction Set (2) 9/20/6 Lecture 3 - Instruction Set - Al 1

INTRODUCTION TO BRANCHING

INTRODUCTION TO BRANCHING. There are two forms of unconditional branching in the MC68000.

Assembly Language. Operand Size. The internal registers. Computers operate on chunks of data composed of a particular number of bits.

EECE416 :Microcomputer Fundamentals and Design Instruction Sets and Groups

CPE/EE 421 Microcomputers

ADD Add Binary ADD Operation: (Source)+(Destination) Destination

Lab Reports. Program Description (separate page - ONLY IF REQUIRED)

Addressing Modes. To review data transfer instructions and applying the more advanced addressing modes.

Arithmetic for Computers

68000 Architecture. To review the the architecture of the microprocessor.

SEE 3223 Microprocessors. 4: Addressing Modes. Muhammad Mun im Ahmad Zabidi

Math in MIPS. Subtracting a binary number from another binary number also bears an uncanny resemblance to the way it s done in decimal.

Lecture 9. INC and DEC. INC/DEC Examples ADD. Arithmetic Operations Overflow Multiply and Divide

COMPUTER ARITHMETIC (Part 1)

; MC68010/MC /32-8IT VIRTUAL MEMORY MICROPROCESSORS. Advance Information MAY, '1985

MOTOROLA M68000 FAMILY

Tutorial 1 Microcomputer Fundamentals

Number Systems and Their Representations

68000 Architecture, Data Types and Addressing Modes. 9/20/6 Lecture 2 - Prog Model 1

1. bit manipulation instructions such as BTST, BCHG

Module 7: Address Registers & Array Processing

Assembly Assignment 6 - Lottery

Alex Milenkovich 1. CPE/EE 421 Microcomputers: Motorola 68000: Architecture & Assembly Programming. Outline

68000 Assembler by Paul McKee. User's Manual

Freescale Semiconductor, I. Table 1: MCF5206 Power Consumption. 16MHZ 25MHz 33MHz UNITS mw. Notational Conventions

Machine Language and Assembly Language

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

Lecture 5 Assembly Programming: Arithmetic

PART II: Cap. 6 - Linguaggio macchina M68000

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

Lecture 8: Addition, Multiplication & Division

9 Multiplication and Division

ENE 334 Microprocessors

Intel 8086: Instruction Set

Module 2: Computer Arithmetic

stack frame where register An is used as the argument pointer.

Physics 116B Winter 2006: Problem Assignment 8

carry in carry 1101 carry carry

... Executing conditional instructions

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

Freescale Semiconductor, I

Mark Redekopp, All rights reserved. EE 357 Unit 4b. CF Assembly Basics

Arithmetic Instructions

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

Arithmetic Operations

Signed number Arithmetic. Negative number is represented as

ECE260: Fundamentals of Computer Engineering

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI

Integer Multiplication and Division

Chapter Two MIPS Arithmetic

Fast Arithmetic. Philipp Koehn. 19 October 2016

4/8/17. Admin. Assignment 5 BINARY. David Kauchak CS 52 Spring 2017

Computer Organisation CS303

An-Najah National University Faculty of Engineering Electrical Engineering Department Programmable Logic Controller. Chapter 11 Math instruction

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

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

COMP 303 Computer Architecture Lecture 6

EC 333 Microprocessor and Interfacing Techniques (3+1)

Sparse Notes on an MIPS Processor s Architecture and its Assembly Language

EEM336 Microprocessors I. Arithmetic and Logic Instructions

Subroutines. passing data

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017)

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

EXPERIMENT NO.1. A Microcontroller is a complete computer system built on a single chip.

Chapter 5 : Computer Arithmetic

TUTORIAL Assembly Language programming (2)

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

Signed Multiplication Multiply the positives Negate result if signs of operand are different

Organisasi Sistem Komputer

CPS 104 Computer Organization and Programming

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

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

H8/300L Series Programming Manual

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Programming. A. Assembly Language Programming. A.1 Machine Code. Machine Code Example: Motorola ADD

CS 270: Computer Organization. Integer Arithmetic Operations

Lab Cover Page. Lab Date and Time: Teaching Assistant to whom you are submitting

Defining and Using Simple Data Types

8088/8086 Programming Integer Instructions and Computations

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

Review: MIPS Organization

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

CO212 Lecture 10: Arithmetic & Logical Unit

Number System. Introduction. Decimal Numbers

ISA 563 : Fundamentals of Systems Programming

ECE 3120 Computer Systems Arithmetic Programming

Integer Arithmetic. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Chapter 10 - Computer Arithmetic

Programming the Motorola MC68HC11 Microcontroller

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

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10]

CHW 261: Logic Design

COMPUTER ORGANIZATION & ARCHITECTURE

Basic Assembly Instructions

Harry H. Porter, 2006

Outline. EEL-4713 Computer Architecture Multipliers and shifters. Deriving requirements of ALU. MIPS arithmetic instructions

Arithmetic and Bitwise Operations on Binary Data

Transcription:

MATHEMATICAL INSTRUCTIONS Multiply unsigned MULU <ea>,dn Action Notes: Example: Multiplies the word length <ea> times the least significant word in Dn. The result is a long word. 1. The lowest word of Dn contains the multiplier. 2. The result is a -bit long word. 3. The negative (N) and zero (Z) flags are set according to the result. The overflow (V) and carry (C) bits are always cleared since there can never be an overflow or carry with this instruction. MULU #$1,D4 BEFORE 16 15 don't care 1 1 1 1 1 1 1 1 AFTER 16 1 1 15 1 1 1 1 1 1 result extends into upper word -195-

Multiply signed MULS <ea>,dn Action Notes: Example: Multiplies the word length <ea> times the least significant word in Dn. The result is a sign extended long word. 1. The lowest word of Dn contains the multiplier. 2. The result is a -bit long word which takes account of the multiplier and multiplicand s signs. 3. The negative (N) and zero (Z) flags are set according to the result. The overflow (V) and carry (C) bits are always cleared since there can never be an overflow or carry with this instruction. MULS #$1,D4 BEFORE 16 15 don't care 1 1 1 1 1 1 1 1 AFTER 2 19 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 sign extension 15 1 1 1 1 1 1 multiplication result -196-

Divide unsigned DIVU <ea>,dn Action Divides the -bit integer in Dn by the 16-bit integer in <ea>. The most significant word of the -bit result is the remainder; the least significant word is the quotient. 16 15 remainder quotient Notes: 1. There is also a DIVS but you will need to sign extend what s in Dn before you can divide with sign. This can be done using the instruction EXT.L, which extends the lowest word to a long word, for signed numbers. 2. You may use the instruction ANDI.L #$FFFF,Dn to clear bits 16- for unsigned number division. Example: DIVU #1,D4 BEFORE (D4 contains 1 ) Note that 1 = $2 = %1 16 15 1 AFTER (the result is a quotient of 3 1 with a remainder of 2 1 ) 16 15 1 1 1 remainder = 2 quotient = 3-197-

Example: SUppose you want to do a signed divide of - in D4 by 1, i.e. DIVS #1,D4 Consider what happens if you put - in D4 using a MOVE immediate MOVE.W #-,D4 16 15 1 1 1 1 1 1 1 1 1 1 1 The - is sign-extended to a word. You must extend this to a long word before you can do a DIVS EXT.L D4 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 15 1 1 1 1 1 1 1 1 1 1 1 Now you can correctly use the DIVS DIVS #1,D4 to get the resulting quotient of -3 1 with a remainder of -2 1, i.e. (D4) = $FFFE FFFD 16 15 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 remainder = -2 quotient = -3-198-

MATH INSTRUCTIONS Instruction ADDI ADDQ SUB SUBI SUBQ SUBX ADDX SUBA NEG NEGX MULS MULU DIVS DIVU EXT Comments Add a constant, cannot be used with An as a destination. Adds an immediate constant between 1 and 8. flags in normal way Clears Z only if the result is nonzero, i.e. it sets Z to 1 if the result is zero else Z remains unchanged. This instruction subtracts the source and the X bit from the destination. basically the same as SUBX but adds. Doesn t effect status register. Negates (subtracts from zero). WARNING: NEG is NOT a COMPLEMENT. It computes - (Destination) - (X-bit) Adds X bit to destination, then subtracts from zero. Multiply two words. Divides a long word by a word. WARNING: Division by zero generates a TRAP. Sign extend -199-

EXAMPLE: DOUBLE PRECISION ADDITION This program adds two 64-bit (8-byte) numbers together. The program uses: NUM1 NUM2 64-bit number, 8 consecutive bytes 64-bit number, 8 consecutive bytes stored immediately higher in memory than NUM1 Functional specification (pseudocode) A3 = starting address of NUM1 A = A3 + 8 ;starting address of NUM2 A1 = A + 8 ;ending address of NUM2 plus 1 byte X = ;clear X-bit ;loop starting with least significant bytes FOR j = 1,4 DO NUM1(j) = NUM1(j) + NUM2(j) + X; word NUM1 A3 NUM2 A $6A4D $ED5 $A937 $6414 $56C8 $46E6 $76C8 $4AEA start putting results here A1-2-

MC68 assembly code for double precision add program: ORG $5 NUM1 DC.W $6A4D, $ED5,$A937,$6414 NUM2 DC.W $56C8, $46E6,$76C8,$4AEA BYTECNT EQU 8 ;number of bytes to add together MAIN LEA NUM1,A3 ;use A3 for address first number LEA BYTECNT(A3),A ;the second number begins 8 bytes beyond the beginning of the first number - use address register indirect with displacement LEA BYTECNT(A),A1 ;address beyond end of second number MOVEQ #,CCR ;clear the X bit of the SR MOVEQ #BYTECNT-1,D2 ;set up loop counter, adjusted for DBRA. MOVEQ is ok since counter is 7 LOOP MOVE.B -(A),D MOVE.B -(A1),D1 ADDX.B D1,D ;D=D+D1+X-bit MOVE.B D,(A) ;save result in NUM1 DBF D2,LOOP ;repeat 7 times END MAIN -21-

EXAMPLE: BINARY MULTIPLICATION This program multiplies two 8-bit unsigned numbers using a shift and add algorithm to generate a 16-bit product. The multiplier is in D2 and the multiplicand in D1. The product is returned in D1. algorithm: 1. Starting with most significant bit of multiplier, i.e. bit=8 2. Shift product to line up properly (product = 2*product) 3. If multiplier[bit] = 1 then product=product+multiplier 4. Decrement bit. If bit then goto 2. The program uses: MULTIPLICAND MULTIPLIER PRODUCT 8-bit number to be multiplied 8-bit number that MULTIPLICAND is multiplied by -bit result Functional specification (pseudocode) PRODUCT = ; BIT=8 /* starting at MSB */ /*clear PRODUCT*/ FOR j = 1,8 DO /*do for each bit of MULTIPLIER*/ BEGIN PRODUCT = PRODUCT*2; /*shift PRODUCT left by one bit*/ IF MULTIPLIER[9-bit] = 1 THEN PRODUCT = PRODUCT + MULTIPLICAND; /* do calculations from most significant bit to least significant bit */ BIT=BIT-1; /* decrement bit */ END -22-

DETAILED EXAMPLE: multiplier = 61 16 (97 1 ) multiplicant = 6F 16 (111 1 ) multiplier: (D2) = 111 ($ 61) multiplicand (D1) = 111111 ($ 6F) initial product: (D) = ($ ) shift product: (D) = ($ ) MUL[8] = don t add new product (D) = ($ ) shift product: (D) = ($ ) MUL[7] = 1 so add (D1) = 111111 ($ 6F) new product (D) = 111111 ($ 6F) shift product: (D) = 111111 ($ DE) MUL[6] = 1 so add (D1) = 111111 ($ 6F) new product (D) = 1 1111 ($1 4D) shift product: (D) = 1 1111 ($2 9A) MUL[5] = don t add new product (D) = 1 1111 ($2 9A) shift product: (D) = 11 111 ($5 34) MUL[4] = don t add new product (D) = 11 111 ($5 34) shift product: (D) = 11 111 ($A 68) MUL[3] = don t add new product (D) = 11 111 ($A 68) shift product: (D) = 11 111 ($14 D) MUL[2] = don t add new product (D) = 11 111 ($14 D) -23-

shift product: (D) = 111 11 ($29 A) MUL[1] = 1 so add (D1) = 111111 ($ 6F) new product (D) = 111 1111 ($2A F) final answer: (D) = 111 1111 ($2A F) where $2AF = 1767 1 = 97 1 x 111 1-24-

MC68 assembly code for binary multiply program: ORG $5 A DC.W $61 B DC.W $62 RESULT DS.L 1 MAIN CLR.L D ;clear -bit product register MOVE.L D,D1 ;clear upper word for ADD.L MOVE.W A,D1 ;copy multiplicand into D1 MOVE.W B,D2 ;copy multiplier into D2 MOVE.W #16-1,D3 ;loop count = 16-1 for DBRA instruction LOOP ADD.L D,D ;shift product left one bit ADD.W D2,D2 ;shift multiplier left one bit BCC.S STEP ; Use carry to check whether to add. If carry= goto next step. ADD.L D1,D ;if multiplier [15] was one then add multiplicand. STEP DBRA D3,LOOP ;else continue with loop LEA RESULT,A1 ;get where to put answer MOVE.L D,(A1) ;store result END MAIN NOTES: 1. Program uses shift and add algorithm. 2. DBRA is equivalent to DBF and works in most assemblers. -25-

REVIEW for Integer arithmetic functions ADD.<size> <source>,<destination> One operand MUST be a data register; affects all five status codes in CCR Overflow (V) Set if two like-signed numbers (both positive or both negative) are added and the has a different sign. This is causes by the result exceeding the 2 s complement range of numbers, causing the sign bit to change. Mathematically, V = C s C p The V and N flags are pertinent only for signed numbers but are set for all additions. ADDA <ea>,an If the destination is an address, the condition codes are not changed. For adding multiple words, the extend can be used. ADDX Adds two (data) registers or memory locations. However, zero is only cleared if the result is non-zero; otherwise, zero is unchanged. ADD.L D,D2 ADDX.L D1,D3 The above code adds the double precision numbers together: D1 D3 X D D2 Memory to memory adds do not change X, Z. You must set them. For example: MOVE #4,CCR ;sets Z bit, clears all others -26-