CIS 020 Assembly Programming Chapter 07 - Decimal Arithmetic Operations © John Urrutia 2012, All Rights Reserved.5/27/20121.

Slides:



Advertisements
Similar presentations
Using Registers Ch.7 – p.158 Topic 1. Base - Displacement See page 159 PACKPDEC(3),ZDEC(3)
Advertisements

Fixed Point Numbers The binary integer arithmetic you are used to is known by the more general term of Fixed Point arithmetic. Fixed Point means that we.
Programs & Defining Data Ch.5 – pp Data in Computer Memory See page Byte locations in memory - One character per byte location.
ICS312 Set 2 Representation of Numbers and Characters.
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
DAT2343 Comparison of The LMC and General Computer Models © Alan T. Pinck / Algonquin College; 2003.
7-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
CIS 020 Assembly Programming Chapter 02 - Numbering Systems & Data Representation © John Urrutia 2012, All Rights Reserved.5/27/20121.
Assembly Language and Computer Architecture Using C++ and Java
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.

Assembly Language and Computer Architecture Using C++ and Java
Data types and variables
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
The Binary Number System
COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter.
Binary Number Systems.
The Binary Number System
Data Representation Number Systems.
Simple Data Type Representation and conversion of numbers
Information Representation (Level ISA3) Floating point numbers.
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
The 8051 Microcontroller and Embedded Systems
Number Systems Part 2 Numerical Overflow Right and Left Shifts Storage Methods Subtraction Ranges.
How Computers Work Dr. John P. Abraham Professor UTPA.
Machine Instruction Characteristics
EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,
Data Representation in Computer Systems
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Java Software Solutions Lewis and Loftus Chapter 5 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. More Programming Constructs.
CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
7-1 Chapter 7.  Basic Arithmetic Verbs  Options Available with Arithmetic Verbs  COMPUTE Statement  Signed Numbers in Arithmetic Operations  Intrinsic.
The Hexadecimal Number System and Memory Addressing ISAT 121.
Floating Point Arithmetic
CPS120: Introduction to Computer Science Operations Lecture 9.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
7-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Significant Figure Rules RulesExamples The following are always significant Non zero digits Zeros between non zero digits Zero to the right of a non zero.
CIS 020 Assembly Programming Chapter 11 - Binary Operations Using RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
1 2.1 Introduction A bit is the most basic unit of information in a computer. –It is a state of “on” or “off” in a digital circuit. –Sometimes these states.
CIS 020 Assembly Programming Chapter 06 - Comparisons & Logical control Procedures © John Urrutia 2012, All Rights Reserved.5/27/20121.
MECH1500 Chapter 3.
Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.
CHAPTER 3: Number Systems
CIS 020 Assembly Programming Chapter 08 - Advanced Decimal Arithmetic Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.
CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS.
CIS 020 Assembly Programming Chapter 05 - Move Statements © John Urrutia 2012, All Rights Reserved.5/27/20121.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Chapter 1 Representing Data in a Computer. 1.1 Binary and Hexadecimal Numbers.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Module 2.2 Errors 03/08/2011. Sources of errors Data errors Modeling Implementation errors Absolute and relative errors Round off errors Overflow and.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Dr. ClincyLecture 2 Slide 1 CS Chapter 2 (1 of 5) Dr. Clincy Professor of CS Note: Do not study chapter 2’s appendix (the topics will be covered.
Thinking Mathematically
Dr. Clincy Professor of CS
Floating Point Numbers: x 10-18
Data Representation in Computer Systems
MISP Assembly.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
MIPS Assembly.
Recent from Dr. Dan Lo regarding 12/11/17 Dept Exam
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
DATA TYPES AND OPERATIONS
Computer Organization and Assembly Language
Presentation transcript:

CIS 020 Assembly Programming Chapter 07 - Decimal Arithmetic Operations © John Urrutia 2012, All Rights Reserved.5/27/20121

Decimal Numbers Zoned-Decimal (printable character) format, 10 Bytes, can’t be used for calculations. To be used in calculations they must be converted into the Packed-Decimal (non-printable) format, 6 Bytes. Packing strips the zone nibble for each byte and shifts the decimal nibble to the left. © John Urrutia 2012, All Rights Reserved.25/27/2012 Print Character Hexadecimal ValueF0F1F2F3F4F5F6F7F8F9 Numeric Value Hexadecimal Value F

Decimal Numbers Unless otherwise designated Zone-Decimal numbers are considered positive values. The sign of a number is stored in the rightmost byte For Zone-Decimal it is in the Zone portion of the byte For Packed-Decimal it is in the Digit portion of the byte © John Urrutia 2012, All Rights Reserved.35/27/2012

Decimal Numbers Unless otherwise designated Zone-Decimal numbers are considered positive values. Packed-Decimal format carries the sign of the number in the rightmost nibble The sign is base on the following values: © John Urrutia 2012, All Rights Reserved.45/27/2012 Numeric Value Hexadecimal Value F PositiveNegative 1010 – A 1100 – C 1110 – E 1111 – F 1011 – B D Preferred Values

Convert from ZD to PD format PACK instruction converts Zone-Decimal numbers to Packed-Decimal numbers, and is storage to storage. Syntax of Instruction Op Code – PACK Operand 1 – label or address Operand 2 – label or address Instruction processes right to left © John Urrutia 2012, All Rights Reserved.55/27/2012

Convert from ZD to PD format Operand 1 determines how many bytes to process The Maximum number of bytes to pack is 16 which limits the length of Operand 2 to 16 bytes The length needed for Operand 1 is determined by this formula: (length of operand 2/2) + 1 The Assembler will not warn you if you make a mistake in this calculation © John Urrutia 2012, All Rights Reserved.65/27/2012

PACK examples © John Urrutia 2012, All Rights Reserved.75/27/2012 Normal – 5 bytes pack exactly into 3 bytes X'51234F'

PACK examples © John Urrutia 2012, All Rights Reserved.85/27/2012 Operand 1 short – 5 bytes truncate into 2 bytes

PACK examples © John Urrutia 2012, All Rights Reserved.95/27/2012 Operand 2 short – 3 bytes pad left into 3 bytes

PACK examples © John Urrutia 2012, All Rights Reserved.105/27/2012 Self Packed

PACK examples © John Urrutia 2012, All Rights Reserved.115/27/2012 Maximum data packed 45F ’

Relative Addressing Just like the previous instructions we can modify the length and offset of labels for PACK instructions in the same way. Each operand can be modified © John Urrutia 2012, All Rights Reserved.125/27/2012

PACK Constants Use the DC assembler directive to define all constant values. The data type identifier will dictate how much storage will be allocated to this constant. Sign is allowed but decimal point is not. You are responsible for knowing where the decimal point goes! © John Urrutia 2012, All Rights Reserved.135/27/2012

The Decimal Instructions Order of operation When you evaluate a numeric expression the order of operations govern the outcome. PEMDAS – mnemonic for the priority. Parenthesis – from innermost to outermost Exponentiation – Multiplication – Division – Addition – Subtraction – © John Urrutia 2012, All Rights Reserved.145/27/2012 Processed left to right

The Decimal Instructions AP, SP – All are storage-to-storage instructions just like PACK Sets the condition code, branch Mask 01 – condition code = 3Overflow / Underflow 02 - condition code = 2Plus / Positive 04 - condition code = 1Minus / Negative 08 - condition code = 0Zero 14 – not condition code = 3No Overflow / Underflow 13 – not condition code = 2Not Plus / Positive 11 – not condition code = 1Not Minus / Negative 07 – not condition code = 0Not Zero © John Urrutia 2012, All Rights Reserved.155/27/2012

AP – add packed Syntax of Instruction Op Code – AP Operand 1 –first addend (before execution) and sum (after execution) Operand 2 – second addend Both Operands must be in packed-decimal format Operand 1 should be one byte larger than the size of Operand 2 to prevent overflow conditions. All packed-decimal instructions set the sign to X’C’ – Positive or X’D’ – Negative © John Urrutia 2012, All Rights Reserved.165/27/2012

AP – add packed Example: CC=2 Plus value © John Urrutia 2012, All Rights Reserved.175/27/2012

AP – add packed Example: Data Exception Occurs (S0C7) © John Urrutia 2012, All Rights Reserved.185/27/2012

AP – add packed to multiply Example: CC=2 Plus value © John Urrutia 2012, All Rights Reserved.195/27/2012

Convert from PD to ZD format UNPK (unpack) instruction converts Packed-Decimal numbers to Zone-Decimal numbers, and is storage to storage. Syntax of Instruction Op Code – UNPK Operand 1 – label or address Operand 2 – label or address Instruction processes right to left © John Urrutia 2012, All Rights Reserved.205/27/2012

Convert from PD to ZD format Operand 1 determines how many bytes to process The Maximum number of bytes to unpack is 16 and so is the length of Operand 2 The length needed for Operand 1 is determined by this formula but can never be longer 16 bytes: (length of operand 2)*2 – 1 The Assembler will give a syntax error if the length of either operand is greater than 16 bytes © John Urrutia 2012, All Rights Reserved.215/27/2012

Convert from PD to ZD format Mixed length Operands cause the following: If Operand 1 can contain more digits than Operand 2, Operand 1 is padded to the left with zeros – X’F0’ If Operand 1 can’t contain all the digits in Operand 2, Operand 1 High-order values are truncated. © John Urrutia 2012, All Rights Reserved.225/27/2012

UNPK examples © John Urrutia 2012, All Rights Reserved.235/27/2012 Normal – 3 bytes unpack exactly into 5 bytes

UNPK examples Operand 1 larger – 2 bytes unpack into 5 bytes High-order bytes padded with zeros © John Urrutia 2012, All Rights Reserved.245/27/2012

UNPK examples Operand 2 larger – 3 bytes unpack into 3 bytes High-order byte values (1 & 2) truncated © John Urrutia 2012, All Rights Reserved.255/27/2012

UNPK examples Maximum Operand 1 – 16 Bytes © John Urrutia 2012, All Rights Reserved.265/27/2012

Securing the Sign ± The last digit of an unpacked number contain the sign of the number in the Zone portion Any arithmetic operation changes the sign to the preferred ‘C’ or ‘D’ these zone values are NOT numbers © John Urrutia 2012, All Rights Reserved.275/27/2012 HexCharacter X’C0’{ X’C1’A X’C2’B X’C3’C X’C4’D X’C5’E X’C6’F X’C7’G X’C8’H X’C9’I HexCharacter X’D0’} X’D1’J X’D2’K X’D3’L X’D4’M X’D5’N X’D6’O X’D7’P X’D8’Q X’D9’R

Securing the Sign ± We must set the zone to F OI – to the rescue Or Immediate is an instruction that allows us to modify any of the bits in a byte. It is used to make sure the last byte of an unpacked field will print as a number. © John Urrutia 2012, All Rights Reserved.285/27/2012

OI – or immediate Syntax of Instruction Op Code – OI Operand 1 –Label or address of byte to change Operand 2 – Mask of bits to turn-on The Mask of the instruction can be any byte of data and all of the on bits (1) will be reflected in the first operand. When securing the sign the address of the last byte of the field is designated. © John Urrutia 2012, All Rights Reserved.295/27/2012

OI – or immediate The Mask value B’ ’ each digit represents a bit that will be turned-on after execution. The byte identified by operand 1 is modified by the mask. © John Urrutia 2012, All Rights Reserved.305/27/2012 Byte Operand X’C7’ B’ ’ Mask Operand X’F0’ B’ ’ Result Byte Operand X’F7’ B’ ’ Each bit is turned on left to right

OI example Correct character for output © John Urrutia 2012, All Rights Reserved.315/27/2012

Countdown to the end We have learned enough at this point to be able to create a count controlled loop structure which we can use to simulate the factorial function in mathematics. Using just the instructions we have learned create a program that will : Solve factorial problems for 0 through 18. or Identify the smallest 16 digit Fibonacci number © John Urrutia 2012, All Rights Reserved.325/27/2012

Factorial and Fibonacci Factorial In mathematics, the factorial of a non-negative integer n, is the product of all positive integers less than or equal to n. ea. 5 factorial is equal to 120 = 5 * 4 * 3 * 2 * 1 ea. 6 factorial is equal to 720 = 6 * 5 * 4 * 3 * 2 * 1 © John Urrutia 2012, All Rights Reserved.335/27/2012

Factorial and Fibonacci Fibonacci In mathematical terms, the sequence F n of Fibonacci numbers is defined by the recurrence relation F n = F n-1 + F n-2 with seed values of F 0 = 0 and F 1 = 1 ea. F 2 = 1, F 3 = 2, F 4 = 3, F 5 = 5, F 6 = 8, F 7 = 13 The smallest 2 digit Fibonacci number is 13. © John Urrutia 2012, All Rights Reserved.345/27/2012