Natawut NupairojAssembly Language1 Arithmetic Operations.

Slides:



Advertisements
Similar presentations
Cosc 2150: Computer Organization
Advertisements

1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Goal: Write Programs in Assembly
Lecture 5: MIPS Instruction Set
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
Lecture - 2 Number systems and computer data formats
Computer Organization & Assembly Language
Computer Structure - Computer Arithmetic Goal: Representing Numbers in Binary  Base 10 (decimal) - Numbers are represented using 10 numerals: 0, 1, 2,
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
Logical & shift ops (1) Fall 2007 Lecture 05: Logical Operations.
Integer Multiplication and Division
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
CPSC355 Week 3 Hoang Dang. Week 3 Assignment 1 Do/while loop Assignment 2 Binary Bitwise operation.
Sparc Architecture Overview
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C Chapter 3 – Digital Logic and Binary Numbers These are lecture notes to accompany.
Simple Data Type Representation and conversion of numbers
Natawut NupairojAssembly Language1 Subroutines. Natawut NupairojAssembly Language2 Subroutines A subroutine is a piece of program codes that performs.
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
CSC 3210 Computer Organization and Programming Chapter 2 SPARC Architecture Dr. Anu Bourgeois 1.
CPU Internal memory I/O interface circuit System bus
CSC 3210 Computer Organization and Programming Chapter 8 MACHINE INSTRUCTIONS D.M. Rasanjalee Himali.
ICS312 Set 9 Logic & Shift Instructions. Logic & Shift Instructions Logic and Shift Instructions can be used to change the bit values in an operand. The.
CSC 3210 Computer Organization and Programming Chapter 2 SPARC Architecture Dr. Anu Bourgeois 1.
Making Decision – Microprocessor
Natawut NupairojAssembly Language1 Memory and Stack.
Chapter 19 Number Systems. Irvine, Kip R. Assembly Language for Intel-Based Computers, Translating Languages English: Display the sum of A times.
Integer Multiplication and Division
Natawut NupairojAssembly Language1 Control Structure.
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C Chapter 4 –Binary Arithmetic These are lecture notes to accompany the book SPARC.
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C Chapter 8 – Machine Instructions These are lecture notes to accompany the book.
EET 4250 Instruction Representation & Formats Acknowledgements: Some slides and lecture notes for this course adapted from Prof. Mary Jane Penn.
Natawut NupairojAssembly Language1 Pipelining Processor.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 9 Binary Representation and Logical Operations.
CSC 3210 Computer Organization and Programming
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Chapter 2 SPARC Architecture Chinua Umoja 1.  SPARC is a load/store architecture  Registers used for all arithmetic and logical operations  32 registers.
SPARC Programming Model 24 “window” registers 8 global registers Control registers –Multiply step –PSR (status flags, etc.) –Trap Base register –Window.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
Chapter 8 – Machine Instructions
Deeper Assembly: Addressing, Conditions, Branching, and Loops
Integer Multiplication and Division
Data Representation Binary Numbers Binary Addition
Lecture 4: MIPS Instruction Set
Chapter 3 – Digital Logic and Binary Numbers
Number Systems.
Lecture 4: MIPS Instruction Set
LING 408/508: Programming for Linguists
ARM Control Structures
MISP Assembly.
How to represent signed integers
CS 235 Computer Organization & Assembly Language
CSC 3210 Computer Organization and Programming
Computer Architecture & Operations I
Shift & Rotate Instructions)
Logical Operations Boy who sow wild oats better hope for crop failure.
Computer Architecture
Flow of Control -- Conditional branch instructions
ARM Control Structures
MIPS Assembly.
MIPS assembly.
Generalities for Assembly Language
MIPS Arithmetic and Logic Instructions
Bit Manipulations CS212.
Logical Operations Boy who sow wild oats better hope for crop failure.
Presentation transcript:

Natawut NupairojAssembly Language1 Arithmetic Operations

Natawut NupairojAssembly Language2 Arithmetic Operations Signed/unsigned integer –64-bit –96-bit (extended precision) Floating-point –32-bit (single precision) –64-bit (double precision) –128-bit (quadraple precision) 64-bit logical operations

Natawut NupairojAssembly Language3 Integer Operations Signed Integer –[-2 (n-1), 2 (n-1) -1] Unsigned Integer –[0, 2 n -1] Indentical Operations: add, sub,... Difference in how to interpret condition codes and branches add, addcc*, sub, subcc* Format: add rs, reg_or_imm, rd

Natawut NupairojAssembly Language4 Condition Codes V - set when the register is not long enough to hold the result. N - set when the most significant bit is 1. C - set when the operation generates a carry. Z - set when all bits of the result are zero.

Natawut NupairojAssembly Language5 Constants Representations Integer mov 97, %r1! Decimal number mov 0141, %r1! Octal number mov 0x61, %r1! Hexadecimal number Character mov 'a', %r1 mov "a", %r1 ASCII table

Natawut NupairojAssembly Language6 Integer Example do { x--;/* x = x - 1; */ } while(x != 0) Approach#1 loop: sub %l0, 1, %l0 cmp %l0, 0 bne loop nop Approach#2 loop: subcc %l0, 1, %l0 bnz loop nop

Natawut NupairojAssembly Language7 Logical Operations and, andn, xor, or, xnor, orn andce, andncc, xorcc, orcc, xnorcc, orncc not a andn b= a and (not b) a xnor b= a xor (not b) a orn b= a or (not b)

Natawut NupairojAssembly Language8 Logical Example SPARC Logical a Instr. Operations b anda and b andna and (not b) or a or b orna or (not b) xora xor b xnora xor (not b)

Natawut NupairojAssembly Language9 Shift Operations There are 3 shift instructions:

Natawut NupairojAssembly Language10 Shift Examples mov 1, %l1! %l1 = sll %l1, 4, %l2! %l2 = srl %l2, %l1, %l3! %l3 = sll %l1, 31, %l2! %l2 = sra %l2, 3, %l3! %l3 = srl %l2, 3, %l3! %l3 =

Natawut NupairojAssembly Language11 Our Third Program Convert pack decimal number in “x” (8 digits, no sign) to be stored in “y” in binary format. Example: –convert pack-decimal “ ” to binary. Pack-decimal: – Binary: – –two approaches from left to right or from right to left. –We will do from right to left.

Natawut NupairojAssembly Language12 Our Third Program First, extract the rightmost digit. Then, multiply it with 10^(digit-1) and add it to the result. Shift x to right 4 times to get the next digit. Repeat until all digits are done. For example: to convert “ ”. 8*10^(1-1) + 7*10^(2-1) + … + 1*10^(8-1) = We will need a variable to keep track the value to multiply to each digit.

Natawut NupairojAssembly Language13 Our Third Program int main() { int x, y, num, i, mulval; x = 0x ;// number to be converted. y = 0;// result. mulval = 1;// 10^(digit-1). for(i=0 ; i < 8 ; i++) { num = x & 0xF;// extract the rightmost digit. y = y + num*mulval;// add to the result. x = x >> 4;// next digit. mulval = mulval * 10; }

Natawut NupairojAssembly Language14 Our Third Program define(x_r, l0) define(y_r, l1) define(i_r, l2) define(mulval_r, l3) define(num_r, l4).global main main:save %sp, -64, %sp set 0x , %x_r !load 32-bit constant to x clr %y_r! y = 0; mov 1, %mulval_r! mulval = 1;

Natawut NupairojAssembly Language15 Our Third Program ! Convert for to while loop clr %i_r! i = 0; loop:cmp %i_r, 8! if i >= 8 bge done! then exit the loop nop! delay slot and %x_r, 0xF, %num_r! num = x & 0xF; mov %num_r, %o0 mov %mulval_r, %o1 call.mul! num * mulval nop! delay slot add %y_r, %o0, %y_r! y = y + num*mulval; srl %x_r, 4, %x_r! x = x >> 4;

Natawut NupairojAssembly Language16 Our Third Program mov %mulval_r, %o0 mov 10, %o1 call.mul ! mulval*10 nop ! delay slot mov %o0, %mulval_r ! mulval = mulval*10; add %i_r, 1, %i_r ! i++; ba loop ! repeat loop nop ! delay slot done:mov 1, %g1 ! end of program ta 0

Natawut NupairojAssembly Language17 Synthetic Instructions using %g0 "cmp" is actually a synthetic instruction. –This instruction is not existed !!! –But it got translated to something else !!! cmp %r1, 12 = subcc %r1, 12, %g0 For example: –to compare %r1 and 12, first sub %r1 with 12. –if result = 0, %r1 = 12. (Z = 1) –If result < 0, %r1 < 12. (N = 1) –If result > 0, %r1 > 12. (N = 0)

Natawut NupairojAssembly Language18 Comparison and Condition Codes Instruction be bne bl bg ble bge Condition Codes Z = 1 Z = 0 (N xor V) = 1 (N xor V) = 0 (Z or (N xor V)) = 1 (Z or (N xor V)) = 0

Natawut NupairojAssembly Language19 Other Synthetic Instructions mov 201, %o2 = or %g0, 201, %o2 mov %g5, %i6 = or %g0, %g5, %g6 clr %i7 = or %g0, %g0, %i7 tst %l6 = subcc %l6, %g0, %g0

Natawut NupairojAssembly Language20 Set 32-bit Constant to Register set 0x , %l2 For any instruction, the biggest (or smallest) constant value is 4095 (or -4096) which is a 22- bit constant. (Why?) For 32-bit constant, we use the “set” instruction which is a synthetic instruction. It is converted to: sethi %hi(0x ), %l2 or %l2, %lo(0x ), %l2

Natawut NupairojAssembly Language21 Set 32-bit Constant to Register sethi %hi(0x ), %l2 Store the first 22-bit of the constant to %l2. or %l2, %lo(0x ), %l2 Store the last 10-bit of the constant to %l2. Done by assembler*