### Create a StudySoup account

#### Be part of our community, it's free to join!

Already have a StudySoup account? Login here

# Machine Dependent Prog ECS 050

UCD

GPA 3.75

### View Full Document

## 87

## 0

## Popular in Course

## Popular in Engineering Computer Science

This 18 page Class Notes was uploaded by Ashleigh Dare on Tuesday September 8, 2015. The Class Notes belongs to ECS 050 at University of California - Davis taught by Staff in Fall. Since its upload, it has received 87 views. For similar materials see /class/191683/ecs-050-university-of-california-davis in Engineering Computer Science at University of California - Davis.

## Popular in Engineering Computer Science

## Reviews for Machine Dependent Prog

### What is Karma?

#### Karma is the currency of StudySoup.

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 09/08/15

ECS 50 Computer Organization and MachineDependent Programming Spring 2008 Introduction and Review Handout 1 shoukataliintelcom My Contact Information Name Dr Shoukat Ali pronounced Shaw Cut Uh Li Email shoukataliintelcom Phone 9169349956 Office Office Hours 730 830 PM Thursday UI DAVIS Whatl Plan To Do Today explain why this course is very important Some history of computers talk about some administrative matters What This Course Is About Introduction to Processor Architecture Introduction to instruction sets addressing modes and register sets and theirvariation from one machine to another The Role of System Software in Producing an Abstract Machine Distinction between the roles of hardware and software The use of compilers and operating systems in providing abstractions and machine independence to the programmer Machine Capability and Speed Transportabilitynontransportability of programs on different machines and under different operating systems and compilers HERAYE UC DAVIS understand the organization ofa simple microprocessor understand the use ofan instruction set Course Objectives mirrnnrnrs nr Definition Computer executes a stored pro ram what is the distinction between program and data Atkins Bib Memory Peripherals CPU mom IUI39 RAM RUM pl mlcl39 etc DANquot Bil L 39C DAVIS 1960s era of large mainframes machines costing millions of dnllar 39 r lUUlll 39r r typical applications business data processing and largescale scienti c computing 1970s era of minicomputers smallersized machines mostly used by multiple users in a time sharequot fashion each user would access the machine through a dumb terminal A Short History of Computers More A Short History of Computers 1980s era of desktop computers based on microprocessors personal computers and workstations individually owned no tim i g led to servers computers that provided largerscale services such as reliable longterm le storage le servers and more computing power compute servers 1980s also saw microcontrollers aka embedded computer computers lodged in other devices where the presence ofthe computers is not immediately obvious these computers interface with real world and turn some devices on and off and monitor conditions 1990s era ofthe Internet and the World Wide Web UCDAVIS A Desktop Computer General Purpose Microprocessors and Microcontrollers microprocessor a computer that is contained in a single integrated circuit all peripherals are offthe CPU chip microcontroller a microprocessor with a number of integrated peripherals everything is on one chip J9 Dammu CPL CPU RA ROM 1 mm Q h Genus nle atha 39C p Purpow V v Minor 10 Tunel Sena W 1 pnw t l UM Pl ll Addie bus 4 quot in Geuemmupase Mwmpmmor Swan in llcrommmllex V r onmp a L gt v m Three Types of Computers Currently Important Which Computer Type Sells More desktop server and embedded computers mmquot new Embedded Mums ximsmooo mummpmua um um um m wxxwx o mum ma Warm mm 4mm 40a nu Mmpmc onwldyxryear mth minutes in mu uu l we mm prorassorwnly cnmlsysmlesltnwp Pncerpzrmmmnm Thmughpu mummy mmpmmnmupum mm ye wmann mm applimtlmvsyvki r pcrlammnm mum 0 mm L onquot M mg on 12 Microcontrollers Are Embedded In These Horne Items Home pplian amcorder Imemom Remote controls Teleph ues id Security systems Cellul ome computers Pagmg vs Camera Cable TV tuner imball machmes VCR ys Exercise equipment tit laws 13 Administrative Matters More Microcontroller Applications Consumer electronics Industrial Controls Labeling machines Coin Acceptors Aerospace Flight control systems Navigation systems U our Do Not Jeopardize Your Success In ECS5O every one ofyou can do well on this course do not jeopardize your success by skipping classes failing to do the homework procrastinating expecting to learn by osmosisquot being dishonest in any way nanny151D mum ways at Lezmmu Deslnn ve wvvsa eNan edmesanhawmsawecamsevmb ems an vvudmv mmmmmcamemm WmmmmmQ sesmmumemm mmva mm mWunmmmasmm mmy bmwmvemembevmomm mm pm m m w puns m m H Cnurse PrerEquIslles mm Iexlhnnk vac v s mcampmgsmm eum M nummmc aw mecemu 1992 mum w ymczl Le ure rnmm 5mmmevw ewa hevvemaus em 35 muka 5 mmme mum 5mm m my mquot 35 muka mm mm cuss unmasm mm mm mm magnum 5mg Wmmmbummbmmmm m JCDNIIS Homework Assignments while you are expected to complete all homework assignments the grader may randomly select only certain problems to grade two types of assignments exercises from the text book or otherwise the weekly MCQs daily multiple choice questions students submit two MCQs every week on Tuesday must submit the question 4 choices and the solution based on the content of the previous week s lectures due by midnight every Tuesday must be submitted by emailing to me starts the second week of classes No late homework UCDAVIS 21 Exam Dates Exam 1 Thursday April 24 Exam 2 Tuesday May 20 Final Exam Tuesday June 10 from 8301030 PM students needing special accommodations for an exam should notify me at least one week prior to the exam UL DAVIS 23 Group Exercises and Quizzes class will be divided into groups of 2 3 students one person from the group should email me with the names of all group members deadline forthis email is one weekfrom today group members will be working together on some class exercises may also have a number of unannounced quizzes in class to be submitted by each student individually a score of zero will be given for a quiz or group exercise in case of absence ucnnws n Grading Homework 20 Quizzes and group exercises 5 Exam 1 20 Exam 2 20 Final exam comprehensive 35 QC DAVIS 24 Academic Honesty Do not take someone else39s work and present it as your own I encourage you to study in groups Discussions on HW are welcome However you must not take someone else s work and present it as your own If in doubt please check with me Any instances of cheating will be reported to university administrative officials for further action and possible suspension or expulsion from the University H M Feedback VWI take surveys from time to time Your comments are welcome throughout the semester Number Systems UC DAVIS munJnuh u mum Signals l WWI lily Basic Electronic Signal Concepts signal a voltage or a current that conveys information so how many pieces of information are in a signal depends on how you interpret the signalll analog signal signal changes in a range and value of the signal represents a l piece of information binary digital signal signalchanges in a range but we interpret only pieces of information 0 or 1 false or true no or yes negated or asserted bad or good UCDAVIS 29 So What Is A Digital Signal Like the way a signal is interpreted can be different the digital way of interpreting a signal the analog way of interpreting a signal Why Are We Talking About Number Systems Information is represented using bit patterns in computers l100101111011111011001011 VVhy UL DAVIS 31 5 volts any voltage in the red range is interpreted as logic 1 any voltage in the gray range cannot be interpreted invalid any voltage in the green range is interpreted as logic 0 0 volts ucwns an Different Types of Numbers integers 2 1012 real numbers 12141421356 380375 questions how do we represent integers and real numbers in a binary digital system how should we implement arithmetic operations like add subtract multiply and divide QC DAVIS 32 Positional Number System Base 10 l the familiar decimal system uses 10 digits 0129 l the digits are placed side by side I the position of a digit determines its true value I 1962 l19621X1039X1026X1012X100 1000900602 1962 l14251X1014X1002X10715X1072 10402005 1425 UCDAVIS 33 Positional Number System Generalize I generalize the idea on the previous slide to any base I consider a S of digits 1an 110112qp I assume 8 is expressed in base b I the value ofS in base b dMX b 391 dox b0 d71 X b1 d7pgtlt brp ii I 31245x521x4xj 755208 828m Binary Numbers I numbers expressed in base 2 I 10121gtlt22 0x211gtlt20 401 5 I 110110121X231X22 0X211X201X2 1 0X2 2 1gtlt2 3 840105025 137510 I converting from decimal to binary I divide the given number repeatedly by 2 until the quotient is less than 2 save all remainders I string togetherthe remainders to form the binary equivalent UL DA I5 35 UI DAVIS 34 Binary Numbers Conversion Example 39 2310 2 I 32 quot 11 rem 1 LSB I 112 quot 5 rem 1 I 52 quot 2 rem 1 I 22 quot 1 rem 0 I 12 quot 0 rem 1MSB I Sanity check I 1011121gtlt24 0x231gtlt221gtlt211x2016421 23 HERAYE 36 Converting From Decimal to Base N analogous to the method for converting from decimal to binary repeatedly divide by N until quotient is zero save all remainders the first remainder is the least significant digit and the last remainder is the most significant digit UCDAVIS 37 Converting From Decimal to Base N How do we determine d1 dnyW dyrvar3 di d1 XN LHS divided by N results in Quotient of dwquotNV393 72quoter4 d2 Remainderis d1 UL DAVIS 39 Converting From Decimal to Base N a we want to know how to represent 257 in base 16 using 4 digits in base 16 We want to know d3d2d1d0 such that d3163 d2162 df16 d0160 257 From previous slide we know that d3d2d1d0 is 0101 In general representing X in base N using y digits requires solving dwquotNv1dr2 Nv2 0X each digit is less than N and larger than 0 LHS divided by N dnyW dyrfNW d1 d0N the quotient is dwquotNV392 dH WV393 d1 the remainder is d Notation remainder of X divided by N X mod N Notation quotient ofX divided by N XN UI DAVIS 38 Representing Negative Numbers three methods exist signedmagnitude representation radix complement representation method 1 is most intuitive but least easy to use for additionsubtraction will see why the socalled complement representations are a better suited for additionsubtraction will see why QC DAVIS 4n SignedMagnitude SM Representation use a symbol to specify whether the magnitude is positive or negative for decimal numbers positivenegative are indicated by and signs 1030 210012 for binary numbers positivenegative are indicated by using an extra bit position 0 for positive 1 for negative 01012 510 11012 5m 01112 1011112 7m 00002 010 10002 0m UCDAVIS 41 Complement Number CN Representation in SM a positive number and its negation differ only in sign or a sign bit for binary numbers in ON the negative of a number is equal to the socalled complement of the number radix complement of an n digit number D is given by r D where ris the radix or base of the number 10 s complement of 49 is 102 49 51 ie negative of 49 in 10 s complement is 51 UL DAVIS 43 Problem With Using SM Representation how to add two numbers represented in SM examine theof the addends if both have the same justand use the sign of the addends as the sign of the sum if the addends have different determine which number has the larger magnitude subtract the smaller magnitude number from the larger magnitude number append the sign of the larger magnitude number with the difference so what what is the problem with the above complement representation of negative numbers does not have this problem UC DAVIS 42 More on Radix Complement Representation of Negative Numbers for binary numbers radix complement is called two s complement the complement equals r D 2 D alternative convenient way of finding 2 s complement write the number in the binary form I flip all bits I add one drop any carry out ofMSB 8bit examples 17m000100012 omoooooooo2 1mooooooo12 flipbits 111011102 111111112 111111102 add1 111011112 1000000002 111111112 Ifact a ve number will always have a1 in the MSB I HELENE 4 Conversions in 2 s Complement I 1011127 I 1gtlt 24H 0x231gtlt221x211x20 16421 9 I note that if we are not using unsigned numbers 11121gtlt24 0X231gtlt221gtlt211X2016421 23 I given n bits the range of representable numbers in 2 s complement is 2 1 to 2 1 1 UCDAVIS 45 2 s Complement AdditionSubtraction I add 2 s complement numbers just as we would add positive numbers and ignore the carry out of the sign bit I sign bit is the MSB Short Quiz Positional Notation I number representation I d31 3D dzdwdCI is a 32digit number I what is its value I questions I what is the value of101 ifit is in binary base I what is the value of101 ifit is in base 16 I what is the value of101 ifit is in base 10 UL DAVIS 47 USP E More On 2 s Compliment Binary Base I more examples I what is the value of 1111 if it is in 2 s com Iement binar base 1111 I what is the value of 11 if it is in 2 s complement binary base 11 I what is the value of 111 1 if it is in 2 s complement binary I 1 I what is the largest 4bit number in 2 s complement binary I le most bit must be nd all others must be I 0 4 2 1 I what is the smallest 4bit number in 2 s complement binary I le most bit must be nd all others must be I 80008 given n bits the range of representable numbers in 2 s complement is 2 1 to 2M 1 ugznAVIs 48 Encoding A Number In 2 s Compliment Binary how do we encode a negative number say 7 using 4bit 2 s complement binary many methods exist one heat trick encode the magnitude in simple binary 7 ip the bits u add 1 l drop any carry out of le most bit check to make sure you got it right 1001 I 7 UCDAVIS 49 Is The Result Of An Addition Valid Computers do all their processing in fixed size cells called registers Intel 8086 80186 80286 have 16 bit wide registers Intel 80386 i486 Pentium Core have 32 bit wide registers Intel Itanium has 64 bit wide registers Unless the result of an addition is too large to be accommodated in the registerwhere the result is deposited the addition is valid How do we know if it is invalid vegMa an Comparing Unsigned Binary and 2 s Complement Bit string in in 2 s UL DAVI 51 Overflow in Unsigned Binary Assume an 8bit long string If the sum is more than 255 we say that the addition has overflowed Can be detected in the hardware by checking if there is a carry out of the most significant bit MSB Usually computers store the value of the carry that comes out of the MSB in a special 1bit cell called the carry flag After an unsigned addition the carry flag is checked If it is 1 the addition has overflowed 01111111 127 11111111 255 01111111 127 00000010 2 10000000 128 10000000 128 10000001 129 01111111 127 11111111 255 DAVIS 52 HS Overflow in 2 s Compliment Binary Assume an 8bit long string If the sum is more than 127 or smaller than 128 the addition has overflowed Can only occur if the sign bits of the numbers being added are the same Can be detected in the hardware by checking if the sign bit of the result is not the same as that of numbers being added 01111111 127 00000010 2 11111111 1 01111111 127 10000000 l128 10000001 127 10000001 127 01111111 127 00000000 0 In computers there is a special 1bit cell ca the overflow flag that is set by hardware to 1 for all cases like UCDAVIS 53 Hexadecimal Numbers Base 16 hexadecimal numbers can use 16 digits I 0123456789ABCDEF I A10B11C12 I D913E14F15 I what is the value of BZFD if it is in base 16 BZFD 8x163 2x162Fx161 0x160 vegMa 54 Hex to Binary Conversion Hexadecimal is a more compact representation of binary Each hex digit representsdecimal values Four binary digits representdecimal values Therefore one hex digit can replacebinary digits Example I 0011 1011 1001 1010 1100 1010 0000 0000 binary 3 l9 Dc l0 E hex I the C language assumes that any number prefixed by 0x is hexadecima I eg is understood to be hexadecimal UL DAVI Which Base Should We Use I decimal I great for humans most arithmetic is done with this base I 2 s complement binary I this is what computers use so get used to them I become familiar with how to do basic arithmetic with them I hex I long strings of binary numbers are much better represented in hex ugznAVIs SB ECS 50 Chapter 2 Lecture Notes I Main Memory Organization and Maj or Hardware Components A What is the type of information stored in a memory location 1 Unknown by hardware 2 It is in the hands of the programmercompiler a inty 32697 0X8047 b printfquotd u cnquot y y y in a 32 bit machine c 32697 32839 G in a 32 bit II Main Memory Organization A word size usually the size of number used in CPU addition circuitry 32 bits usually now Integers the size of a word B How are multiple byte words stored l Littleendian LSByte has lower address Intel 2 Bigendian LSByte has highest address VAX SPARC CUSP a Allows word subtraction for alphabetizing 3 MIPS and PowerPC give the OS the choice of either endian when it boots C Words must be aligned in most machines In 32bit means words only begin at addresses which are multiples of 4 Thus byte access and word access are two different things D Most RISC machines tend to use xed instruction length equal to the word size E Most CISC machines have variable instruction lengths l 6 bytes or more F address size number of bits in an address CUSP 12 bits 8086 20 bits 286 24 bits 386 and RISC 32 bit III Four Major Hardware Components of a Computer A CPU 1 ALU arithmetic and logic unit Arithmetic bitwise operations compare Doesn t store anything Control Unit is intelligence of CPU Does decoding Registers a PC Program counter Contains address of currently executing instruction b On Intel actually CS code segment and IP instruction pointer 1 16bit mode has 20 bit addresses uses 16 bit CS as MSB and then adds 16 bit IP 2 32bit mode has 32 bit addresses uses 32 bit CS and IP c SP Stack pointer Contains address of top of stack for temporary storage d XR IndeX register Helps access arrays e PS Process status register Contains ags including condition codes and bigendian vs little endian ag for PowerPC and MIPS I DRs Data registers 1 Word size 2 CUSP Accumulator 3 MIPS has 32 32bit general purpose registers PC and two for multiplication 4 SPARC has 8 global and a register window onto a quotregister lequotthat sees 24 registers at a time Implementations allow 2 to 32 windows Great for procedure calls Think of as top of stack g MAR Memory address register CPU connection to address bus h MDR Memory data register CPU connection to data bus i IR Instruction register Holds current instruction so MDR may be overwritten wzv 4 Memory a Internal cache on CPU Chip b Pentium 8K data 8K address c Secondary Cache on motherboard before system bus 256K 1M 15 ns B Main memory on motherboard 60 ns 1 Secondary Memory on disk 10000 ns C 10 Devices 1 Keyboards monitors CDROMs modems printers modems oppy disks hard disks D System Bus 1 Data BusSame number of lines as bits in a memory word a CUSP 24 bits b Petium 2 32bits allows two words to be accessed simultaneously 2 Address BusSame number of lines as bits in the computer s addresses a CUSP 12 bits 3 Control Bus a MEMR and MEMW tell memory whether to read or write IV Instruction CycleFetch decode execute A Fetch by transferring instruction at address of PC from memory to IR B Decode instruction using microcode of CPU 1 Also increment PC C Execute the instruction V SelfModifying Programs A The only thing to be learned from these is that code and data are indistinguishable to the computer Discussion 2 Notes 012808 Practice Midterm Problem 1 Write the CUSP oating point representation for the decimal 1350625 Remember the CUSP s representation is 8bit exponent followed by the sign bit followed by the 16bit mantissa which excludes the leading 1 leading one is implicit Thus as 13510 100001112062510 00012 The binary representation of 1350625 is 100001110001 1000011100010000 27 8bit exponent field 7 135810855123 100001112 Sign bit 0 positive number 16 bit mantissa field with implicit leading 1 000011100010000 Putting all that together you get 100001110000011100010000 which is 870710 Practice Midterm Problem 2 Signed 25 complement values are added or substracted in exactly the same manner as unsigned ones Remember as mentioned in the book that computers do not substract 7 they negate the second operand and add them together Also in the case of unsigned addition over ow occurs when the correct sum is too large to be represented using the available bits In the case of unsigned substraction over ow occurs if the value being substracted is the larger one In the case of signed addition as well as substraction over ow occurs when the result has an incorrect sign Assume signed 25 complement operation A56FF3 9FF7FF OV 456782 381734 808080 B796B4 A689BE B8FDE3 A689BE 47021D ED8BDB Exercise 1 1 What is the purpose of minios lst and minicgts obj files 2 Say that you are writing a program and that it currenty contains a bug How would you go about debugging it How do you run a program in cusp How do you step through a program What does the instruction JMP FUNCTION accomplish What does the instruction RTN accomplish 3 4 5 Why is the first instruction of all your programs LDS EO 0 6 7 8 What is the purpose of minios library What are some functions that it provides Exercise 2 Convert the following C code into CUSP if n lt 10 X 1 else X 3 Y 5 In CUSP code LDA N CMA lO JGT ELSE LDA 1 STA X JMP AFTER ELSE LDA 3 STA X LDA 5 STA Y AFTER More C code i 1 while i lt 10 i In CUSP code LDA 1 STA I LOOP CMA lO JGT OUT INC I JMP LOOP OUT n lt 10 If not skip to else part X 1 Branch around else part X 3 y5 Both paths continue from here i l i lt 10 if not break i go re test i

### BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.

### You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

#### "I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

#### "I bought an awesome study guide, which helped me get an A in my Math 34B class this quarter!"

#### "I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

#### "It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.