Xuan Guo. Lecture XIV: Review of Chapter 3 & 4. CSC 3210 Computer Organization and Programming Georgia State University. March 5, 2015.

Similar documents
Chapter 4 Simple Calculations

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

Lecture VIII: Branching and Control Statements. Xuan Guo. CSC 3210 Computer Organization and Programming Georgia State University.

Compiler Design. Homework 1. Due Date: Thursday, January 19, 2006, 2:00

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: The MIPS ISA (P&H ) Consulting hours. Milestone #1 (due 1/26)

Number System. Introduction. Decimal Numbers

Lecture VII: The debugger gdb and Branching. Xuan Guo. CSC 3210 Computer Organization and Programming Georgia State University.

Unsigned Binary Integers

Unsigned Binary Integers

2.2: Bitwise Logical Operations

Basic Arithmetic (adding and subtracting)

Chapter 2 SPARC Architecture Chinua Umoja

CS & IT Conversions. Magnitude 10,000 1,

10-1 C D Pearson Education, Inc. M. Morris Mano & Charles R. Kime LOGIC AND COMPUTER DESIGN FUNDAMENTALS, 4e

Advanced Computer Architecture-CS501

Octal and Hexadecimal Integers

CMPE223/CMSE222 Digital Logic Design. Positional representation

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

Arithmetic and Logical Operations

Chapter 3: part 3 Binary Subtraction

The Assembly Language of the Boz 5

Number representations

H8/300L Series Programming Manual

Course Topics - Outline

RISC-V Assembly and Binary Notation

EE 3170 Microcontroller Applications

Chapter 4 Arithmetic Functions

TABLE 9-1. Symbolic Convention for Addressing Modes. Register indirect LDA (R1) ACC M[ R1] Refers to Figure 9-4. Addressing mode. Symbolic convention

CSC201, SECTION 002, Fall 2000: Homework Assignment #2

Tailoring the 32-Bit ALU to MIPS

Chapter 2 Bits, Data Types, and Operations

ECE 30 Introduction to Computer Engineering

GR712RC Incorrect Annulation of Floating-point Operation on Instruction Cache Parity Error. Technical note Doc. No GRLIB-TN-0012 Issue 1.

Sheet For the following C code: a = b + c; b = a + c; d = a b; Write an equivalent assembly MIPS program. Solution:

ECE232: Hardware Organization and Design

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

Lecture 6: Signed Numbers & Arithmetic Circuits. BCD (Binary Coded Decimal) Points Addressed in this Lecture

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2

6. Binary and Hexadecimal

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

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

ENE 334 Microprocessors

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

ARM Assembly Language. Programming

Basic Processor Design

Chapter 2 Bits, Data Types, and Operations

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

Lecture 2: Number Systems

COMP 303 Computer Architecture Lecture 6

ECE260: Fundamentals of Computer Engineering

CSE 30 Winter 2009 Final Exam

Arithmetic Processing

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

Computer Sc. & IT. Digital Logic. Computer Sciencee & Information Technology. 20 Rank under AIR 100. Postal Correspondence

EE 3170 Microcontroller Applications

ECEN 468 Advanced Logic Design

CSE 30 Fall 2006 Final Exam

ECE260: Fundamentals of Computer Engineering

Integer Multiplication and Division

MACHINE LEVEL REPRESENTATION OF DATA

Reconfigurable Computing Systems ( L) Fall 2012 Tiny Register Machine (TRM)

Exam 1 Fun Times. EE319K Fall 2012 Exam 1A Modified Page 1. Date: October 5, Printed Name:

TSK3000A - Generic Instructions

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2 Fall 2018

RCX internals (Revised February 24)

Number Systems and Computer Arithmetic

MACHINE LANGUAGE AND ASSEMBLY LANGUAGE

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

Arithmetic for Computers

Number Systems. Readings: , Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

CprE 288 Introduction to Embedded Systems ARM Assembly Programming: Translating C Control Statements and Function Calls

Chapter 1 Preliminaries

Beginning C Programming for Engineers

CSE 30 Spring 2007 Final Exam

EE292: Fundamentals of ECE

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

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

CS101 Lecture 04: Binary Arithmetic

Chapter 2 Bits, Data Types, and Operations

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

CS 101: Computer Programming and Utilization

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

Harry H. Porter, 2006

CHW 261: Logic Design

srl - shift right logical - 0 enters from left, bit drops off right end note: little-endian bit notation msb lsb "b" for bit

Chapter 1 Review of Number Systems

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

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

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.

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

EE260: Logic Design, Spring n Integer multiplication. n Booth s algorithm. n Integer division. n Restoring, non-restoring

MIPS Integer ALU Requirements

Condition Code Register. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Number Systems CHAPTER Positional Number Systems

Number Systems and Their Representations

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

Transcription:

CSC 3210 Computer Organization and Programming Georgia State University March 5, 2015

This lecture Plan for the lecture: Binary Hardware Device Converting from Decimal to other number system Converting from any number system to Decimal Bitwise logical operation Synthetic Instructions Flags Half and Full Adders & Modulus Arithmetic Addition Two s Complement Number Subtraction Shift Unsigned Arithmetic Four condition codes Signed and Unsigned Number Branching Conditions Extended Precision Arithmetic

Binary A computer is a bistable device A bistable device: Easy to design and build Has 2 states: 0 and 1 One Binary digit (bit) represents 2 possible states (0, 1)

A subscript indicates the number s base E.g. is 100 decimal or binary? We don t know! But 14 10 = 1110 2 is clear It is difficult for a human to work with long strings of 0 s and 1 s Octal: base 8 Hexadecimal: base 16

Binary to Hexadecimal 0101011010110011 2 =? in hex Group into 4 bits, from the right: 0101, 0110, 1011, 0011 2 Now translate each (see previous table): 0101 2 => 5, 0110 2 => 6, 1011 2 => b, 0011 2 => 3 So this is 56b3 16 What if there are not enough bits? Pad with 0 s on the left

Hexadecimal to Binary f0e5 16 =? in binary Translate each into a group of 4 bits: f 16 => 1111 2, 0 16 => 0000 2, e 16 => 1110 2, 5 16 => 0101 2 So this is 1111000011100101 2

Decimal to Any Number Base Take the decimal number, and divide by the new number base Keep track of the quotient and remainder Repeat until quotient = 0 Read number from the bottom to the top

Decimal to Binary Binary is base 2 Example: convert 35 (decimal) to binary Quotient Remainder 35 / 2 = 17 1 17 / 2 = 8 1 8 / 2 = 4 0 4 / 2 = 2 0 2 / 2 = 1 0 1 / 2 = 0 1 So 35 10 = 100011 2

Any Number Base to Decimal From right to left, multiply the digit of the number-to-convert by its base position Sum all results

Binary to Decimal Binary is base 2 Example: convert 10110 (binary) to decimal 10110 2 = 1x2 4 + 0x2 3 + 1x2 2 + 1x2 1 + 0x2 0 = 1x16 + 0x8 + 1x4 + 1x2 + 0x1 = 16 + 0 + 4 + 2 + 0 = 22 So 10110 2 = 22 10

In C program and Assembly language Hexadecimal designated by a leading 0x Octal designated by a leading 0 Example mov 0xa, %l0 mov 012, %l1 mov 10, %l2

Bitwise Logical Operations There are several binary operations: NOT AND OR XOR NAND NOR

SPARC Instruction Format These commands are in the form: command reg rs1, reg_or_imm, reg rd command can be any of the following: and, andn, xor, or, xnor, orn andcc, andncc, xorcc, orcc, xnorcc, orncc the cc means set condition codes andn means a and (not b) orn means a or (not b) not reg rs1, reg rd not reg rd recognized as xnor reg rs1, %g0, reg rd xnor reg rd, %g0, reg rd

A Few More Logic Examples (Bonus) In all the examples below, these registers have the following initial values: %l0 = 0x12345678 %l1 = 0x9abcdef0 What are the values for %l1 after the instruction? and %l0, %l1, %l1 xor %l0, %l1, %l1 12345670 88888888 or %l0, %l1, %l1 9abcdef8 not %l0, %l1 edcba987

A Few More Logic Examples (Bonus) %l0 = 0x12345678 (0001,0010,0011,0100,0101,0110,0111,1000) 2 %l1 = 0x9abcdef0 (1001,1010,1011,1100,1101,1110,1111,0000) 2 What are the values for %l1 after the instruction? and %l0, %l1, %l1 xor %l0, %l1, %l1 0x12345670 = (0001,0010,0011,0100,0101,0110,0111,0000) 2 88888888 = (1000,1000,1000,1000,1000,1000,1000,1000) 2 or %l0, %l1, %l1 0x9abcdef8 = (1001,1010,1011,1100,1101,1110,1111,1000) 2 not %l0, %l1 0xedcba987 = (1110,1101,1100,1011,1010,1001,1000,0111) 2

Synthetic Instructions The cmp command is a synthetic one. It is a macro that uses %g0. cmp reg rs1, reg_or_imm command will be expanded to: subcc reg rs1, reg_or_imm, %g0 the tst command compares a register to 0: tst reg rs1 which the assembler turns into: orcc reg rs1, %g0, %g0 Since %g0 ignores any updates, only the condition codes are affected.

Flags & Testing Flags A word may contain 32 flags. Common flag operations and mnemonics set: bset ( done with or ) clear: bclr ( done with andn ) toggle: btog ( done with xor ) bset/bclr/btog reg_or_imm, reg rd This command will see if one or more flags is set btst reg_or_imm, reg rs1 it expands to: andcc reg rs1, reg_or_imm, %g0 example: test if flag 0x02 is set btst 0x02, %a_r be clear nop set: clear:

Binary Sums and Carries a b Sum a b Carry 0 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 0 1 1 0 1 1 1 XOR AND

Half Adder / Full Adder A half adder For adding 2 bits Gives carry out and sum 1 AND and 1 XOR gate A full adder For adding 2 bits plus a carry in Gives carry out and sum 2 ANDs, 2 XORs, and 1 OR

Modulus Arithmetic It considers only numbers in the range 0 <= n <=M, where M is the modulus. SPARC has 32-bit registers, M = 2 32 Each register can store an integer number between 0 and 2 n -1 where n=32 for SPARC if you have a value of 2 n -1 in a register, and you add 1 to this, the register will then hold a value of 0

Complement Arithmetic r n -1-b+1 is called the radix complement ten s complement if r=10 two s complement if r=2 r n -1-b is called the diminished radix complement nine s complement if r=10 one s complement if r=2 Any number where the most significant digit >= (r/2) is considered negative 10000000 means 128 when r=2, n=8 84 means 16 when r=10, n=2

Two s Complement In binary, finding the one s complement and the two s complement are easy One s complement: Replace every 0 with a 1, and replace every 1 with a 0 Two s complement: Find the one s complement, and add 1

Two s Complement Example What is 16 (decimal) in binary (r=2)? We ll assume n=8 16 = 0001 0000 in binary 1110 1111 one s complement + 0000 0001 add 1 1111 0000 two s complement

Addition and Subtraction The two s complement system is an interpretation of numbers in registers; the hardware always performs binary addition. To subtract, find the 2 s complement of the 2 nd operand, and add There is no need for a hardware subtractor

Shift Instructions A registers contents can be shifted left shift is like multiplying by 2 right shift is like dividing by 2 Shift right logical (srl) 0 Shift right arithmetic (sra) Shift left logical (sll) 0 Shift left arithmetic is not provided, it would be the same as shift left logical

Shift Instructions Shift right logical (srl) srl reg rs1, reg_or_imm, reg rd Shift right arithmetic (sra) sra reg rs1, reg_or_imm, reg rd Shift left logical (sll) sll reg rs1, reg_or_imm, reg rd The number of shifts is the low 5 bits of the reg_or_imm, so largest shift is 31

Branching Conditions Branching is based on the following flags: N (negative) the most significant bit of the result not used with unsigned numbers V (overflow) when result is too big for the register Z (zero) set when all bits of the result are 0 C (carry) set when an addition has carry out, or when subtraction does not have carry out

Signed Branches Assembler Signed Arithmetic Mnemonic Branches Condition Codes bl branch on less (N xor V) = 1 ble branch on less or equal Z or (N xor V) = 1 be branch on equal Z = 1 bne branch on not equal Z = 0 bge branch on greater or equal (N xor V) = 0 bg branch on greater Z or (N xor V) = 0

Unsigned Branches The carry flag (C) can be used instead of the overflow flag (V) Assembler Unsigned Arithmetic Mnemonic Branches Condition Codes blu branch on less C = 1 bleu branch on less or equal Z or C = 1 be branch on equal Z = 1 (same as signed branch) bne branch on not equal Z = 0 (same as signed branch) bgeu branch on greater or equal C = 0 bgu branch on greater Z = 0 and C = 0

Condition Code Branches Assembler Condition Code Mnemonic Branches Condition Codes bneg branch on negative N = 1 bpos branch on positive N = 0 bz branch on zero set Z = 1 (same as be) bnz branch on zero not set Z = 0 (same as bne) bvs branch on overflow set V = 0 bvc branch on overflow clear V = 1 bcs branch on carry set C = 1 (same as blu) bcc branch on carry clear C = 0 (same as bgeu)

Numeric Labels The assembler allows single-digit labels to appear many times in a single source file. [page 137] 1: addcc %lo_r, %lo_r, %lo_r bcc 1f! find label 1 forward add %hi_r, %hi_r, %hi_r bset 1, %hi_r The letter b or f must be appended to the digit, for backward or forward direction. The closest label in that direction will be the branch target, if the branch is taken. These are good for labels used in control structures.

Extended Precision What if we need to work with data that are more than 32 bits wide? We can use extended precision instructions, with the carry addx reg rs1, reg_or_imm, reg rd addxcc reg rs1, reg_or_imm, reg rd these mean: reg rd = reg rs1 + reg_or_imm + C

Extended Precision (Sub) We can use extended precision instructions, with the carry subx reg rs1, reg_or_imm, reg rd subxcc reg rs1, reg_or_imm, reg rd these mean: reg rd = reg rs1 - reg_or_imm - C Data larger than 32 bits must be stored in 2 (or more) registers. That is, add (or sub) the low part first, then use the extended precision addx (or subx) for the high part. This is just like doing arithmetic on paper, where we work with one digit at a time.

Extended Precision example Given a number A spans over registers %l1 to %l2 and a number B spans over registers %o1 to %o2. Write an assembly code segment to perform A = A - B [A = %l1%l2, B = %o1%o2] ABCDEFABCDEFABCD - BCDEFBCDEFBCDEFB = EEEEF3DDDE32CCD2 subcc %l2, %o2, %l2! sub bits 0 to 31 subx %l1, %o1, %l1! sub bits 32 to 63 and C