srl - shift right logical - 0 enters from left, bit drops off right end note: little-endian bit notation msb lsb "b" for bit
|
|
- Geoffrey Heath
- 6 years ago
- Views:
Transcription
1 Clemson University -- CPSC 231 Shifts (p. 123) srl - shift right logical - 0 enters from left, bit drops off right end 0 b 31 b 30 b 2 b 1 b 0 note: little-endian bit notation msb lsb "b" for bit a f gcc generates srl srl by 1 becomes for unsigned int variable a in 5 7 a b a = a >> 1; sra - shift right arithmetic - sign bit replicated on left, bit drops off right end b 31 b 30 b 2 b 1 b 0 sign lsb a f gcc generates sra sra by 1 becomes for int variable a in a = a >> 1; d 7 a b
2 sll - shift left logical - 0 enters from right, bit drops off left end b 31 b 30 b 2 b 1 b 0 0 msb lsb a f gcc generates sll sll by 1 becomes for a = a << 1; e a c the shift count is given as a 5-bit value (0-31) either as an immediate value or in a register; if you specify a larger value then the actual shift count is the number you specify modulo 32 a shift right has a choice of what to put in the most significant bit (i.e., the sign bit) from the left: either zeros or replicating the sign bit; that is why there are two shift right opcodes a shift left has no choice as to what will go into the sign bit - it has to be one of the bits already in the register, which is determined by the shift amount; zeros always come into the least significant bit on the right Multiplication by small constants (skip ahead to pp ) 1) convert the constant into a sum of powers of two (can allow a subtract) 2) convert the multiplications by powers of two into left shifts x 10 = x (8 + 2) = (x 8) + (x 2) = (x << 3) + (x << 1) x 20 = x (16 + 4) = (x 16) + (x 4) = (x<<4)+(x<<2) x 15 = x (16-1) = (x 16) - x = (x << 4) - x
3 Bitwise Operators Two main applications o to combine several values into a single variable o to accomplish certain arithmetic operations Bitwise Rotation A bitwise rotation (or circular shift) is a shift operator that shifts all bits of its operand. Unlike an arithmetic shift, a rotate does not preserve a number's sign bit or distinguish a number's exponent from its mantissa. Unlike a logical shift, the vacant bit positions are not filled in with zeros but are filled in with the bits that are shifted out of the sequence. Rotates rotate %o0 left by 1 bit addcc %o0, %o0, %o0 addx %o0, %g0, %o0 macro for rol(rs1,n,rd) A B rotate left by n n 32-n define(rol,` sll $1,$2,%o0 srl $1,eval(32-$2),%o1 or %o0,%o1,$3 ') B 32-n A n final result is equiv. to shifting A right by 32-n and shifting B left by n
4 macro for ror(rs1,n,rd define(ror,` srl $1,$2,%o0 sll $1,eval(32-$2),%o1 or %o0,%o1,$3 ') A B 32-n n B A n 32-n rotate right by n final result is equiv. to shifting A right by n and shifting B left by 32-n A B 0 A B 0 or B A
5 Field extraction with a bit mask - field already in rightmost bits bit mask - a word where bits are used to zero out or select portions of another word assume we are working with nibbles (4-bit fields) remove (clear) all other bits and work with only the low four bits (the mask will have 0s in all the bit positions we wish to clear and 1s in the bit positions we wish to select) xxxx xxxx xxxx xxxx xxxx xxxx xxxx zzzz %a_r and zzzz %b_r and %a_r,0xf,%b_r Field extraction with a bit mask - field not in rightmost bits if you want to work with the next nibble to the left, remove (clear) all other bits and work with only next to last four bits yyyy yyyy yyyy yyyy yyyy yyyy zzzz yyyy %a_r and and %a_r,0xf0,%b_r zzzz 0000 %b_r it is usually easier to work with the field when it is shifted to the right zzzz 0000 %b_r zzzz %c_r srl %b_r,4,%c_r even better, you can shift and then mask yyyy yyyy yyyy yyyy yyyy yyyy zzzz yyyy %a_r srl %a_r,4,%b_r 0000 yyyy yyyy yyyy yyyy yyyy yyyy zzzz %b_r and zzzz %c_r and %b_r,0xf,%c_r
6 Field extraction without a mask a left shift and then a right shift can isolate the desired field yyyy yyyy yyyy yyyy yyyy yyyy zzzz yyyy %a_r sll %a_r,24,%b_r zzzz yyyy %b_r srl %b_r,28,%b_r zzzz %b_r use a logical right shift for an unsigned value or an arithmetic right shift for a signed value, which provides sign extension %a_r sll %a_r,24,%b_r %b_r sra %b_r,28,%b_r %b_r Field insertion with a bit mask first, if necessary, clear out the field into which you wish to insert (the mask will have 0s in the bit positions we wish to clear and 1s in all other bit positions) xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx %a_r set 0xffffff0f,%mask_r %mask_r and %a_r,%mask_r,%b_r xxxx xxxx xxxx xxxx xxxx xxxx 0000 xxxx %b_r alternatively, you can use the instruction andn or the instruction bclr with a selection mask of 0xf0, that is, with a mask that uses 1s to define the field that we will insert xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx %a_r andn %a_r,0xf0,%b_r xxxx xxxx xxxx xxxx xxxx xxxx 0000 xxxx %b_r
7 if necessary, shift the new value to the correct field position before inserting zzzz %c_r sll %c_r,4,%d_r zzzz 0000 %d_r then insert the new value into the field zzzz 0000 %d_r xxxx xxxx xxxx xxxx xxxx xxxx 0000 xxxx %b_r or %d_r,%b_r,%e_r xxxx xxxx xxxx xxxx xxxx xxxx zzzz xxxx %e_r Example A perfect example for when you'd want to combine multiple values into a single variable is if you're doing graphics work with 32-bit color. In a 32-bit color dword, there are four distinct values. The low byte (bits 0 through 7) is the value for blue. The next most significant byte is a value for green, then a byte for blue, and finally, the high byte is an alpha (transparency) value. So the color dword looks like this in memory: AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB Now, suppose you have a 32-bit integer called dwcolor, and you want to extract the value for green. How should we do it? What we need is a way to eliminate the other three bytes, and leave the red byte untouched. We will define a value called a mask, which has 0s where you want to erase information, and 1s where you want to save information. Since we want to extract the red byte, our mask would look like this:
8 We need to convert this to hex since we can't write binary numbers directly into C code The hex equivalent is 0x00FF0000. If we use the bitwise AND on dwcolor and our mask, we get the following result: dwcolor: AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB mask: & result: RRRR RRRR There is just one problem with this. To use the red byte by itself like we want, it would have to be the low byte. But it's not it is 16 bits up in the dword. All we need now is a shift right by 16 places, and we're all set: Previous: RRRR RRRR Shift: >> Result: RRRR RRRR == RRRR RRRR We have done exactly what we wanted to do: we extracted the red byte from the full color dword. The previous example can be applied to virtually anything that uses bit fields to store a number of values in a single variable. All you have to do is make sure your masks are set correctly, and you shift by the correct number of places. The mask should contain a 1 wherever you want to keep information, and a 0 wherever you want to clear it. Example 2: Suppose we have a 16-bit color word. Color word: RRRR RGGG GGGB BBBB Red mask: == 0xF800 Green mask: == 0x07E0 Blue mask: == 0x001F Note that instead of clearing all the fields but one so we can use that by itself, we can also use AND to leave all the fields except one as they are, clearing only that one.
9 Example: alter a 32-bit color dword by clearing its green byte. But, then what happens if you want to set that value to something else without altering the rest of the color word? Use the bitwise AND operator and a number of shifts, but it wouldn't be the most efficient way. To easily splice new values into a larger variable, we need to employ the bitwise OR. Example: Inserting and Combining Values Now our situation is the reverse to what we did for extracting a byte. Instead of extracting a byte from a color dword, we want to reset one. Maybe we have a color dword that represents the color (214, 53, 240), and we want to change it to (214, 166, 240). The first step is to clear the green byte to 0 To see how to rewrite that byte, consider the truth table for the bitwise OR. Remember that any value ORed with 0 is that value. So we must create a new mask to use. It will have zeroes wherever the color dword is already defined, and it will have an actual color value wherever the color dword has a 0. Example: dwcolor: AAAA AAAA RRRR RRRR BBBB BBBB mask: GGGG GGGG result: AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB So in this case, the mask is the green byte, located at the appropriate position so that it merges correctly with the color dword. As before, we can use a bitwise shift to shift the green byte into the position we want it in. In the example above, the green byte is located eight bits above the low byte, so the shift operation you'd use would look like this: Previous: GGGG GGGG == GGGG GGGG Shift: << Result: GGGG GGGG
10 Example extract and insert macros for dealing with packed words! positional parameters for extract() and insert()!! $1 - packed register! $2 - shift amount! (can be immediate or register)! $3 - mask, positioned in least-significant bits! (can be immediate or register)! $4 - result register!! note that the insert macro also uses %o0 to hold shifted mask! define(extract,` ifelse($2,0,` and $1, $3, $4',` srl $1, $2, $4 and $4, $3, $4') ') define(insert,` and $4, $3, $4 ifelse($2,0,` andn $1, $3, $1',` mov $3, %o0 sll %o0, $2, %o0 andn $1, %o0, $1 sll $4, $2, $4') or $1, $4, $1 ')! example use extract(%packed_r,%shift_amt_r,%mask_r,%temp_r) inc %temp_r insert(%packed_r,%shift_amt_r,%mask_r,%temp_r)! or extract(%packed_r,12,0x3f,%temp_r) dec %temp_r insert(%packed_r,12,0x3f,%temp_r)
11 ! combining the two macros for updating a packed word! $5 - inc or dec define(update_field,` extract($1,$2,$3,$4) $5 $4 insert($1,$2,$3,$4) ')! example use update_field(%packed_r,%shift_amt_r,%mask_r,%temp_r,inc) written as cpp macros #define EXTRACT( pack, shift, mask, field ) \ (field) = ((pack) >> (shift)) & (mask) #define INSERT( pack, shift, mask, field ) \ (pack) = ((pack) & ~((mask) << (shift))) (((field) & (mask)) << (shift)) alternate definitions of EXTRACT using field width to generate mask (~0 form suggested by Mitch Alsup) #define EXTRACT2( pack, shift, width, field ) \ (field) = (((pack) >> (shift)) & ((1 << width) - 1)) #define EXTRACT3( pack, shift, width, field ) \ (field) = (((pack) >> (shift)) & (~((~0) << width))
12 example #include<stdio.h> #define INSERT2( pack, shift, width, field ) \ (pack) = ((pack) & ~(((1 << width) - 1) << (shift))) \ (((field) & ((1 << width) - 1)) << (shift)) #define EXTRACT2( pack, shift, width, field ) \ (field) = (((pack) >> (shift)) & ((1 << width) - 1)) int main() int a = 0x1234abcd; int b; printf("0x%x\n",a); EXTRACT2( a, 12, 8, b ); printf("0x%x\n",b); b = b - 0x4b; printf("0x%x\n",b); INSERT2( a, 12, 8, b ); printf("0x%x\n",a); return 0; which has output 0x1234abcd 0x4a 0xffffffff 0x123ffbcd
13 simpler macros for a prepositioned mask! alternate extract/insert definitions if mask is! pre-positioned at correct bit field (probably means! that mask is register rather than an immediate value)!! same parameters! define(extract_prepos_mask,` and $1, $3, $4 ifelse($4,0,,`srl $4, $2, $4') ') define(insert_prepos_mask,` andn $1, $3, $1 ifelse($4,0,,`sll $4, $2, $4') and $4, $3, $4 or $1, $4, $1 ') prepositioned-mask approach written as cpp macros #define EXTRACT_PPM( pack, shift, mask, field ) \ (field) = ((pack) & (mask)) >> (shift) #define INSERT_PPM( pack, shift, mask, field ) \ (pack) = ((pack) & ~(mask)) (((field) << (shift)) & (mask)) / atobcd() - convert ASCII digit string to packed BCD string input parameters: s - address of ASCII digit string assumptions about input string: - should contain one ASCII digit per byte ('0'-'9') - terminated by the null byte - does not contain a +/- sign
14 b - address of buffer area for packed BCD string assumptions about buffer area: - large enough to hold result; floor(strlen(s)/2) + 1 return value: address of buffer area effect/output: ASCII digits are converted into two BCD nibbles per byte in the result buffer in big-endian order. The resulting packed BCD string is terminated by 0xf in either the left half or the right half of the last byte of the string. typical calling sequence: bcd_string = atobcd( digit_string, buffer ); local variables: save - pointer variable to save the starting address of the buffer b to use as the return value left_half - logical flag indicating which nibble to store - true means that the next BCD value should be stored in left-hand nibble of the current byte in buffer - false means that the next BCD value should be stored in right-hand nibble /
15 #include<stdio.h> char atobcd( char s, char b ) char save = b; int left_half = 1; while( (s >= '0') && (s <= '9') ) if( left_half ) b = (s & 0xf) << 4; else b = b (s & 0xf); b++; left_half = 1 - left_half; s++; if( left_half ) b = 0xf0; else b = b 0xf; return save;
16 void prt_bytes( char p, char type ) if( type == 'b' ) while( ((p & 0xf0)!= 0xf0) && ((p & 0xf)!= 0xf) ) printf(" 0x%02x",(unsigned char)p++); printf(" 0x%02x\n",(unsigned char)p); else while( p ) printf(" 0x%02x",(unsigned char)p++); printf(" 0x%02x\n",(unsigned char)p); int main() char test[2][10] = " "," "; char result[2][10]; output atobcd(test[0],result[0]); prt_bytes(test[0],'s'); prt_bytes(result[0],'b'); atobcd(test[1],result[1]); prt_bytes(test[1],'s'); prt_bytes(result[1],'b'); return 0; 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x00 0x12 0x34 0x56 0x78 0xf0 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x00 0x12 0x34 0x56 0x78 0x9f
17 example conversion of ASCII decimal digits to a binary number scan of digits is left-to-right, that is, from most significant digit to least => use Horner's rule for calculating an n-term polynomial a n-1 x n-1 + a n-2 x n a 0 = [ a n-1 x + a n-2 ] x a 0 or as might appear in a program value = 0; for( i = 0; I < n; i++ ) value = x value; a = << next coefficient, that is, the (n-i-1)st coefficient >> value = value + a; that is, initially: value = 0; after iteration 0: value = a n-1 after iteration 1: value = a n-1 x + a n-2 after iteration 2: value = [ a n-1 x + a n-2 ] x + a n-3... For decimal, you multiply by 10 value = 0; for( i = 0; i < n; i++ ) // n iterations: 0,1,...,n-1 value = 10value; a = << next coefficient >> value = value + a; (or, better yet, use shifts and adds) becomes value = 10 value; value = (value << 3) + (value << 1);
Binary Logic (review)
Binary Logic (review) Basic logical operators: (Chapter 7 expanded) NOT AND outputs 1 only if both inputs are 1 OR outputs 1 if at lest one input is 1 XOR outputs 1 if exactly one input is 1 a not 0 1
More informationBut first, encode deck of cards. Integer Representation. Two possible representations. Two better representations WELLESLEY CS 240 9/8/15
Integer Representation Representation of integers: unsigned and signed Sign extension Arithmetic and shifting Casting But first, encode deck of cards. cards in suits How do we encode suits, face cards?
More informationCOMP2611: Computer Organization. Data Representation
COMP2611: Computer Organization Comp2611 Fall 2015 2 1. Binary numbers and 2 s Complement Numbers 3 Bits: are the basis for binary number representation in digital computers What you will learn here: How
More informationCS 261 Fall Binary Information (convert to hex) Mike Lam, Professor
CS 261 Fall 2018 Mike Lam, Professor 3735928559 (convert to hex) Binary Information Binary information Topics Base conversions (bin/dec/hex) Data sizes Byte ordering Character and program encodings Bitwise
More informationBeginning C Programming for Engineers
Beginning Programming for Engineers R. Lindsay Todd Lecture 6: Bit Operations R. Lindsay Todd () Beginning Programming for Engineers Beg 6 1 / 32 Outline Outline 1 Place Value Octal Hexadecimal Binary
More informationCSCI 2212: Intermediate Programming / C Chapter 15
... /34 CSCI 222: Intermediate Programming / C Chapter 5 Alice E. Fischer October 9 and 2, 25 ... 2/34 Outline Integer Representations Binary Integers Integer Types Bit Operations Applying Bit Operations
More informationNumber Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers
Outline of Introduction Administrivia What is computer architecture? What do computers do? Representing high level things in binary Data objects: integers, decimals, characters, etc. Memory locations (We
More informationBitwise Instructions
Bitwise Instructions CSE 30: Computer Organization and Systems Programming Dept. of Computer Science and Engineering University of California, San Diego Overview v Bitwise Instructions v Shifts and Rotates
More informationLecture 6 Decision + Shift + I/O
Lecture 6 Decision + Shift + I/O Instructions so far MIPS C Program add, sub, addi, multi, div lw $t0,12($s0) sw $t0, 12($s0) beq $s0, $s1, L1 bne $s0, $s1, L1 j L1 (unconditional branch) slt reg1,reg2,reg3
More informationComputer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers
Computer Science 324 Computer Architecture Mount Holyoke College Fall 2007 Topic Notes: Bits and Bytes and Numbers Number Systems Much of this is review, given the 221 prerequisite Question: how high can
More informationChapter 4. Operations on Data
Chapter 4 Operations on Data 1 OBJECTIVES After reading this chapter, the reader should be able to: List the three categories of operations performed on data. Perform unary and binary logic operations
More informationInf2C - Computer Systems Lecture 2 Data Representation
Inf2C - Computer Systems Lecture 2 Data Representation Boris Grot School of Informatics University of Edinburgh Last lecture Moore s law Types of computer systems Computer components Computer system stack
More information2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)
2.1 Unit 2 Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting) 2.2 Skills & Outcomes You should know and be able to apply the following skills with confidence Perform addition & subtraction
More informationPage 1. Where Have We Been? Chapter 2 Representing and Manipulating Information. Why Don t Computers Use Base 10?
Where Have We Been? Class Introduction Great Realities of Computing Int s are not Integers, Float s are not Reals You must know assembly Memory Matters Performance! Asymptotic Complexity It s more than
More informationCPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS
CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS Aleksandar Milenković The LaCASA Laboratory, ECE Department, The University of Alabama in Huntsville Email: milenka@uah.edu Web:
More informationLecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)
Lecture Topics Today: Integer Arithmetic (P&H 3.1-3.4) Next: continued 1 Announcements Consulting hours Introduction to Sim Milestone #1 (due 1/26) 2 1 Overview: Integer Operations Internal representation
More informationInteger Representation
Integer Representation Announcements assign0 due tonight assign1 out tomorrow Labs start this week SCPD Note on ofce hours on Piazza Will get an email tonight about labs Goals for Today Introduction to
More informationCSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators
CSE 351: The Hardware/Software Interface Section 2 Integer representations, two s complement, and bitwise operators Integer representations In addition to decimal notation, it s important to be able to
More informationArithmetic Operations
Arithmetic Operations Arithmetic Operations addition subtraction multiplication division Each of these operations on the integer representations: unsigned two's complement 1 Addition One bit of binary
More informationCPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS
CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS Aleksandar Milenković The LaCASA Laboratory, ECE Department, The University of Alabama in Huntsville Email: milenka@uah.edu Web:
More informationModule 2: Computer Arithmetic
Module 2: Computer Arithmetic 1 B O O K : C O M P U T E R O R G A N I Z A T I O N A N D D E S I G N, 3 E D, D A V I D L. P A T T E R S O N A N D J O H N L. H A N N E S S Y, M O R G A N K A U F M A N N
More information10.1. Unit 10. Signed Representation Systems Binary Arithmetic
0. Unit 0 Signed Representation Systems Binary Arithmetic 0.2 BINARY REPRESENTATION SYSTEMS REVIEW 0.3 Interpreting Binary Strings Given a string of s and 0 s, you need to know the representation system
More informationMath 230 Assembly Programming (AKA Computer Organization) Spring 2008
Math 230 Assembly Programming (AKA Computer Organization) Spring 2008 MIPS Intro II Lect 10 Feb 15, 2008 Adapted from slides developed for: Mary J. Irwin PSU CSE331 Dave Patterson s UCB CS152 M230 L10.1
More informationMACHINE LEVEL REPRESENTATION OF DATA
MACHINE LEVEL REPRESENTATION OF DATA CHAPTER 2 1 Objectives Understand how integers and fractional numbers are represented in binary Explore the relationship between decimal number system and number systems
More informationComputer Organization & Systems Exam I Example Questions
Computer Organization & Systems Exam I Example Questions 1. Pointer Question. Write a function char *circle(char *str) that receives a character pointer (which points to an array that is in standard C
More informationXuan Guo. Lecture XIV: Review of Chapter 3 & 4. CSC 3210 Computer Organization and Programming Georgia State University. March 5, 2015.
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
More informationEmbedded programming, AVR intro
Applied mechatronics, Lab project Embedded programming, AVR intro Sven Gestegård Robertz Department of Computer Science, Lund University 2017 Outline 1 Low-level programming Bitwise operators Masking and
More informationCPS 104 Computer Organization and Programming
CPS 104 Computer Organization and Programming Lecture-3 : Memory, Bit Operations. Sep. 3, 1999 Dietolf (Dee) Ramm http://www.cs.duke.edu/~dr/cps104.html CPS104 Lec3.1 GK&DR Fall 1999 Administrivia Homework
More informationSurvey. Motivation 29.5 / 40 class is required
Survey Motivation 29.5 / 40 class is required Concerns 6 / 40 not good at examination That s why we have 3 examinations 6 / 40 this class sounds difficult 8 / 40 understand the instructor Want class to
More informationReview Topics. Midterm Exam Review Slides
Review Topics Midterm Exam Review Slides Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University!! Computer Arithmetic!! Combinational
More informationSelection from Susta:Computer System Structures & John Loomis: Computer organization & M.Mudawar:Computer Architecture & Assembly Language. Cvičení 1.
Selection from Susta:Computer System Structures & John Loomis: Computer organization & M.Mudawar:Computer Architecture & Assembly Language Cvičení 1. Version: 1.1 ČVUT-FEL in Prague, Bytes, Nibbles, and
More informationArithmetic and Logical Operations
Arithmetic and Logical Operations 2 CMPE2c x +y + sum Or in tabular form Binary Addition Carry Out Sum B A Carry In Binary Addition And as a full adder a b co ci sum 4-bit Ripple-Carry adder: Carry values
More informationBinary representation of integer numbers Operations on bits
Outline Binary representation of integer numbers Operations on bits The Bitwise AND Operator The Bitwise Inclusive-OR Operator The Bitwise Exclusive-OR Operator The Ones Complement Operator The Left Shift
More informationNumber Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:
N Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as: a n a a a The value of this number is given by: = a n Ka a a a a a
More informationShift and Rotate Instructions
Shift and Rotate Instructions Shift and rotate instructions facilitate manipulations of data (that is, modifying part of a 32-bit data word). Such operations might include: Re-arrangement of bytes in a
More informationENE 334 Microprocessors
Page 1 ENE 334 Microprocessors Lecture 10: MCS-51: Logical and Arithmetic : Dejwoot KHAWPARISUTH http://webstaff.kmutt.ac.th/~dejwoot.kha/ ENE 334 MCS-51 Logical & Arithmetic Page 2 Logical: Objectives
More information9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation
Data Representation II CMSC 313 Sections 01, 02 The conversions we have so far presented have involved only unsigned numbers. To represent signed integers, computer systems allocate the high-order bit
More informationApplication Note. Introduction AN2471/D 3/2003. PC Master Software Communication Protocol Specification
Application Note 3/2003 PC Master Software Communication Protocol Specification By Pavel Kania and Michal Hanak S 3 L Applications Engineerings MCSL Roznov pod Radhostem Introduction The purpose of this
More informationTopics Power tends to corrupt; absolute power corrupts absolutely. Computer Organization CS Data Representation
Computer Organization CS 231-01 Data Representation Dr. William H. Robinson November 12, 2004 Topics Power tends to corrupt; absolute power corrupts absolutely. Lord Acton British historian, late 19 th
More informationComputer Organization MIPS ISA
CPE 335 Computer Organization MIPS ISA Dr. Iyad Jafar Adapted from Dr. Gheith Abandah Slides http://www.abandah.com/gheith/courses/cpe335_s08/index.html CPE 232 MIPS ISA 1 (vonneumann) Processor Organization
More informationCS61C Machine Structures. Lecture 12 - MIPS Procedures II & Logical Ops. 2/13/2006 John Wawrzynek. www-inst.eecs.berkeley.
CS61C Machine Structures Lecture 12 - MIPS Procedures II & Logical Ops 2/13/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L12 MIPS Procedures II / Logical (1)
More informationCOMP2121: Microprocessors and Interfacing. Number Systems
COMP2121: Microprocessors and Interfacing Number Systems http://www.cse.unsw.edu.au/~cs2121 Lecturer: Hui Wu Session 2, 2017 1 1 Overview Positional notation Decimal, hexadecimal, octal and binary Converting
More informationSigned Binary Numbers
Signed Binary Numbers Unsigned Binary Numbers We write numbers with as many digits as we need: 0, 99, 65536, 15000, 1979, However, memory locations and CPU registers always hold a constant, fixed number
More informationSISTEMI EMBEDDED. The C Pre-processor Fixed-size integer types Bit Manipulation. Federico Baronti Last version:
SISTEMI EMBEDDED The C Pre-processor Fixed-size integer types Bit Manipulation Federico Baronti Last version: 20180312 The C PreProcessor CPP (1) CPP is a program called by the compiler that processes
More informationKinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other
Kinds Of Data CHAPTER 3 DATA REPRESENTATION Numbers Integers Unsigned Signed Reals Fixed-Point Floating-Point Binary-Coded Decimal Text ASCII Characters Strings Other Graphics Images Video Audio Numbers
More informationl l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers
198:211 Computer Architecture Topics: Lecture 8 (W5) Fall 2012 Data representation 2.1 and 2.2 of the book Floating point 2.4 of the book Computer Architecture What do computers do? Manipulate stored information
More informationIntegers II. CSE 351 Autumn Instructor: Justin Hsia
Integers II CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun http://xkcd.com/571/
More informationThe type of all data used in a C (or C++) program must be specified
The type of all data used in a C (or C++) program must be specified A data type is a description of the data being represented That is, a set of possible values and a set of operations on those values
More information17. Instruction Sets: Characteristics and Functions
17. Instruction Sets: Characteristics and Functions Chapter 12 Spring 2016 CS430 - Computer Architecture 1 Introduction Section 12.1, 12.2, and 12.3 pp. 406-418 Computer Designer: Machine instruction set
More informationDo not start the test until instructed to do so!
Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other electronic devices
More informationChapter 4: Data Representations
Chapter 4: Data Representations Integer Representations o unsigned o sign-magnitude o one's complement o two's complement o bias o comparison o sign extension o overflow Character Representations Floating
More informationMore on C programming
Applied mechatronics More on C programming Sven Gestegård Robertz sven.robertz@cs.lth.se Department of Computer Science, Lund University 2017 Outline 1 Pointers and structs 2 On number representation Hexadecimal
More informationICS Instructor: Aleksandar Kuzmanovic TA: Ionut Trestian Recitation 2
ICS 2008 Instructor: Aleksandar Kuzmanovic TA: Ionut Trestian Recitation 2 Data Representations Sizes of C Objects (in Bytes) C Data Type Compaq Alpha Typical 32-bit Intel IA32 int 4 4 4 long int 8 4 4
More informationCourse Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation
Course Schedule CS 221 Computer Architecture Week 3: Information Representation (2) Fall 2001 W1 Sep 11- Sep 14 Introduction W2 Sep 18- Sep 21 Information Representation (1) (Chapter 3) W3 Sep 25- Sep
More informationIBM 370 Basic Data Types
IBM 370 Basic Data Types This lecture discusses the basic data types used on the IBM 370, 1. Two s complement binary numbers 2. EBCDIC (Extended Binary Coded Decimal Interchange Code) 3. Zoned Decimal
More informationSISTEMI EMBEDDED. The C Pre-processor Fixed-size integer types Bit Manipulation. Federico Baronti Last version:
SISTEMI EMBEDDED The C Pre-processor Fixed-size integer types Bit Manipulation Federico Baronti Last version: 20170307 The C PreProcessor CPP (1) CPP is a program called by the compiler that processes
More informationComputer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2
Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2 Instructor: Rob Bergen Applied Computer Science University of Winnipeg Announcements Website is up
More informationChapter 2A Instructions: Language of the Computer
Chapter 2A Instructions: Language of the Computer Copyright 2009 Elsevier, Inc. All rights reserved. Instruction Set The repertoire of instructions of a computer Different computers have different instruction
More informationNumber System. Introduction. Decimal Numbers
Number System Introduction Number systems provide the basis for all operations in information processing systems. In a number system the information is divided into a group of symbols; for example, 26
More informationCS3350B Computer Architecture MIPS Instruction Representation
CS3350B Computer Architecture MIPS Instruction Representation Marc Moreno Maza http://www.csd.uwo.ca/~moreno/cs3350_moreno/index.html Department of Computer Science University of Western Ontario, Canada
More informationCPS 104 Computer Organization and Programming Lecture-2 : Data representations,
CPS 104 Computer Organization and Programming Lecture-2 : Data representations, Sep. 1, 1999 Dietolf Ramm http://www.cs.duke.edu/~dr/cps104.html CPS104 Lec2.1 GK&DR Fall 1999 Data Representation Computers
More informationSISTEMI EMBEDDED. The C Pre-processor Fixed-size integer types Bit Manipulation. Federico Baronti Last version:
SISTEMI EMBEDDED The C Pre-processor Fixed-size integer types Bit Manipulation Federico Baronti Last version: 20160302 The C PreProcessor CPP (1) CPP is a program called by the compiler that processes
More informationunused unused unused unused unused unused
BCD numbers. In some applications, such as in the financial industry, the errors that can creep in due to converting numbers back and forth between decimal and binary is unacceptable. For these applications
More informationTopic Notes: Bits and Bytes and Numbers
Computer Science 220 Assembly Language & Comp Architecture Siena College Fall 2010 Topic Notes: Bits and Bytes and Numbers Binary Basics At least some of this will be review, but we will go over it for
More informationIntegers II. CSE 351 Autumn Instructor: Justin Hsia
Integers II CSE 351 Autumn 2017 Instructor: Justin Hsia Teaching Assistants: Lucas Wotton Michael Zhang Parker DeWilde Ryan Wong Sam Gehman Sam Wolfson Savanna Yee Vinny Palaniappan http://xkcd.com/557/
More informationCS 61C: Great Ideas in Computer Architecture Introduction to Assembly Language and RISC-V Instruction Set Architecture
CS 61C: Great Ideas in Computer Architecture Introduction to Assembly Language and RISC-V Instruction Set Architecture Instructors: Krste Asanović & Randy H. Katz http://inst.eecs.berkeley.edu/~cs61c 9/7/17
More informationIntegers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0
Integers So far, we've seen how to convert numbers between bases. How do we represent particular kinds of data in a certain (32-bit) architecture? We will consider integers floating point characters What
More informationChapter 2 Number System
Chapter 2 Number System Embedded Systems with ARM Cortext-M Updated: Tuesday, January 16, 2018 What you should know.. Before coming to this class Decimal Binary Octal Hex 0 0000 00 0x0 1 0001 01 0x1 2
More informationInstruction Set Architecture
C Fortran Ada etc. Basic Java Instruction Set Architecture Compiler Assembly Language Compiler Byte Code Nizamettin AYDIN naydin@yildiz.edu.tr http://www.yildiz.edu.tr/~naydin http://akademik.bahcesehir.edu.tr/~naydin
More informationData Representation 1
1 Data Representation Outline Binary Numbers Adding Binary Numbers Negative Integers Other Operations with Binary Numbers Floating Point Numbers Character Representation Image Representation Sound Representation
More informationReview Topics. Midterm Exam Review Slides
Review Topics Midterm Exam Review Slides Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University Computer Arithmetic Combinational
More informationNumber representations
Number representations Number bases Three number bases are of interest: Binary, Octal and Hexadecimal. We look briefly at conversions among them and between each of them and decimal. Binary Base-two, or
More informationECE2049-E18 Lecture 6 Notes 1. ECE2049: Embedded Computing in Engineering Design E Term Lecture #6: Exam Review
ECE2049-E18 Lecture 6 Notes 1 ECE2049: Embedded Computing in Engineering Design E Term 2018 Lecture #6: Exam Review Administrivia Exam 1: Next Tuesday (6/5) HW4: Short assignment, due Tuesday Lab 1: Due
More informationAE52/AC52/AT52 C & Data Structures JUNE 2014
Q.2 a. Write a program to add two numbers using a temporary variable. #include #include int main () int num1, num2; clrscr (); printf( \n Enter the first number : ); scanf ( %d, &num1);
More informationTutorial 1: C-Language
Tutorial 1: C-Language Problem 1: Data Type What are the ranges of the following data types? int 32 bits 2 31..2 31-1 OR -2147483648..2147483647 (0..4294967295 if unsiged) in some machines int is same
More informationCS 107 Lecture 2: Bits and Bytes (continued)
CS 107 Lecture 2: Bits and Bytes (continued) Friday, January 12, 2018 Computer Systems Winter 2018 Stanford University Computer Science Department Reading: Reader: Number Formats Used in CS 107 and Bits
More informationSU 2017 May 18/23 LAB 3 Bitwise operations, Program structures, Functions (pass-by-value), local vs. global variables. Debuggers
SU 2017 May 18/23 LAB 3 Bitwise operations, Program structures, Functions (pass-by-value), local vs. global variables. Debuggers 1. Problem A Pass-by-value, and trace a program with debugger 1.1 Specification
More informationCS 241 Data Organization Binary
CS 241 Data Organization Binary Brooke Chenoweth University of New Mexico Fall 2017 Combinations and Permutations In English we use the word combination loosely, without thinking if the order of things
More informationIntegers II. CSE 351 Autumn 2018
Integers II CSE 351 Autumn 2018 Instructor: Teaching Assistants: Justin Hsia Akshat Aggarwal An Wang Andrew Hu Brian Dai Britt Henderson James Shin Kevin Bi Kory Watson Riley Germundson Sophie Tian Teagan
More informationDigital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.
Digital Logic 1 Data Representations 1.1 The Binary System The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer. The system we
More informationCS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014
B CS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014 DUE : March 3, 2014 READ : - Related sections of Chapter 2 - Related sections of Chapter 3 - Related sections of Appendix A - Related sections
More information2010 Summer Answers [OS I]
CS2503 A-Z Accumulator o Register where CPU stores intermediate arithmetic results. o Speeds up process by not having to store these results in main memory. Addition o Carried out by the ALU. o ADD AX,
More informationOperators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur
Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators
More informationCompiler Design. Homework 1. Due Date: Thursday, January 19, 2006, 2:00
Homework 1 Due Date: Thursday, January 19, 2006, 2:00 Your Name: Question 1 Is SPARC big- or little- Endian? When a word of data is stored in memory, which byte is stored in the first byte (i.e., in the
More informationUNIT-II. Part-2: CENTRAL PROCESSING UNIT
Page1 UNIT-II Part-2: CENTRAL PROCESSING UNIT Stack Organization Instruction Formats Addressing Modes Data Transfer And Manipulation Program Control Reduced Instruction Set Computer (RISC) Introduction:
More informationSIGNED AND UNSIGNED SYSTEMS
EE 357 Unit 1 Fixed Point Systems and Arithmetic Learning Objectives Understand the size and systems used by the underlying HW when a variable is declared in a SW program Understand and be able to find
More informationMoodle WILLINGDON COLLEGE SANGLI. ELECTRONICS (B. Sc.-I) Introduction to Number System
Moodle 1 WILLINGDON COLLEGE SANGLI ELECTRONICS (B. Sc.-I) Introduction to Number System E L E C T R O N I C S Introduction to Number System and Codes Moodle developed By Dr. S. R. Kumbhar Department of
More informationCHAPTER 3: FUNDAMENTAL OF SOFTWARE ENGINEERING FOR GAMES.
CHAPTER 3: FUNDAMENTAL OF SOFTWARE ENGINEERING FOR GAMES www.asyrani.com TOPICS COVERED C++ Review and Best Practices Data, Code, and Memory in C++ Catching and Handling Errors C++ REVIEW AND BEST PRACTICES
More informationNumber Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column
1's column 10's column 100's column 1000's column 1's column 2's column 4's column 8's column Number Systems Decimal numbers 5374 10 = Binary numbers 1101 2 = Chapter 1 1's column 10's column 100's
More informationC-string format with scanf/printf
CSI333 Lecture 4 C-string format with scanf/printf char mycstring[4]; int intvar; scanf("%3s", &intvar ); /*reads up to 3 chars and stores them PLUS \ in the 4-byte var. intvar*/ scanf("%3s", mycstring);
More informationThe C Programming Language Guide for the Robot Course work Module
The C Programming Language Guide for the Robot Course work Module Eric Peasley 2018 v6.4 1 2 Table of Contents Variables...5 Assignments...6 Entering Numbers...6 Operators...7 Arithmetic Operators...7
More informationLAB A Translating Data to Binary
LAB A Translating Data to Binary Create a directory for this lab and perform in it the following groups of tasks: LabA1.java 1. Write the Java app LabA1 that takes an int via a command-line argument args[0]
More informationChapter 2 Number Systems and Codes Dr. Xu
Chapter 2 Number Systems and Codes Dr. Xu Chapter 2 Objectives Selected areas covered in this chapter: Converting between number systems. Decimal, binary, hexadecimal. Advantages of the hexadecimal number
More informationData Storage. August 9, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 August 9, / 19
Data Storage Geoffrey Brown Bryce Himebaugh Indiana University August 9, 2016 Geoffrey Brown, Bryce Himebaugh 2015 August 9, 2016 1 / 19 Outline Bits, Bytes, Words Word Size Byte Addressable Memory Byte
More informationEE 109 Unit 2. Binary Representation Systems
EE 09 Unit 2 Binary Representation Systems ANALOG VS. DIGITAL 2 3 Analog vs. Digital The analog world is based on continuous events. Observations can take on (real) any value. The digital world is based
More informationMicrocontroller. Instruction set of 8051
UNIT 2: Addressing Modes and Operations: Introduction, Addressing modes, External data Moves, Code Memory, Read Only Data Moves / Indexed Addressing mode, PUSH and POP Opcodes, Data exchanges, Example
More informationTime: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:
ECE 120 Midterm 1 HKN Review Session Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location: Your Room on Compass What to bring: icard, pens/pencils, Cheat sheet (Handwritten) Overview of Review Binary IEEE
More informationRecap from Last Time. CSE 2021: Computer Organization. It s All about Numbers! 5/12/2011. Text Pictures Video clips Audio
CSE 2021: Computer Organization Recap from Last Time load from disk High-Level Program Lecture-2(a) Data Translation Binary patterns, signed and unsigned integers Today s topic Data Translation Code Translation
More informationAnnouncements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls
Announcements HW1 is due on this Friday (Sept 12 th ) Appendix A is very helpful to HW1. Check out system calls on Page A-48. Ask TA (Liquan chen: liquan@ece.rutgers.edu) about homework related questions.
More informationME 461 C review Session Fall 2009 S. Keres
ME 461 C review Session Fall 2009 S. Keres DISCLAIMER: These notes are in no way intended to be a complete reference for the C programming material you will need for the class. They are intended to help
More information