CONDITION CODE AND ARITHMETIC OPERATIONS 353156 – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.

Slides:



Advertisements
Similar presentations
Slides created by: Professor Ian G. Harris Efficient C Code  Your C program is not exactly what is executed  Machine code is specific to each ucontroller.
Advertisements

ARM versions ARM architecture has been extended over several versions.
Multiplication – Microprocessor
Embedded System Design Center ARM7TDMI Microprocessor Data Processing Instructions Sai Kumar Devulapalli.
INTRODUCTION TO THE ARM PROCESSOR – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
COMP3221 lec9-logical-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 9: C/Assembler Logical and Shift - I
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
Lecture 5: Decision and Control CS 2011 Fall 2014, Dr. Rozier.
COMP3221: Microprocessors and Embedded Systems--Lecture 7 1 COMP3221: Microprocessors and Embedded Systems Lecture 7: Arithmetic and logic Instructions.
COMP3221: Microprocessors and Embedded Systems--Lecture 7 1 COMP3221: Microprocessors and Embedded Systems Lecture 7: Arithmetic and logic Instructions.
COMP3221 lec08-arith.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 8: C/Assembler Data Processing
COMP3221 lec06-numbers-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 6: Number Systems - II
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
ARM programmer’s model and assembler Embedded Systems Programming.
Topics covered: ARM Instruction Set Architecture CSE 243: Introduction to Computer Architecture and Hardware/Software Interface.
COMP3221 lec07-numbers-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 7: Number Systems - III
8051 ASSEMBLY LANGUAGE PROGRAMMING
Unit-1 PREPARED BY: PROF. HARISH I RATHOD COMPUTER ENGINEERING DEPARTMENT GUJARAT POWER ENGINEERING & RESEARCH INSTITUTE Advance Processor.
ARM Instructions I Prof. Taeweon Suh Computer Science Education Korea University.
NEGATIVE BINARY NUMBER – Digital Circuit 1 Choopan Rattanapoka.
Embedded System Design Center Sai Kumar Devulapalli ARM7TDMI Microprocessor Thumb Instruction Set.
Basic Operational Concepts of a Computer
The 8051 Microcontroller and Embedded Systems
FUNCTION – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Lecture 2: Basic Instructions CS 2011 Fall 2014, Dr. Rozier.
Lecture 4. ARM Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University ECM586 Special Topics in Embedded Systems.
Stack Stack Pointer A stack is a means of storing data that works on a ‘Last in first out’ (LIFO) basis. It reverses the order that data arrives and is.
CSC 3210 Computer Organization and Programming Chapter 8 MACHINE INSTRUCTIONS D.M. Rasanjalee Himali.
Making Decision – Microprocessor
Lecture 2: Basic Instructions EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering Spring 2014, Dr.
BITWISE OPERATIONS – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
COMPUTER ORGANISATION Sri.S.A.Hariprasad Sr.Lecturer R.V.C.E Bangalore.
1 Chapter 4 ARM Assembly Language Smruti Ranjan Sarangi Computer Organisation and Architecture PowerPoint Slides PROPRIETARY MATERIAL. © 2014 The McGraw-Hill.
ARM Assembly Language Programming and Architecture by Mazidi et al
Lecture 2: Advanced Instructions, Control, and Branching EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C Chapter 8 – Machine Instructions These are lecture notes to accompany the book.
Computer Architecture Lecture 15 Fasih ur Rehman.
CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS.
CS61C L20 Datapath © UC Regents 1 Microprocessor James Tan Adapted from D. Patterson’s CS61C Copyright 2000.
Introduction to Microprocessors Chapter 3. Programming Model (8086)  Shows the various internal registers that are accessible to the programmer.
ECE 447: Lecture 11 Introduction to Programming in Assembly Language.
MICROPROCESSOR DETAILS 1 Updated April 2011 ©Paul R. Godin prgodin gmail.com.
Microprocessor Programming & Interfacing Tutorial 1 Module 1 &2.
MicroProcessors Lec. 4 Dr. Tamer Samy Gaafar. Course Web Page —
8085 INTERNAL ARCHITECTURE.  Upon completing this topic, you should be able to: State all the register available in the 8085 microprocessor and explain.
1 TM 1 Embedded Systems Lab./Honam University r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 (sp) r14 (lr) r15 (pc) cpsr r13 (sp) r14 (lr) spsr r13 (sp)
Instruction Set Architectures Early trend was to add more and more instructions to new CPUs to do elaborate operations –VAX architecture had an instruction.
Intel Xscale® Assembly Language and C. The Intel Xscale® Programmer’s Model (1) (We will not be using the Thumb instruction set.) Memory Formats –We will.
Lecture 6: Decision and Control CS 2011 Spring 2016, Dr. Rozier.
Intel Xscale® Assembly Language and C. The Intel Xscale® Programmer’s Model (1) (We will not be using the Thumb instruction set.) Memory Formats –We will.
Chapter 4: Introduction to Assembly Language Programming
CPU Organisation & Operation
Gunjeet Kaur Dronacharya Group of institutions
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
The University of Adelaide, School of Computer Science
MISP Assembly.
Chapter 8 Central Processing Unit
Architecture Overview
MIPS Assembly.
March 2006 Saeid Nooshabadi
Branching instructions
Overheads for Computers as Components 2nd ed.
MIPS Assembly.
THUMB INSTRUCTION SET.
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
MIPS Arithmetic and Logic Instructions
Introduction to Assembly Chapter 2
Part I Data Representation and 8086 Microprocessors
Arithmetic and Logic Chapter 3
Presentation transcript:

CONDITION CODE AND ARITHMETIC OPERATIONS – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat

Objectives  To understand  Overflow and Underflow  CPSR condition flags  Arithmetic Operation Instructions

Review : Binary Addition/Subtraction  Binary number  ?  ?  In 4-bit microprocessor (2’s complement)  ?  ?

Overflow and Underflow  Overflow occurs when an arithmetic operation yields a result that is greater than the range’s positive limit of 2 N-1 – 1  Underflow occurs when an arithmetic operation yields a result that is less than the range’s negative limit of -2 N-1

Example : overflow  (4-bits 2’s complement)  Note that 4 bits can store +7 to  ≠ -5 OVERFLOW

Example : underflow  (4-bits 2’s complement)  Note that 4 bits can store +7 to  ≠ 4 UNDERFLOW

Status Flags in Program Status Register CPSR  N = Negative result from ALU flag  Z = Zero result from ALU flag  C = ALU opertion Carried out  V = ALU operation oVerflowed FlagsArithmetic Instruction Negative (N = ‘1’)Bit 31 of the result has been set indicates a negative number in signed operation Zero (Z = ‘1’)Result of operation was zero Carry (C = ‘1’)Result was greater than 32 bits Overflow (V = ‘1’)Result was greater than 32 bits indicates a possible corruption of the sign bit in signed number

Experimentation with Condition Flags (1)  Assume 4 bit-number Negative (N) = ? Zero (Z) = ? Carry (C) = ? Overflow (V) = ? Overflow (V) = MSB carry in XOR MSB carry out

Experimentation with Condition Flags (2)  Assume 4 bit-number Negative (N) = ? Zero (Z) = ? Carry (C) = ? Overflow (V) = ? Why V is 0 ?

Experimentation with Condition Flags (3)  Assume 4 bit-number Negative (N) = ? Zero (Z) = ? Carry (C) = ? Overflow (V) = ?

Experimentation with Condition Flags (4)  Assume 4 bit-number Negative (N) = ? Zero (Z) = ? Carry (C) = ? Overflow (V) = ?

Exercise : Condition Flags  Assume 4 bit-number, What are the values store in condition flags (N, Z, C, V) of the following operations.    1110 – 0111  0110 – 0010

More on ARM Assembly Instructions  Largest category of ARM instructions, all sharing the same instruction format  Load/Store architecture  These instructions only work on registers, NOT memory  They each perform a specific operation on operands  4 fields format : 1, 2, 3, 4 1. Operation by name 2. Operand getting result (“destination”) 3. 1 st operand for operation (“source 1”) 4. 2 nd operand for operation : register or shifted register or immediate (numerical constant)

Review : Instructions we’ve learnt  4 fields format : 1, 2, 3, 4 1. Operation by name 2. Operand getting result (“destination”) 3. 1 st operand for operation (“source 1”) 4. 2 nd operand for operation : register or shifted register or immediate (numerical constant) 1234 ADDR0,R1,R2 ADDR0,R1,#100 ADDR0,R1,#0x20

Review: Registers  ARM processor has register R0 – R15  By convention, each register also has a name to make it easier to code Register NumberRegister Name R0a1 R1a2 R2a3 R3a4 R4v1 R5v2 R6v3 R7v4 R8v5 R9v6 R10v7 R11v8 Register NumberRegister Name R12IP R13SP R14LR R15PC IP : Intra Procedure-call scratch register SP : Stack Pointer LR : Link Register PC : Program Counter ADD R0, R1, R2 = ADD a1, a2, a3 MOV R0, R15 = MOV a1, PC

Arithmetic Operations  ADD reg1, reg2, reg3 ;reg1  reg2 + reg3  ADC reg1, reg2, reg3 ;reg1  reg2 + reg3 + C  SUB reg1, reg2, reg3 ;reg1  reg2 - reg3  SBC reg1, reg2, reg3 ;reg1  reg2 - reg3 + C – 1  RSB reg1, reg2, reg3 ;reg1  reg3 - reg2  RSC reg1, reg2, reg3 ;reg1  reg3 - reg2 + C – 1 ** C = Carry bit in the CPSR **

Example 1 AREA ex1, CODE, READONLY ENTRY start MOV a1, #0x5 MOV a2, #0x1A RSB a3, a1, a2 END  After the execution of the program is terminated,  What are the value store in r0, r1, and r2  What are the value in N, Z, C, V bit of CSPR

Example 2 AREA ex2, CODE, READONLY ENTRY start MOV a1, #0x0 MOV a2, #0x0 ADC a3, a1, a2 END  After the execution of the program is terminated,  What are the value store in r0, r1, and r2  What are the value in N, Z, C, V bit of CSPR

Updating Condition Flags in CPSR  Normally, data processing instructions such as ADD, ADC, SUB, etc. do not change the value of condition flags in CPSR  We can add S at the end of instructions to indicate that the condition code (flag) should be updated Instruction (not update CC)Instruction (update CC) ADDADDS ADCADCS SUBSUBS SBCSBCS RSBRSBS RSCRSCS

Example 3 AREA ex3, CODE, READONLY ENTRY start MOV a1, #0x0 MOV a2, #0x0 ADCS a3, a1, a2 END  After the execution of the program is terminated,  What are the value store in r0, r1, and r2  What are the value in N, Z, C, V bit of CSPR

Example 4 AREA ex4, CODE, READONLY ENTRY start MOV a1, #0xFFFFFFFB MOV a2, #0x5 ADDS a3, a1, a2 END  After the execution of the program is terminated,  What are the value store in r0, r1, and r2  What are the value in N, Z, C, V bit of CSPR

Example 5 AREA ex4, CODE, READONLY ENTRY start MOV a1, #0xFFFFFFFB MOV a2, #0x5 ADDS a3, a1, a2 ADD a3, a1, a2 END  After the execution of the program is terminated,  What are the value store in r0, r1, and r2  What are the value in N, Z, C, V bit of CSPR

Assignment 4 AREA assignment4, CODE, READONLY ENTRY start MOV a1, #0xFFFFFF00 MOV a2, #0xFFFFFF58 ADDS a3, a1, a2 MOV a2, #0x1B RSCS a3, a2, a3 END 1. Assume 8 bit-number, What are the values store in condition flags (N, Z, C, V) of the following operations  0xCA + 0x17  0xF0 + 0xF8  0x6F - 0x75  0xC5 - 0xD6 2. After the execution of the program is terminated in ARM processor,  What are the value store in r0, r1, and r2  What are the value in N, Z, C, V bit of CSPR