The document discusses machine instructions and program execution, including different methods for representing signed integers like sign-and-magnitude, one's complement, and two's complement. It also covers binary addition and subtraction using two's complement representation, addressing methods for accessing memory operands, and basic operations on data structures like stacks, queues, lists, and arrays.
The document discusses binary number systems and binary arithmetic. It begins by explaining that binary uses only two digits, 0 and 1, with a base or radix of 2. Each digit has a value depending on its position in the number. The document then provides reasons why binary is used in computers, such as being digital and using simple on/off circuits. It proceeds to explain the rules and processes for binary addition, subtraction, and provides examples of carrying and borrowing in binary arithmetic.
The document discusses different encoding strategies for compressing genomic sequence data, including fixed codes like Golomb-Rice codes and variable codes like Huffman codes. It evaluates the strategies using three datasets - one with highly clustered retrotransposon insertion sites, one with in vivo binding site locations with many single-nucleotide substitutions, and one corresponding to a full diploid human genome sequencing experiment. Preliminary results found Golomb-Rice codes best for encoding locations while Elias Gamma codes worked well for encoding mismatches.
This document discusses number representation systems used in computers, including binary, decimal, octal, and hexadecimal. It provides examples of converting between these different bases. Specifically, it covers:
1) Converting between decimal, binary, octal, and hexadecimal using positional notation and place values.
2) Representing signed integers in binary using ones' complement and twos' complement notation.
3) Tables for converting binary numbers to octal and hexadecimal using place values of each base.
4) Examples of converting values between the different number bases both manually and using the provided conversion tables.
The document discusses different number systems used in computing, including binary, hexadecimal, and octal. It explains that computers internally use the binary number system to represent data and perform calculations. Hexadecimal provides a shorthand way to work with binary numbers, with each hex digit corresponding to four binary digits. The document also covers how to convert between decimal, binary, hexadecimal, and octal numbers. It provides examples of expanding numbers in different bases, as well as adding and subtracting binary numbers using complements.
The document provides an overview of binary systems and how computers use binary to represent data and perform computations. It begins by explaining that computers represent all data and programs as sequences of zeros and ones, using binary rather than decimal. It then discusses the decimal numbering system to provide context for explaining binary. The bulk of the document defines the binary system, how numbers are represented with powers of two, and how to convert between decimal and binary numbers with examples. It concludes by discussing how computers work with groups of bits and standard units of data storage.
This document discusses number bases and converting between different number bases. It covers:
- Place value and value of digits in base 2, 8, and 10
- Writing numbers in expanded notation in different bases
- Converting numbers between bases 2, 8, 10 and vice versa
- Addition and subtraction in base 2
The document provides information about number representation systems including binary, octal, hexadecimal, binary-coded decimal, and ASCII/Unicode character coding. It discusses how to convert between these different numbering systems, perform arithmetic operations like addition in each system, and describes features of each system such as the range of values that can be represented. Examples are provided to illustrate concepts like binary addition, 2's complement representation of negative numbers, and BCD addition. Control codes used in ASCII and the expanded character set of Unicode are also mentioned.
The document discusses binary number systems and binary arithmetic. It begins by explaining that binary uses only two digits, 0 and 1, with a base or radix of 2. Each digit has a value depending on its position in the number. The document then provides reasons why binary is used in computers, such as being digital and using simple on/off circuits. It proceeds to explain the rules and processes for binary addition, subtraction, and provides examples of carrying and borrowing in binary arithmetic.
The document discusses different encoding strategies for compressing genomic sequence data, including fixed codes like Golomb-Rice codes and variable codes like Huffman codes. It evaluates the strategies using three datasets - one with highly clustered retrotransposon insertion sites, one with in vivo binding site locations with many single-nucleotide substitutions, and one corresponding to a full diploid human genome sequencing experiment. Preliminary results found Golomb-Rice codes best for encoding locations while Elias Gamma codes worked well for encoding mismatches.
This document discusses number representation systems used in computers, including binary, decimal, octal, and hexadecimal. It provides examples of converting between these different bases. Specifically, it covers:
1) Converting between decimal, binary, octal, and hexadecimal using positional notation and place values.
2) Representing signed integers in binary using ones' complement and twos' complement notation.
3) Tables for converting binary numbers to octal and hexadecimal using place values of each base.
4) Examples of converting values between the different number bases both manually and using the provided conversion tables.
The document discusses different number systems used in computing, including binary, hexadecimal, and octal. It explains that computers internally use the binary number system to represent data and perform calculations. Hexadecimal provides a shorthand way to work with binary numbers, with each hex digit corresponding to four binary digits. The document also covers how to convert between decimal, binary, hexadecimal, and octal numbers. It provides examples of expanding numbers in different bases, as well as adding and subtracting binary numbers using complements.
The document provides an overview of binary systems and how computers use binary to represent data and perform computations. It begins by explaining that computers represent all data and programs as sequences of zeros and ones, using binary rather than decimal. It then discusses the decimal numbering system to provide context for explaining binary. The bulk of the document defines the binary system, how numbers are represented with powers of two, and how to convert between decimal and binary numbers with examples. It concludes by discussing how computers work with groups of bits and standard units of data storage.
This document discusses number bases and converting between different number bases. It covers:
- Place value and value of digits in base 2, 8, and 10
- Writing numbers in expanded notation in different bases
- Converting numbers between bases 2, 8, 10 and vice versa
- Addition and subtraction in base 2
The document provides information about number representation systems including binary, octal, hexadecimal, binary-coded decimal, and ASCII/Unicode character coding. It discusses how to convert between these different numbering systems, perform arithmetic operations like addition in each system, and describes features of each system such as the range of values that can be represented. Examples are provided to illustrate concepts like binary addition, 2's complement representation of negative numbers, and BCD addition. Control codes used in ASCII and the expanded character set of Unicode are also mentioned.
The document contains instructions for a 35-question mathematics exam on number bases in English for a Malaysian student. It specifies that the exam covers 7 constructs being tested and provides directions on filling out the answer sheet and bubbling in responses. The exam contains both objective and subjective questions ranging in content from place value and conversion between number bases to operations in different bases.
This document contains examples and problems related to binary number systems. It begins by listing octal, hexadecimal, and base-12 numbers and converting between number systems. Later problems involve operations like addition, subtraction, multiplication and division using binary, octal and hexadecimal numbers. Conversions between decimal, binary, octal and hexadecimal are demonstrated. Complement representations for signed binary numbers are also covered.
This document contains 6 presentations on number systems and bases. It covers converting between binary and base 10, adding and subtracting binary numbers, binary multiplication, examples in base 5, and examples in base 7. Calculations are shown for converting between bases, adding, subtracting, and multiplying numbers in different bases.
The document discusses different number systems including positional and non-positional systems. It covers the decimal, binary, octal and hexadecimal number systems in detail. Key points include:
1) Positional systems use the place value of digits to represent numbers, with the decimal and binary systems being examples.
2) Converting between number bases involves repeatedly dividing the number by the new base and recording the remainders as digits.
3) Binary, octal and hexadecimal use groups of bits/digits to simplify conversions between the bases.
4) Floating point numbers represent real numbers with a mantissa and exponent in positional notation.
To convert a binary number to octal:
1) Separate the binary number into groups of 3 digits from the right.
2) Convert each 3-digit group to its octal equivalent.
3) The octal number is the combination of each converted group from right to left.
Overview of computer math and numbers targeted at middle and high school. Covers computer use of numbers including binary numbers, a flip-flop, exponents. A few binary number games and projects are included.
This document provides an overview of binary arithmetic concepts that are important for understanding how computers perform basic math operations. It discusses how binary addition and subtraction work, including the concepts of carrying digits and overflow. It also covers representing negative numbers using two's complement notation and how this allows subtraction to be performed by addition. Finally, it explains how multiplication and division can be accomplished in binary by shifting bits left or right, known as multiplication and division by powers of 2. The goal is to explain these fundamental binary math operations rather than focusing on calculating decimal values.
The document discusses binary numbers and arithmetic. It covers topics like addition, subtraction, multiplication in binary, and different methods for representing signed integers like two's complement. It explains how two's complement works by using bitwise operations to represent negative numbers. For example, it shows that adding two positive 8-bit binary numbers in two's complement is simply the bitwise addition, while subtraction can be performed by adding the number and the two's complement of the subtrahend. The document also discusses issues like carry vs overflow that can occur during binary arithmetic operations.
The document discusses different data types including binary numbers, unsigned and signed integers represented in binary, floating point numbers, and logical operations on bits. It explains binary addition and subtraction, overflow, and different representations for signed integers including sign-magnitude, one's complement, and two's complement. It also covers converting between decimal and binary numbers.
Numeral Systems: Positional and Non-Positional
Conversions between Positional Numeral Systems: Binary, Decimal and Hexadecimal
Representation of Numbers in Computer Memory
Exercises: Conversion between Different Numeral Systems
The document discusses number systems and conversions between different bases. It explains that computers use the binary system with bits representing 0s and 1s. 8 bits form a byte. Decimal, binary, octal and hexadecimal numbering systems are covered. Methods for converting between these bases are provided using division and remainders or grouping bits. Common powers and units used in computing like kilo, mega and giga are also defined. Exercises on converting values between the different number systems are included.
This document provides information about decimal and binary number systems including:
1) Tables that show decimal numbers and their equivalent binary representations from 0 to 15 and other examples up to 100.
2) Examples of converting between decimal and binary with steps shown for converting 1011, 100101, 13, 27, and 114 between the number systems.
3) Practice problems and solutions for adding, subtracting, and converting between decimal and binary.
This document discusses various topics related to digital representation of data including:
1. The differences between FAT32 and NTFS file systems and their advantages and limitations.
2. How data is represented digitally using coding schemes like ASCII and converted between binary and other number systems.
3. An overview of different numbering systems including binary, decimal, octal and hexadecimal; and how to convert between them.
This document contains an exercise on digital electronics concepts including:
1. The differences between analog and digital measurements and pros and cons of analog vs digital electronics.
2. Tables defining binary, octal, decimal, and hexadecimal number systems.
3. Practice problems converting between number systems and performing basic binary math operations like addition, subtraction, multiplication, and division.
4. An independent practice section with additional problems converting between number systems and performing binary math.
The document discusses digital and binary number systems. It covers:
1) Analogue vs digital signals, with digital being discrete values represented using bits for precision.
2) Why digital is used for processing over analogue - due to advances in integrated circuits and noise resistance.
3) How digital values are represented using boolean logic and binary number systems. This includes binary, hexadecimal, and signed numbers using two's complement notation.
4) Arithmetic operations like addition, subtraction in binary using two's complement. The same hardware can be used for both with different flag settings to indicate carry vs overflow.
IP addressing uses logical addressing at the network layer. There are two main versions - IP version 4 uses 32-bit addressing, while IP version 6 uses 128-bit addressing. IP addresses are divided into classes based on the number of network and host bits. Each class supports a different number of networks and hosts per network. Private IP addresses are set aside for internal networks not connected to the public internet. Subnet masks are used to distinguish the network and host portions of an IP address.
Number System | Types of Number System | Binary Number System | Octal Number ...Get & Spread Knowledge
Topic: Number System | Types of Number System | Binary Number System | Octal Number System | Decimal Number System | Hexadecimal Number System
Subject: Digital Logic & Design
Programs: Bachelor of Computer Science, Bachelor of Engineering, Bachelor of Technology, Bachelor of IT, Master of Computer Science.
Lecturer: Junaid Qamar
Email: Getandspreadknowledge@gmail.com
The document outlines a trail project in Eatonville, Washington that will be completed in two phases. Phase 1 will be a volunteer project in September 2012. Phase 2 will include stabilizing a river bank, removing a bridge pier, and installing a prefabricated bridge. The project received $500,000 in donations and a $700,000 grant requiring $702,000 in matching funds to reach the total $1,402,000 budget. Designs for Phase 2 will be completed by October 2012 with construction slated to begin in June 2013.
The Washington Invasive Species Council coordinates efforts to prevent, detect, and eradicate invasive species across the state. It develops statewide strategies and works with various agencies and organizations. The council focuses on prevention, early detection and response, education and outreach, and control and eradication. Many pathways can introduce invasive species, including boats, vehicles, nursery plants, aquaculture, and more. The council provides protocols for inspecting and cleaning equipment to prevent spread when working outdoors. Outreach campaigns aim to educate the public, and a reporting hotline allows people to report sightings.
The document contains instructions for a 35-question mathematics exam on number bases in English for a Malaysian student. It specifies that the exam covers 7 constructs being tested and provides directions on filling out the answer sheet and bubbling in responses. The exam contains both objective and subjective questions ranging in content from place value and conversion between number bases to operations in different bases.
This document contains examples and problems related to binary number systems. It begins by listing octal, hexadecimal, and base-12 numbers and converting between number systems. Later problems involve operations like addition, subtraction, multiplication and division using binary, octal and hexadecimal numbers. Conversions between decimal, binary, octal and hexadecimal are demonstrated. Complement representations for signed binary numbers are also covered.
This document contains 6 presentations on number systems and bases. It covers converting between binary and base 10, adding and subtracting binary numbers, binary multiplication, examples in base 5, and examples in base 7. Calculations are shown for converting between bases, adding, subtracting, and multiplying numbers in different bases.
The document discusses different number systems including positional and non-positional systems. It covers the decimal, binary, octal and hexadecimal number systems in detail. Key points include:
1) Positional systems use the place value of digits to represent numbers, with the decimal and binary systems being examples.
2) Converting between number bases involves repeatedly dividing the number by the new base and recording the remainders as digits.
3) Binary, octal and hexadecimal use groups of bits/digits to simplify conversions between the bases.
4) Floating point numbers represent real numbers with a mantissa and exponent in positional notation.
To convert a binary number to octal:
1) Separate the binary number into groups of 3 digits from the right.
2) Convert each 3-digit group to its octal equivalent.
3) The octal number is the combination of each converted group from right to left.
Overview of computer math and numbers targeted at middle and high school. Covers computer use of numbers including binary numbers, a flip-flop, exponents. A few binary number games and projects are included.
This document provides an overview of binary arithmetic concepts that are important for understanding how computers perform basic math operations. It discusses how binary addition and subtraction work, including the concepts of carrying digits and overflow. It also covers representing negative numbers using two's complement notation and how this allows subtraction to be performed by addition. Finally, it explains how multiplication and division can be accomplished in binary by shifting bits left or right, known as multiplication and division by powers of 2. The goal is to explain these fundamental binary math operations rather than focusing on calculating decimal values.
The document discusses binary numbers and arithmetic. It covers topics like addition, subtraction, multiplication in binary, and different methods for representing signed integers like two's complement. It explains how two's complement works by using bitwise operations to represent negative numbers. For example, it shows that adding two positive 8-bit binary numbers in two's complement is simply the bitwise addition, while subtraction can be performed by adding the number and the two's complement of the subtrahend. The document also discusses issues like carry vs overflow that can occur during binary arithmetic operations.
The document discusses different data types including binary numbers, unsigned and signed integers represented in binary, floating point numbers, and logical operations on bits. It explains binary addition and subtraction, overflow, and different representations for signed integers including sign-magnitude, one's complement, and two's complement. It also covers converting between decimal and binary numbers.
Numeral Systems: Positional and Non-Positional
Conversions between Positional Numeral Systems: Binary, Decimal and Hexadecimal
Representation of Numbers in Computer Memory
Exercises: Conversion between Different Numeral Systems
The document discusses number systems and conversions between different bases. It explains that computers use the binary system with bits representing 0s and 1s. 8 bits form a byte. Decimal, binary, octal and hexadecimal numbering systems are covered. Methods for converting between these bases are provided using division and remainders or grouping bits. Common powers and units used in computing like kilo, mega and giga are also defined. Exercises on converting values between the different number systems are included.
This document provides information about decimal and binary number systems including:
1) Tables that show decimal numbers and their equivalent binary representations from 0 to 15 and other examples up to 100.
2) Examples of converting between decimal and binary with steps shown for converting 1011, 100101, 13, 27, and 114 between the number systems.
3) Practice problems and solutions for adding, subtracting, and converting between decimal and binary.
This document discusses various topics related to digital representation of data including:
1. The differences between FAT32 and NTFS file systems and their advantages and limitations.
2. How data is represented digitally using coding schemes like ASCII and converted between binary and other number systems.
3. An overview of different numbering systems including binary, decimal, octal and hexadecimal; and how to convert between them.
This document contains an exercise on digital electronics concepts including:
1. The differences between analog and digital measurements and pros and cons of analog vs digital electronics.
2. Tables defining binary, octal, decimal, and hexadecimal number systems.
3. Practice problems converting between number systems and performing basic binary math operations like addition, subtraction, multiplication, and division.
4. An independent practice section with additional problems converting between number systems and performing binary math.
The document discusses digital and binary number systems. It covers:
1) Analogue vs digital signals, with digital being discrete values represented using bits for precision.
2) Why digital is used for processing over analogue - due to advances in integrated circuits and noise resistance.
3) How digital values are represented using boolean logic and binary number systems. This includes binary, hexadecimal, and signed numbers using two's complement notation.
4) Arithmetic operations like addition, subtraction in binary using two's complement. The same hardware can be used for both with different flag settings to indicate carry vs overflow.
IP addressing uses logical addressing at the network layer. There are two main versions - IP version 4 uses 32-bit addressing, while IP version 6 uses 128-bit addressing. IP addresses are divided into classes based on the number of network and host bits. Each class supports a different number of networks and hosts per network. Private IP addresses are set aside for internal networks not connected to the public internet. Subnet masks are used to distinguish the network and host portions of an IP address.
Number System | Types of Number System | Binary Number System | Octal Number ...Get & Spread Knowledge
Topic: Number System | Types of Number System | Binary Number System | Octal Number System | Decimal Number System | Hexadecimal Number System
Subject: Digital Logic & Design
Programs: Bachelor of Computer Science, Bachelor of Engineering, Bachelor of Technology, Bachelor of IT, Master of Computer Science.
Lecturer: Junaid Qamar
Email: Getandspreadknowledge@gmail.com
The document outlines a trail project in Eatonville, Washington that will be completed in two phases. Phase 1 will be a volunteer project in September 2012. Phase 2 will include stabilizing a river bank, removing a bridge pier, and installing a prefabricated bridge. The project received $500,000 in donations and a $700,000 grant requiring $702,000 in matching funds to reach the total $1,402,000 budget. Designs for Phase 2 will be completed by October 2012 with construction slated to begin in June 2013.
The Washington Invasive Species Council coordinates efforts to prevent, detect, and eradicate invasive species across the state. It develops statewide strategies and works with various agencies and organizations. The council focuses on prevention, early detection and response, education and outreach, and control and eradication. Many pathways can introduce invasive species, including boats, vehicles, nursery plants, aquaculture, and more. The council provides protocols for inspecting and cleaning equipment to prevent spread when working outdoors. Outreach campaigns aim to educate the public, and a reporting hotline allows people to report sightings.
The document discusses the basic structure of computers including functional units like the CPU, memory, and I/O. It describes how instructions and data are stored in memory and executed by the CPU. The CPU contains arithmetic logic units and registers to process instructions step-by-step under the control of a control unit. System software like operating systems and compilers help manage computer resources and translate programs for execution. Performance depends on hardware design, instruction sets, and software optimization.
This document provides an overview of Undertow, an embeddable web server for Java applications. It discusses Undertow's lightweight and high performance architecture based on small reusable handlers. Key features mentioned include support for Servlet 3.1, web sockets, and acting as a reverse proxy. The document also briefly outlines Undertow's handler-based approach and some built-in handlers like path matching, virtual hosts, and error handling.
Stack and Queue data structures are described. A Stack follows LIFO (last-in, first-out) where elements can only be inserted and removed from one end. Common stack operations are push, pop, and peek. A Queue follows FIFO (first-in, first-out) where elements can only be inserted at the rear and removed from the front. Common queue operations are enqueue and dequeue. Both can be implemented using arrays or linked lists. A circular array implementation improves the efficiency of dequeuing from a queue.
Stacks are data structures that follow LIFO (last in, first out) ordering. Elements can only be added to or removed from one end, called the top. Stacks are used to maintain information between main programs and subroutines. Elements are pushed onto the stack by decrementing the stack pointer and storing the element, and popped off by incrementing the stack pointer after retrieving the element. Operations must check that the stack is not empty before popping or full before pushing to prevent errors.
Computer Organization and Assembly Languagefasihuddin90
This document provides an introduction to the CS-401 course on computer architecture and assembly language programming. It outlines the basic components of a computer, including the processor, memory, and buses that connect them, and describes how data is stored and addressed in memory at the basic level of binary digits.
This document discusses computer instruction and addressing modes. It covers basic instruction types like data transfers, arithmetic/logical operations, program control, and I/O transfers. It also describes common addressing modes like register, immediate, indirect, indexed, relative, auto-increment and auto-decrement that allow flexible access to operands in memory and registers. Instruction execution involves fetching and executing instructions sequentially based on the program counter until a branch instruction redirects execution.
The document discusses various aspects of input and output devices and their interface with the central processing unit of a computer system. It describes how peripherals like keyboards, displays and printers are connected and controlled. It explains the different modes of data transfer between CPU and peripherals, including programmed I/O, interrupt-initiated I/O, and direct memory access. The document also covers topics like asynchronous and synchronous data transmission, handshaking, and hardware priority interrupts.
This document discusses computer organization and architecture. It defines computer organization as the components that computers are built from, while computer architecture is the design of how those components are integrated. The document then covers the evolution of computers through multiple generations from vacuum tubes to integrated circuits. It describes different types of computers based on factors like speed, cost and application. Finally, it outlines the basic functional units of a computer including the central processing unit, memory, input/output and how they interconnect and allow data processing, storage and movement to occur.
Computer Architecture – An IntroductionDilum Bandara
Overview on high-level design of internal components of a computer. Cover step-by-step execution of a program through ALU while accessing & updating registers
The document discusses various methods for input/output (IO) in computer systems, including IO interfaces, programmed IO, interrupt-initiated IO, direct memory access (DMA), and input-output processors (IOPs). It describes how each method facilitates the transfer of data between the CPU, memory, and external IO devices.
The presentation given at MSBTE sponsored content updating program on 'PC Maintenance and Troubleshooting' for Diploma Engineering teachers of Maharashtra. Venue: Government Polytechnic, Nashik Date: 17/01/2011 Session-2: Computer Organization and Architecture.
The document discusses loaders, which are system software programs that perform the loading function of placing a program into memory for execution. There are several types of loaders: compile-and-go loaders directly place assembled code into memory; absolute loaders place code at specified addresses; relocating loaders allow code to be loaded at different addresses and combine programs. Relocating loaders output object code, symbol tables, and relocation information to perform allocation, relocation, linking, and loading separately from assembly. Direct-linking loaders provide more flexibility by allowing multiple program and data segments with intersegment references.
This document outlines the basics of assembly language, including basic elements, statements, program data, variables, constants, instructions, translation to assembly language, and program structure. It discusses statement syntax, valid names, operation and operand fields. It also covers common instructions like MOV, ADD, SUB, INC, DEC, and NEG. Finally, it discusses program segments, memory models, and how to define the data, stack, and code segments.
The document discusses binary number systems and binary arithmetic. It begins by explaining that binary uses only two digits, 0 and 1, with a base or radix of 2. Each digit has a value depending on its position in the number. The document then provides reasons why binary is used in computers, such as being digital and using simple on/off circuits. It proceeds to explain the rules and processes for binary addition, subtraction, and provides examples of carrying and borrowing in binary arithmetic.
Here are the answers to the assignment questions:
1. No overflow occurs when adding 00100110 + 01011010 in two's complement. The sum is 10001000.
2. See textbook 1 problem 2-1.c for the solution.
3. See textbook 1 problem 2-11.c for the solution.
4. See textbook 1 problem 2-19.c for the solution.
5. The decimal equivalent of the hexadecimal number 1A16 is 2610.
The document discusses various number systems including decimal, binary, and signed binary numbers. It provides the following key points:
1) Decimal numbers use ten digits from 0-9 while binary only uses two digits, 0 and 1. Binary numbers represent values through place values determined by powers of two.
2) Conversions can be done between decimal and binary numbers through either summing the place value weights or repeated division/multiplication by two.
3) Binary arithmetic follows simple rules to add, subtract, multiply and divide numbers in binary representation.
4) Signed binary numbers use a sign bit to indicate positive or negative values, with the most common 2's complement form representing negative numbers as the 2's
This document discusses number systems and binary arithmetic. It covers decimal, binary, octal and hexadecimal number systems. For binary, it explains how to convert between decimal and binary, and discusses binary addition, subtraction, and complement representations. The key advantages of using two's complement for binary numbers are that addition and subtraction can both be performed using the same hardware circuitry.
The document provides information about computer arithmetic and binary number representation. It discusses addition and subtraction in binary, signed and unsigned numbers, overflow, and multiplication algorithms. It explains how binary addition and subtraction work using bit-by-bit operations. For multiplication, it describes the shift-add algorithm where the multiplicand is shifted and added to the product based on the multiplier bits. Hardware for implementing this algorithm with registers is also shown.
The document provides information about computer arithmetic and binary number representation. It discusses addition and subtraction in binary, signed and unsigned numbers, overflow, and multiplication algorithms. It explains how binary addition and subtraction work using bit-by-bit operations. For multiplication, it describes the shift-add algorithm where the multiplicand is shifted and added to the product based on the multiplier bits. Hardware for implementing this algorithm with registers is also shown.
The document discusses various methods for representing signed integers in binary, including signed magnitude, 1's complement, 2's complement, and excess binary. It provides examples of adding, subtracting, and multiplying numbers in binary using these different representations. 2's complement is described as the most common method used today due to its simplicity. The key aspects of 2's complement include representing negative numbers by flipping all bits and adding 1, and performing subtraction by adding the 2's complement. Overflow conditions for addition are also explained.
The document discusses binary number representation and arithmetic. It explains decimal to binary conversion. It also describes signed number representation using sign-magnitude and one's complement and two's complement methods. The key advantages of two's complement are that addition can be performed using the same method for positive and negative numbers. Subtraction using two's complement is performed by adding the number to the complement of the subtrahend. Examples of binary addition and subtraction are provided to illustrate these concepts.
The document discusses binary number systems and conversions between binary, decimal, hexadecimal, and octal numbers. It explains binary operations like AND, OR, XOR, and provides truth tables for different logic gate combinations. The next topics will be Boolean logic and software basics like the differences between system and application software.
UNIT-II ARITHMETIC FOR COMPUTERS
Addition and Subtraction – Multiplication – Division – Floating Point Representation – Floating Point Addition and Subtraction.
The document discusses different number systems including binary, decimal, and hexadecimal. It defines base-N number systems and provides examples of decimal, binary, and hexadecimal numbers. Key concepts covered include positional notation, bits and bytes, addition and subtraction in different bases, signed numbers represented using sign-magnitude and two's complement, and arithmetic operations like addition and subtraction on signed binary numbers. Sign extension is introduced as an important concept for performing arithmetic on numbers of different bit-widths in a signed system.
The document discusses different number systems including binary, decimal, and hexadecimal. It defines base-N number systems and provides examples of decimal, binary, and hexadecimal numbers. Key concepts covered include positional notation, bits and bytes, addition and subtraction in different bases, signed numbers represented using sign-magnitude and two's complement, and arithmetic operations like addition and subtraction on signed binary numbers. Sign extension is introduced as an important concept for performing arithmetic on numbers of different bit-widths in a signed system.
Reviewing number systems involves understanding various ways in which numbers can be represented and manipulated. Here's a brief overview of different number systems:
Decimal System (Base-10):
This is the most common number system used by humans.
It uses 10 digits (0-9) to represent numbers.
Each digit's position represents a power of 10.
For example, the number 245 in decimal represents (2 * 10^2) + (4 * 10^1) + (5 * 10^0).
Binary System (Base-2):
Used internally by almost all modern computers.
It uses only two digits: 0 and 1.
Each digit's position represents a power of 2.
For example, the binary number 1011 represents (1 * 2^3) + (0 * 2^2) + (1 * 2^1) + (1 * 2^0) in decimal, which equals 11.
Octal System (Base-8):
Less commonly used, but still relevant in some computer programming contexts.
It uses eight digits: 0 to 7.
Each digit's position represents a power of 8.
For example, the octal number 34 represents (3 * 8^1) + (4 * 8^0) in decimal, which equals 28.
Hexadecimal System (Base-16):
Widely used in computer science and programming.
It uses sixteen digits: 0 to 9 followed by A to F (representing 10 to 15).
Each digit's position represents a power of 16.
Often used to represent memory addresses and binary data more compactly.
For example, the hexadecimal number 2F represents (2 * 16^1) + (15 * 16^0) in decimal, which equals 47.
Each number system has its own advantages and applications. Decimal is intuitive for human comprehension, binary is fundamental in computing due to its simplicity for electronic systems, octal and hexadecimal are often used for human-readable representations of binary data in programming, particularly when dealing with memory addresses and byte-oriented data.
Understanding these number systems is essential for various fields such as computer science, electrical engineering, and mathematics, as they provide different perspectives on how numbers can be represented and manipulated.
The document discusses different number systems including binary, decimal, and hexadecimal. It defines base-N number systems and provides examples of decimal, binary, and hexadecimal numbers. Key concepts covered include positional notation, bits and bytes, addition and subtraction in different bases, signed numbers represented using sign-magnitude and two's complement, and arithmetic operations like addition and subtraction on signed binary numbers. Sign extension is introduced as an important concept for performing arithmetic on numbers of different bit-widths in a signed system.
The document discusses different number systems including binary, decimal, and hexadecimal. It defines base-N number systems and provides examples of decimal, binary, and hexadecimal numbers. Key concepts covered include positional notation, bits and bytes, addition and subtraction in different bases, signed numbers represented using sign-magnitude and two's complement, and arithmetic operations like addition and subtraction on signed binary numbers. Sign extension is introduced as an important concept for performing arithmetic on numbers of different bit-widths in a signed system.
The document discusses various techniques for accelerating the multiplication process, including shift-and-add, Booth's recoding, and higher radix multipliers. Booth's recoding maps digit sets to [-1,1] to skip additions when partial products are zero. Modified Booth's recoding improves on this by considering three adjacent bits to encode multipliers into [-2,2], allowing the use of radix-4 grouping to reduce the number of partial product additions. Modern multipliers apply Modified Booth's Recoding to take advantage of its higher radix structure.
The document discusses different number systems including binary, decimal, and hexadecimal. It defines base-N number systems and provides examples of decimal, binary, and hexadecimal numbers. Key concepts covered include positional notation, bits and bytes, addition and subtraction in different bases, signed numbers represented using sign-magnitude and two's complement, and arithmetic operations like addition and subtraction on signed binary numbers. Sign extension is introduced as an important concept for performing arithmetic on numbers of different bit-widths in a signed system.
The document provides an exam schedule for the week of July 19-24 listing the courses being tested each day. On Thursday, July 19 exams are scheduled for Computer Fundamentals and Physics lab. Friday has exams for English and Calculus. Monday's exam is for Humanities. Tuesday's exams are for PE and Sociology/Anthropology.
The document discusses different number systems including binary, decimal, and hexadecimal. It explains that binary uses two digits (0,1), decimal uses ten digits (0-9), and hexadecimal uses sixteen digits (0-9 plus A-F). All of these systems are positional number systems where the value of each digit depends on its place value. The document then discusses binary addition and subtraction, two's complement representation for signed numbers, hexadecimal addition, and concepts like nibbles and bytes.
This presentation includes basic of PCOS their pathology and treatment and also Ayurveda correlation of PCOS and Ayurvedic line of treatment mentioned in classics.
हिंदी वर्णमाला पीपीटी, hindi alphabet PPT presentation, hindi varnamala PPT, Hindi Varnamala pdf, हिंदी स्वर, हिंदी व्यंजन, sikhiye hindi varnmala, dr. mulla adam ali, hindi language and literature, hindi alphabet with drawing, hindi alphabet pdf, hindi varnamala for childrens, hindi language, hindi varnamala practice for kids, https://www.drmullaadamali.com
Physiology and chemistry of skin and pigmentation, hairs, scalp, lips and nail, Cleansing cream, Lotions, Face powders, Face packs, Lipsticks, Bath products, soaps and baby product,
Preparation and standardization of the following : Tonic, Bleaches, Dentifrices and Mouth washes & Tooth Pastes, Cosmetics for Nails.
Thinking of getting a dog? Be aware that breeds like Pit Bulls, Rottweilers, and German Shepherds can be loyal and dangerous. Proper training and socialization are crucial to preventing aggressive behaviors. Ensure safety by understanding their needs and always supervising interactions. Stay safe, and enjoy your furry friends!
Assessment and Planning in Educational technology.pptxKavitha Krishnan
In an education system, it is understood that assessment is only for the students, but on the other hand, the Assessment of teachers is also an important aspect of the education system that ensures teachers are providing high-quality instruction to students. The assessment process can be used to provide feedback and support for professional development, to inform decisions about teacher retention or promotion, or to evaluate teacher effectiveness for accountability purposes.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
Strategies for Effective Upskilling is a presentation by Chinwendu Peace in a Your Skill Boost Masterclass organisation by the Excellence Foundation for South Sudan on 08th and 09th June 2024 from 1 PM to 3 PM on each day.
Executive Directors Chat Leveraging AI for Diversity, Equity, and InclusionTechSoup
Let’s explore the intersection of technology and equity in the final session of our DEI series. Discover how AI tools, like ChatGPT, can be used to support and enhance your nonprofit's DEI initiatives. Participants will gain insights into practical AI applications and get tips for leveraging technology to advance their DEI goals.
A workshop hosted by the South African Journal of Science aimed at postgraduate students and early career researchers with little or no experience in writing and publishing journal articles.
2. Objectives
Machine instructions and program execution,
including branching and subroutine call and return
operations.
Number representation and addition/subtraction in
the 2’s-complement system.
Addressing methods for accessing register and
memory operands.
Assembly language for representing machine
instructions, data, and programs.
Program-controlled Input/Output operations.
Operations on stack, queue, list, linked-list, and
array data structures.
4. Unsigned Integer
Consider a n-bit vector of the form:
A = an −1an − 2 an − 3 a0
where ai=0 or 1 for i in [0, n-1].
This vector can represent positive integer values V =
A in the range 0 to 2n-1, where
n −1 n−2
A=2 an −1 + 2 an − 2 + + 2 a1 + 2 a0
1 0
5. Signed Integer
3 major representations:
Sign and magnitude
One’s complement
Two’s complement
Assumptions:
4-bit machine word
16 different values can be represented
Roughly half are positive, half are negative
6. Sign and Magnitude
Representation
-7 +0
-6 1111 0000 +1
1110 0001
-5 +2 +
1101 0010
-4 1100 0011 +3 0 100 = + 4
-3 1011 0100 +4 1 100 = - 4
1010 0101
-2 +5 -
1001 0110
-1 1000 0111 +6
-0 +7
High order bit is sign: 0 = positive (or zero), 1 = negative
Three low order bits is the magnitude: 0 (000) thru 7 (111)
Number range for n bits = +/-2n-1 -1
Two representations for 0
7. One’s Complement
Representation
-0 +0
-1 1111 0000 +1
1110 0001
-2 +2 +
1101 0010
-3 1100 0011 +3 0 100 = + 4
-4 1011 0100 +4 1 011 = - 4
1010 0101
-5 +5 -
1001 0110
-6 1000 0111 +6
-7 +7
Subtraction implemented by addition & 1's complement
Still two representations of 0! This causes some problems
Some complexities in addition
8. Two’s Complement
Representation
-1 +0
-2 1111 0000 +1
1110 0001
-3 +2 +
1101 0010
like 1's comp
except shifted -4 1100 0011 +3 0 100 = + 4
one position
clockwise -5 1011 0100 +4 1 100 = - 4
1010 0101
-6 +5 -
1001 0110
-7 1000 0111 +6
-8 +7
Only one representation for 0
One more negative number than positive
number
12. Addition and Subtraction – Sign
Magnitude
4 0100 -4 1100
result sign bit is the
same as the operands' +3 0011 + (-3) 1011
sign
7 0111 -7 1001
when signs differ, 4 0100 -4 1100
operation is subtract,
sign of result depends -3 1011 +3 0011
on sign of number with
the larger magnitude 1 0001 -1 1111 `
13. Addition and Subtraction – 1’s
Complement
4 0100 -4 1011
+3 0011 + (-3) 1100
7 0111 -7 10111
End around carry 1
1000
4 0100 -4 1011
-3 1100 +3 0011
1 10000 -1 1110
End around carry 1
0001
14. Addition and Subtraction – 1’s
Complement
Why does end-around carry work?
n
Its equivalent to subtracting 2 and adding 1
n n
M - N = M + N = M + (2 - 1 - N) = (M - N) + 2 - 1 (M > N)
n n
-M + (-N) = M + N = (2 - M - 1) + (2 - N - 1) n-1
M+N<2
n n
= 2 + [2 - 1 - (M + N)] - 1
after end around carry:
n
= 2 - 1 - (M + N)
this is the correct form for representing -(M + N) in 1's comp!
15. Addition and Subtraction – 2’s
Complement
4 0100 -4 1100
+3 0011 + (-3) 1101
If carry-in to the high
order bit = 7 0111 -7 11001
carry-out then ignore
carry
if carry-in differs from 4 0100 -4 1100
carry-out then overflow
-3 1101 +3 0011
1 10001 -1 1111
Simpler addition scheme makes twos complement the most common
choice for integer number systems within digital systems
16. Addition and Subtraction – 2’s
Complement
Why can the carry-out be ignored?
-M + N when N > M:
n n
M* + N = (2 - M) + N = 2 + (N - M)
n
Ignoring carry-out is just like subtracting 2
-M + -N where N + M < = 2n-1
n n
-M + (-N) = M* + N* = (2 - M) + (2 - N)
n n
= 2 - (M + N) + 2
After ignoring the carry, this is just the right two’s complement
representation for -(M + N)!
18. Overflow - Add two positive numbers to get a
negative number or two negative numbers to
get a positive number
-1 +0 -1 +0
-2 1111 0000 +1 -2 1111 0000 +1
1110 0001 1110 0001
-3 +2 -3
1101 1101 +2
0010 0010
-4 -4
1100 0011 +3 1100 0011 +3
-5 1011 -5 1011
0100 +4 0100 +4
1010 1010
-6 0101 -6 0101
1001
+5 +5
0110 1001 0110
-7 1000 0111 +6 -7 1000 +6
0111
-8 +7 -8 +7
5 + 3 = -8 -7 - 2 = +7
19. Overflow Conditions
0111 1000
5 0101 -7 1001
3 0011 -2 1100
-8 1000 7 10111
Overflow Overflow
0000 1111
5 0101 -3 1101
2 0010 -5 1011
7 0111 -8 11000
No overflow No overflow
Overflow when carry-in to the high-order bit does not equal carry out
20. Sign Extension
Task:
Given w-bit signed integer x
Convert it to w+k-bit integer with same value
Rule:
Make k copies of sign bit:
X′= x
w–1 ,…, xw–1 , xw–1 , xw–2 ,…, x0
w
X • • •
k copies of MSB
• • •
X′ • • • • • •
k w
21. Sign Extension Example
short int x = 15213;
int ix = (int) x;
short int y = -15213;
int iy = (int) y;
Decimal Hex Binary
x 15213 3B 6D 00111011 01101101
ix 15213 00 00 C4 92 00000000 00000000 00111011 01101101
y -15213 C4 93 11000100 10010011
iy -15213 FF FF C4 93 11111111 11111111 11000100 10010011
23. Memory Location, Addresses,
and Operation
n bits
first word
Memory consists
second word
of many millions of
storage cells,
•
each of which can •
•
store 1 bit.
Data is usually i th word
accessed in n-bit
groups. n is called •
word length. •
•
last word
Figure 2.5. Memory words.
24. Memory Location, Addresses,
and Operation
32-bit word length example
32 bits
b 31 b 30 b1 b0
•
•
•
Sign bit: b 31= 0 for positive numbers
b 31= 1 for negative numbers
(a) A signed integer
8 bits 8 bits 8 bits 8 bits
ASCII ASCII ASCII ASCII
character character character character
(b) Four characters
25. Memory Location, Addresses,
and Operation
To retrieve information from memory, either for one
word or one byte (8-bit), addresses for each location
are needed.
A k-bit address memory has 2k memory locations,
namely 0 – 2k-1, called memory space.
24-bit memory: 224 = 16,777,216 = 16M (1M=220)
32-bit memory: 232 = 4G (1G=230)
1K=210
1T=240
26. Memory Location, Addresses,
and Operation
Itis impractical to assign distinct addresses
to individual bit locations in the memory.
The most practical assignment is to have
successive addresses refer to successive
byte locations in the memory – byte-
addressable memory.
Byte locations have addresses 0, 1, 2, … If
word length is 32 bits, they successive words
are located at addresses 0, 4, 8,…
27. Big-Endian and Little-Endian
Assignments
Word
address Byte address Byte address
0 0 1 2 3 0 3 2 1 0
4 4 5 6 7 4 7 6 5 4
• •
• •
• •
k k k k k k k k k k
2 -4 2 -4 2 -3 2- 2 2 - 1 2 - 4 2- 1 2 - 2 2 -3 2 -4
(a) Big-endian assignment (b) Little-endian assignment
Figure 2.7. Byte and word addressing.
28. Memory Location, Addresses,
and Operation
Address ordering of bytes
Word alignment
Access numbers, characters, and character
strings
29. Memory Operation
Load (or Read or Fetch)
Copy the content. The memory content doesn’t change.
Address – Load
Registers can be used
Store (or Write)
Overwrite the content in memory
Address and Data – Store
Registers can be used
31. “Must-Perform” Operations
Data transfers between the memory and the
processor registers
Arithmetic and logic operations on data
Program sequencing and control
I/O transfers
32. Register Transfer Notation
Identifya location by a symbolic name
standing for its hardware binary address
(LOC, R0,…)
Contents of a location are denoted by placing
square brackets around the name of the
location (R1←[LOC], R3 ←[R1]+[R2])
Register Transfer Notation (RTN)
34. Basic Instruction Types
High-levellanguage: C = A + B
Action: C ← [A] + [B]
Assembly: Add A, B, C
Three-address instruction:
Operation Source1, Source2, Destination
Two-address instruction:
Operation Source, Destination
Add A, B = B ←[A] + [B]
35. Basic Instruction Types
Need to add something to the above two-address
instruction to finish:
Move B, C = C ← [B]
One-address instruction (to fit in one word length)
Accumulator: Add A
Load A
Add B
Store C
Zero-address instructions (stack operation)
36. Using Registers
Registers are faster
The number of registers is smaller
Shorter instructions
Potential speedup
Minimize the frequency with which data is
moved back and forth between the memory
and processor registers.
37. Using Registers
Load A, Ri
Store Ri, A
Add A, Ri
Add Ri, Rj
Add Ri, Rj, Rk
Move Source, Destination
Move A, R = Load A, R
i i
Move Ri, A = Store Ri, A
38. Using Registers
In the processors where arithmetic operations are
allowed only on operands in register
Move A, Ri
Move B, Rj
Add Ri, Rj
Move Rj, C
In the processors where one operand may be in the
memory but the other one must be in registers
Move A, Ri
Add B, Ri
Move Ri, C
39. Instruction Execution and
Straight-Line Sequencing
Address Contents
i
Assumptions:
Begin execution here Move A,R0
i +4
3-instruction
program
- One memory operand
Add B,R0
segment per instruction
i +8 Move R0,C
- 32-bit word length
- Memory is byte
addressable
A - Full memory address
can be directly specified
in a single-word instruction
B Data for
the program
Two-phase procedure
C
Figure 2.8. A program for C ← [Α] + [Β].
40. i Move NUM1,R0
i+4 Add NUM2,R0
Branching i+8 Add NUM3,R0
•
•
•
i + 4n - 4 Add NUMn,R0
i + 4n Move R0,SUM
•
•
•
SUM
NUM1
NUM2
•
•
•
NUMn
Figure 2.9. A straight-line program for adding n numbers.
41. Move N,R1
Clear R0
Branching LOOP
Determine address of
"Next" number and add
Program "Next" number to R0
loop
Decrement R1
Branch>0 LOOP
Branch target
Move R0,SUM
Conditional branch
•
•
•
SUM
N n
NUM1
Figure 2.10. Using a loop to add n numbers. NUM2
•
•
•
NUMn
42. Condition Codes
Condition code flags
Condition code register / status register
N (negative)
Z (zero)
V (overflow)
C (carry)
Different instructions affect different flags
43. Generating Memory Addresses
How to specify the address of branch target?
Can we give the memory operand address
directly in a single Add instruction in the
loop?
Use a register to hold the address of NUM1;
then increment by 4 on each pass through
the loop.
45. Stacks
A list of data elements, usually words or
bytes, with the accessing restriction that
elements can be added or removed at one
end of the list only.
Top / Bottom / Pushdown Stack
Last-In-First-Out (LIFO)
Push / Pop
46. Stacks
0
Stack •
pointer •
register •
Current
SP - 28 top element
17
739
Stack
•
•
•
Bottom
BOTTOM 43 element
•
•
•
k
2 - 1
Figure 2.21. A stack of words in the memory.
48. Stacks
SP 19
- 28 - 28
17 SP 17
739 739
Stack
• •
• •
• •
43 43
NEWITEM 19 ITEM - 28
(a) After push from NEWITEM (b) After pop into ITEM
Figure 2.22. Effect of stack operations on the stack in Figure 2.21.
49. Stacks
The size of stack in a program is fixed in
memory.
Need to avoid pushing if the maximum size is
reached
Need to avoid popping if stack is empty
Compare instruction
Compare src, dst
[dst] – [src]
Will not change the values of src and dst.
50. Stacks
SAFEPOP Compare #2000,SP Chec to seeif the stac pointer contains
k k
Branc 0
h> EMPTYERR OR an addressvaluegreaterthan 2000. If it
does,the stac is empt . Branc to the
k y h
routine EMPTYERROR for appropriate
action.
Move (SP)+,ITEM Otherwise,pop the top of the stac into
k
memory location ITEM.
(a) Routine for a safe pop operation
SAFEPUSH Compare #1500,SP Chec to seeif the stac pointer
k k
Branc ≤ 0
h FULLERR OR contains an addressvalueequal
to or less than 1500. If it does, the
stac is full. Branc to the routine
k h
FULLERR OR for appropriate action.
Move NEWITEM, – (SP) Otherwise,push the elemen in memory
t
location NEWITEM onto the stac k.
(b) Routine for a safe push operation
Figure 2.23. Checking for empty and full errors in pop and push operations.
51. Queues
Data are stored in and retrieved from a queue
on a First-In-First-Out (FIFO) basis.
New data are added at the back (high-
address end) and retrieved from the front
(low-address end).
How many pointers are needed for stack and
queue, respectively?
Circular buffer
53. Subroutines
It is often necessary to perform a particular subtask
(subroutine) many times on different data values.
To save space, only one copy of the instructions
that constitute the subroutine is placed in the
memory.
Any program that requires the use of the subroutine
simply branches to its starting location (Call).
After a subroutine has been executed, it is said to
return to the program that called the subroutine, and
the program resumes execution. (Return)
54. Subroutines
Since the subroutine may be called from different
places in a calling program, provision must be made
for returning to the appropriate location.
Subroutine Linkage method: use link register to
store the PC.
Call instruction
Store the contents of the PC in the link register
Branch to the target address specified by the instruction
Return instruction
Branch to the address contained in the link register
55. Subroutines
Memory Memory
location Calling program location Subroutine SUB
200 Call SUB 1000 first instruction
204 next instruction
Return
1000
PC 204
Link 204
Call Return
Figure 2.24. Subroutine linkage using a link register.
56. Subroutine Nesting and The
Processor Stack
If a subroutine calls another subroutine, the
contents in the link register will be destroyed.
If subroutine A calls B, B calls C, after C has
been executed, the PC should return to B,
then A
LIFO – Stack
Automatic process by the Call instruction
Processor stack
57. Parameter Passing
Exchange of information between a calling
program and a subroutine.
Several ways:
Through registers
Through memory locations
Through stack
58. Passing Parameters through
Processor Registers
Calling program
Move N,R1 R1 servesas a coun ter.
Move #NUM1,R2 R2 pointsto thelist.
Call LISTADD Call subroutine.
Move R0,SUM Sa result.
ve
.
.
.
Subroutine
LISTADD Clear R0 Initialize sumto 0.
LOOP Add (R2)+,R0 Add entry from list.
Decremen t R1
Branc >0
h LOOP
Return Return to calling program.
Figure 2.25. Program of Figure 2.16 written as a subroutine; parameters passed through registers.
59. Passing Parameters through
Stack
Assumetop of stac is atlevel 1 below.
k
- Passing by reference
Move #NUM1, – (SP) Pushparameters
onto stac
k.
- Passing by value
Move N, – (SP)
Call LISTADD Call subroutine
(top of stac at level 2).
k
Move 4(SP),SUM Sa result.
ve
Add #8,SP Restoretop of stack
(top of stac at level 1).
k
Level 3 → [R2]
.
.
. [R1]
[R0]
LISTADD MoveMultiple R0– R2,– (SP) Sa registers
ve
(top of stac at level 3).
k Level 2 → Return address
Move 16(SP),R1 Initialize coun to n.
ter n
Move 20(SP),R2 Initialize pointer to the list.
Clear R0 Initialize sum to 0. NUM1
LOOP Add (R2)+,R0 Add entry from list. Level 1 →
Decremen t R1
Branch>0 LOOP
Move R0,20(SP) Put result on the stac
k.
MoveMultiple (SP)+,R0 R2
– Restoreregisters. (b) Top of stack at various times
Return Return to calling program.
(a) Calling program and subroutine Figure 2.26. Program of Figure 2.16 written as a subroutine; parameters passed on the stack.
60. The Stack Frame
Some stack locations constitute a private
work space for a subroutine, created at the
time the subroutine is entered and freed up
when the subroutine returns control to the
calling program. Such space is called a stack
frame.
Frame pointer (FP)
Index addressing to access data inside frame
-4(FP), 8(FP), …
61. The Stack Frame
SP saved [R1]
(stack pointer)
saved [R0]
localvar3
localvar2
localvar1 Stack
frame
FP for
(frame pointer) saved [FP]
called
Return address subroutine
param1
param2
param3
param4
Old TOS
(top-of-stack)
Figure 2.27. A subroutine stack frame example.
62. SP and FP
Move FP, -(SP)
Move SP, FP
Subtract #12, SP
Push R0 and R1
…
Pop R0 and R1
Add #12, SP
Pop FP
Return
63. Stack Frames for Nested
Subroutines
Memory
location Instructions Commen
ts
Main program
.
.
.
2000 Move PARAM2, – (SP) Placeparameters stack.
on
2004 Move PARAM1, – (SP)
2008 Call SUB1
2012 Move (SP),RESULT Store result.
2016 Add #8,SP Restorestack level.
2020 next instruction
.
.
.
First subroutine
2100 SUB1 Move FP, – (SP) Sa frame pointer register.
ve
2104 Move SP,FP Load the frame pointer.
2108 MoveMultiple R0– R3,– (SP) Sa registers.
ve
2112 Move 8(FP),R0 Get first parameter.
Move 12(FP),R1 Get secondparameter.
.
.
.
Move PARAM3, – (SP) Placea parameter n stack.
o
2160 Call SUB2
2164 Move (SP)+,R2 Pop SUB2 result into R2.
.
.
.
Move R3,8(FP) Placeansw on stack.
er
MoveMultiple (SP)+,R0– R3 Restoreregisters.
Move (SP)+,FP Restoreframe pointer register.
Return Return to Main program.
Second subroutine
3000 SUB2 Move FP, – (SP) Sa frame pointer register.
ve
Move SP,FP Load the frame pointer.
MoveMultiple R0– R1,– (SP) Sa registers R0 and R1.
ve
Move 8(FP),R0 Get the parameter.
.
.
.
Move R1,8(FP) Place SUB2 result on stack.
MoveMultiple (SP)+,R0– R1 Restoreregisters R0 and R1.
Move (SP)+,FP Restoreframe pointer register.
Return Return to Subroutine 1.
Figure 2.28. Nested subroutines.
64. Stack Frames for Nested
Subroutines
[R1] from SUB1
[R0] from SUB1 Stack
frame
FP [FP] from SUB1 for
second
2164 subroutine
param3
[R3] from Main
[R2] from Main
[R1] from Main
Stack
[R0] from Main frame
for
FP [FP] from Main first
subroutine
2012
param1
param2
Old TOS
Figure 2.29. Stack frames for Figure 2.28.
66. Logic Instructions
AND
OR
NOT (what’s the purpose of the following)
Not R0
Add #1, R0
Determine if the leftmost character of the four ASCII
characters stored in the 32-bit register R0 is Z
(01011010)
And #$FF000000, R0
Compare #$5A000000, R0
Branch=0 YES
68. Logical Shifts
Two decimal digits represented in ASCII code are
located at LOC and LOC+1. Pack these two digits in
a single byte location PACKED.
Move #LOC,R0 R0 points to data.
MoveByte (R0)+,R1 Load first byte into R1.
LShiftL #4,R1 Shift left by 4 bit positions.
MoveByte (R0),R2 Load secondbyte into R2.
And #$F,R2 Eliminate high-order bits.
Or R1,R2 ConcatenateheBCD digits.
t
MoveByte R2,PACKED Store the result.
Figure 2.31. A routine that packs two BCD digits.
70. C R0
before: 0 1 1 1 0 . . . 0 1 1
Rotate
0
after: 1 1 1 0 . . . 0 1 1 0 1
(a) Rotate left without carr
y RotateL #2,R0
C R0
before: 0 0 1 1 1 0 . . . 0 1 1
after: 1 1 1 0 . . . 0 1 1 0 0
(b) Rotate left with carr
y RotateLC #2,R0
R0 C
before: 0 1 1 1 0 . . . 0 1 1 0
after: 1 1 0 1 1 1 0 . . . 0 1
(c) Rotate ight without carr
r y RotateR #2,R0
R0 C
before: 0 1 1 1 0 . . . 0 1 1 0
after: 1 0 0 1 1 1 0 . . . 0 1
(d) Rotate ir with carr
ght y RotateRC #2,R0
Figure 2.32. Rotate instructions.
71. Multiplication and Division
Not very popular (especially division)
Multiply R , R
i j
Rj ← [Ri] х [Rj]
Any problem?
Divide R , R
i j
Rj ← [Ri] / [Rj]
73. Vector Dot Product Program
n −1
Dot Product = ∑ A(i ) × B (i )
i =0
Move #AVEC,R1 R1 points to vector A.
Move #BVEC,R2 R2 points to vector B.
Move N,R3 R3 serv as a coun
es ter.
Clear R0 R0 accum ulates the dot product.
LOOP Move (R1)+,R4 Computethe productof
Multiply (R2)+,R4 nextcomponen ts.
Add R4,R0 Add to previoussum.
Decrement R3 Decrement thecounter.
Branch > 0 LOOP Loop again if not done.
Move R0,DOTPR OD Storedot product in memory.
Figure 2.33. A program for computing the dot product of two vectors.
74. Byte-Sorting Program
Sort a list of bytes stored in memory into
ascending alphabetic order.
The list consists of n bytes, not necessarily
distinct, stored from memory location LIST to
LIST+n-1. Each byte contains the ASCII code
for a character from A to Z. The first bit is 0.
Straight-selection algorithm (compare and
swap)
75. Byte-Sorting Program
for (j = n – 1; j > 0; j = j – 1)
{ for ( k = j – 1; k > = 0; k = k – 1 )
{ if (LIST[k] > LIST[ j])
{ TEMP = LIST[k];
LIST[k] = LIST[ j ];
LIST[ j] = TEMP;
}
}
}
(a) C-language program for sorting
Move #LIST,R0 Load LIST into baseregister R0.
Move N,R1 Initialize outer loop index
Subtract #1,R1 register R1 to j = n – 1.
OUTER Move R1,R2 Initialize inner loop index
Subtract #1,R1 register R2 to k = j – 1.
MoveByte (R0,R1),R3 Load LIST( j ) into R3, which holds
current maximum in sublist.
INNER CompareByte R3,(R0,R2) If LIST( k) ≤ [R3],
Branc ≤ 0
h NEXT do not exhange.
MoveByte (R0,R2),R4 Otherwise,exchange LIST(k)
MoveByte R3,(R0,R2) with LIST(j ) and load
MoveByte R4,(R0,R1) new maximum into R3.
MoveByte R4,R3 RegisterR4 serv esas TEMP.
NEXT Decremen t R2 Decremen index registersR2 and
t
Branc ≥ 0
h INNER R1, which alsoserv e
Decremen t R1 as loop counters, and branc h
Branc 0
h> OUTER back if loopsnot finished.
(b) Assembly language program for sorting
76. Byte-Sorting Program
The list must have at least two elements
because the check for loop termination is
done at the end of each loop.
If the machine instruction set allows a move
operation from one memory location directly
to another memory location:
MoveByte (R0, R2), (R0, R1)
MoveByte R3, (R0, R2)
MoveByte (R0, R1), R3
77. Linked List
Many nonnumeric application programs
require that an ordered list of information
items be represented and stored in memory
in such a way that it is easy to add items to
the list or to delete items from the list at ANY
position while maintaining the desired order
of items.
Different from Stacks or Queues.
78. Problem Illustration
N n
Maintain this list of Student ID
LIST
records in consecutive
memory locations in LIST + 4 Test 1
some contiguous Student 1
LIST + 8 Test 2
block of memory in
increasing order of LIST + 12 Test 3
student ID numbers.
LIST + 16 Student ID
What if a student
withdraws from the Test 1
course so that an Student 2
Test 2
empty record slot is
created? Test 3
What if another
student registers in •
the course? •
•
79. Linked List
Each record still occupies a consecutive four-word block in the memory.
But successive records in the order do not necessarily occupy
consecutive blocks in the memory address space.
Each record contains an address value in a one-word link field that
specifies the location of the next record in order to enable connecting
the blocks together to form the ordered list.
Link address
Record 1 Record 2 Record k 0
Head Tail
(a) Linking structure
Record 1 Record 2
New record
(b) Inserting a new record between Record 1 and Record 2
80. List in Memory Memory Key Link Data
address field field field
(ID) (Test scores)
1 word 1 word 3 words
First
record 2320 27243 1040 Head
Head pointer
Second
record 1040 28106 1200
Third
record 1200 28370 2880
•
•
•
Second last
record 2720 40632 1280
Last
1280 47871 0 Tail
record
Figure 2.36. A list of student test scores organized as a linked list in memory.
81. Insertion of a New Record
Suppose that the INSERTION Compare #0, RHEAD
ID number of the
new record is Branch>0 HEAD new record
Move RNEWREC, RHEAD becomes a
28241, and the not empty one-entry list
Return
next available
free record block HEAD Compare (RHEAD), (RNEWREC)
is at address Branch>0 SEARCH
new record
2960. insert new record Move RHEAD, 4(RNEWREC)
becomes
somewhere after Move RNEWREC, RHEAD
What are the current head
new head
Return
possibilities of the
SEARCH Move RHEAD, RCURRENT
new record’s
Move 4(RCURRENT), RNEXT
position in the list. LOOP
Compare #0, RNEXT
Branch=0 TAIL
ne w record becomes ne tail
w Compare (RNEXT), (RNEWREC)
Branch<0 INSERT
insert new record in Move RNEXT, RCURRENT
an interior position Branch LOOP
INSERT Move RNEXT, 4(RNEWREC)
TAIL Move RNEWREC, 4(RCURRENT)
Return
82. Deletion of a Record
DELETION Compare (RHEAD), RIDNUM
Branch>0 SEARCH
Move 4(RHEAD), RHEAD
not the head record
Return
SEARCH Move RHEAD, RCURRENT
LOOP Move 4(RCURRENT), RNEXT
Compare (RNEXT), RIDNUM
Branch=0 DELETE
Move RNEXT , RCURRENT
Branch LOOP
DELETE Move 4(RNEXT), RTEMP
Move RTEMP , 4(RCURRENT)
Return
Figure 2.38. A subroutine for deleting a record from a linked list. Any problem?
84. Encoding of Machine
Instructions
Assembly language program needs to be converted into machine
instructions. (ADD = 0100 in ARM instruction set)
In the previous section, an assumption was made that all
instructions are one word in length.
Suppose 32-bit word length, 8-bit OP code (how many
instructions can we have?), 16 registers in total (how many
bits?), 3-bit addressing mode indicator.
Add R1, R2
8 7 7 10
Move 24(R0), R5
LshiftR #2, R0 OP code Source Dest Other info
Move #$3A, R1
Branch>0 LOOP (a) One-word instruction
85. Encoding of Machine
Instructions
What happens if we want to specify a memory
operand using the Absolute addressing mode?
Move R2, LOC
14-bit for LOC – insufficient
Solution – use two words
OP code Source Dest Other info
Memory address/Immediate operand
(b) Two-word instruction
86. Encoding of Machine
Instructions
Then what if an instruction in which two operands
can be specified using the Absolute addressing
mode?
Move LOC1, LOC2
Solution – use two additional words
This approach results in instructions of variable
length. Complex instructions can be implemented,
closely resembling operations in high-level
programming languages – Complex Instruction Set
Computer (CISC)
87. Encoding of Machine
Instructions
If we insist that all instructions must fit into a single
32-bit word, it is not possible to provide a 32-bit
address or a 32-bit immediate operand within the
instruction.
It is still possible to define a highly functional
instruction set, which makes extensive use of the
processor registers.
Add R1, R2 ----- yes
Add LOC, R2 ----- no
Add (R3), R2 ----- yes
88. Encoding of Machine
Instructions
How to load a 32-bit address into a register that
serves as a pointer to memory locations?
Solution #1 – direct the assembler to place the
desired address in a word location in a data area
close to the program, so that the Relative
addressing mode can be used to load the address.
Solution #2 – use logical and shift instructions to
construct the desired 32-bit address by giving it in
parts that are small enough to be specifiable using
the Immediate addressing mode.
89. Encoding of Machine
Instructions
An instruction must occupy only one word –
Reduced Instruction Set Computer (RISC)
Other restrictions
OP code Ri Rj Rk Other info
(c) Three-operand instruction