Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic.

Slides:



Advertisements
Similar presentations
NEG Instruction Change operand content into two’s complement (negative value) and stored back into its operand mov bl, b neg bl; bl = mov.
Advertisements

Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 2 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Assembly Programming Notes for Practical2 Munaf Sheikh
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Computer Organization & Assembly Language
Video systems (continue). Practice Modify the program to get a string from a keyboard to display the input string on the middle of the screen with reverse.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
Chapter 2 : Number System
Boolean Algebra and Logic Gate
CHAPTER 7 ASSEMBLY LANGUAGE INSTRUCTIONS
Chapter 3 Boolean Algebra and Logic Gate (Part 2).
Relationship Between Basic Operation of Boolean and Basic Logic Gate The basic construction of a logical circuit is gates Gate is an electronic circuit.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
6.1) Assembly Language Program Format 6.2) Features of Assembly Language 6.3) Data Definition CHAPTER 6 ASSEMBLY LANGUAGE PROGRAM FORMAT AND DATA DEFINITION.
Practical Session 2. Labels Definition valid characters in labels are: letters, numbers, _, $, ~,., and ? first character can be: letter, _, ? and.
+ CS 325: CS Hardware and Software Organization and Architecture Exam 1: Study Guide.
Lecture 18 Last Lecture Today’s Topic Instruction formats
Fundamentals of Assembly language
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
Computers Organization & Assembly Language
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
An Introduction to 8086 Microprocessor.
Summer 2014 Chapter 1: Basic Concepts. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Chapter Overview Welcome to Assembly Language.
Assembly Language for x86 Processors 7th Edition
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
Chapter 1: Basic Concepts
CSI-2111 Computer Architecture Ipage Revision  Objective : To examine basic concepts of: –2.1 Numbering Systems –2.2 Binary Numbers –2.3 Boolean.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Logic Circuits I.
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
ICS312 Set 9 Logic & Shift Instructions. Logic & Shift Instructions Logic and Shift Instructions can be used to change the bit values in an operand. The.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Chapter 4 Requirements for Coding in Assembly Language.
UHD:CS2401: A. Berrached1 The Intel x86 Hardware Organization.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
SAK Chapter 21 Chapter 2 : Number System 2.1 Decimal, Binary, Octal and Hexadecimal Numbers 2.2 Relation between binary number system with other.
Click to add Title Comunicación y Gerencia Click To add Subtitle Click to add Text Fundamentals of Assembly Language.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
Review of Assembly language. Recalling main concepts.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
Introduction Arithmetic instructions are used to perform arithmetic operation such as Addition Subtraction Multiplication Division These operations can.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
Lecture 2 Chapter 4 –Requirements for coding in Assembly Language 1.
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
Preliminary to Assembly Language Programming CE 140 A1/A2 28 June 2003.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Intel MP Organization. Registers - storage locations found inside the processor for temporary storage of data 1- Data Registers (16-bit) AX, BX, CX, DX.
I NTEL 8086 M icroprocessor بسم الله الرحمن الرحيم 1.
1 Chapter 1: Introduction Appendix A: Binary and Hexadecimal Tutorial Assembly Language for Intel-Based Computers, 3rd edition Kip R. Irvine.
Assembly language programming
Instruction set Architecture
Format of Assembly language
Data Transfers, Addressing, and Arithmetic
8086 Microprocessor.
Assembly Language Programming Part 2
INTRODUCTION ABOUT ASSEMBLY
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
Introduction to Assembly Language
BIC 10503: COMPUTER ARCHITECTURE
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
Shift & Rotate Instructions)
Symbolic Instruction and Addressing
Chapter 4 –Requirements for coding in Assembly Language
Requirements for coding in Assembly Language
Chapter 6 –Symbolic Instruction and Addressing
Chapter 8: Instruction Set 8086 CPU Architecture
Part I Data Representation and 8086 Microprocessors
Presentation transcript:

Chapter 2 Summary

Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic operation

Positive Numbers A computer represents positive integers in binary Three methods for representing negative numbers (signed numbers) are –Sign-magnitude –One’s complement –Two’s complement

Sign Magnitude Representation the number’s sign and magnitude (value) Sign -- Positive numbers  0 and negative numbers  1 e.g = 64 and = -64 Easy for human to understand but it requires some special logic for arithmetic operations (addition, subtraction)

Arithmetic Operation Computers mostly storing information, particularly integers, in byte form In this section we look how addition and subtraction are performed in computers To perform mathematical functions, a CPU contains a component called ALU (arithmetic logic unit) – to perform arithmetic operations (addition & subtraction) and logic operation (in next chapter)

One’s Complement The negative number is represented by flipping the number’s bits E.g., becomes E.g. consider  ( ) =  = (9 bits)  = (8 bits)  103 – 97 = 6 =  Try = ?? and – = ??

Ones Complement In the ones complement representation, positive numbers are same as that of sign-and-magnitude Example: +5 = (8 bit)  as in sign-and-magnitude representation Sign-and-magnitude and ones complement use the same representation above for +5 with 8 bits and all positive numbers. For negative numbers, their representation are obtained by changing bit 0 → 1 and 1 → 0 from their positive numbers

Example: Convert –5 into ones complement representation (8 bit) Solution: First, obtain +5 representation in 8 bits  Change every bit in the number from 0 to 1 and vice-versa. –5 10 in ones complement is

Exercise: Get the representation of ones complement (6 bit) for the following numbers: i)+7 10 ii) –10 10 Solution: (+7) = Solution: (+10) 10 = So, (-10) 10 =

Twos complement Similar to ones complement, its positive number is same as sign- and-magnitude Representation of its negative number is obtained by adding 1 to the ones complement of the number.

Example: Convert –5 into twos complement representation and give the answer in 8 bits. Solution: First, obtain +5 representation in 8 bits  Obtain ones complement for –5  Add 1 to the ones complement number:  = –5 in twos complement is

Exercise: Obtain representation of twos complement (6 bit) for the following numbers i)+7 10 ii)–10 10 Solution: (+7) = (same as sign-magnitude) Solution: (+10) 10 = (-10) 10 = = So, twos compliment for –10 is

Two’s Complement Makes addition and subtraction simple The fact that all numbers are stored in 2’s complement form allows the ALU to use just one circuit for all basic mathematical operations Visual Basic uses 2’s complement representations of numbers

Two’s Complement Rules –Just add all the bits –Throw away EAC (“end around carry”) –if a – b becomes a + (-b) –e.g (-1)10110(-10) (8) (-3) (7) (-13) try again – in 2’s complement

Chapter 3 Summary

Relationship Between Basic Operation of Boolean and Basic Logic Gate The basic construction of a logical circuit is gates Gate is an electronic circuit that emits an output signal as a result of a simple Boolean operation on its inputs Logical function is presented through the combination of gates The basic gates used in digital logic is the same as the basic Boolean algebra operations (e.g., AND, OR, NOT,…)

The package Truth Tables and Boolean Algebra set out the basic principles of logic. A B F A B F A B F A B F F F F F Name Graphic Symbol Boolean Algebra Truth Table ABAB ABAB ABAB ABAB A F AND OR NOT NAND NOR F = A. B Or F = AB F = A + B _____ F = A + B ____ F = A. B Or F = AB _ F = A B F the symbols, algebra signs and the truth table for the gates

1. Identity Elements 2. Inverse Elements 1. A = A A. A = A = A A + A = 1 3. Idempotent Laws 4. Boundess Laws A + A = A A + 1 = 1 A. A = A A. 0 = 0 5. Distributive Laws 6. Order Exchange Laws A. (B + C) = A.B + A.C A. B = B. A A + (B. C) = (A+B). (A+C) A + B = B + A 7. Absorption Laws 8. Associative Laws A + (A. B) = AA + (B + C) = (A + B) + C A. (A + B) = AA. (B. C) = (A. B). C 9. Elimination Laws 10. De Morgan Theorem     A + (A. B) = A + B (A + B) = A. B     A. (A + B) = A. B (A. B) = A + B Basic Theorems of Boolean Algebra

Relationship Between Boolean Function and Logic Circuit A B Q Boolean function  Q = AB + B = (NOT A AND B) OR B Logic circuit A AB B = AB + B

Relationship Between Boolean Function and Logic Circuit Any Boolean function can be implemented in electronic form as a network of gates called logic circuit A B F A.B = AB C D C + D = AB + C + D

G = A. (B + C + D) A B C D C + D B + C + D

Truth Table

A B Q A AB B = AB + B Produce a truth table from the logic circuit ABAABQ

Karnaugh Map A graphical way of depicting the content of a truth table where the adjacent expressions differ by only one variable For the purposes simplification, the Karnaugh map is a convenient way of representing a Boolean function of a small number (up to four) of variables The map is an array of 2 n squares, representing all possible combination of values of n binary variables Example: 2 variables, A and B A B B A B A B A B A

AB C D A B C D A B CD A B C D 4 variables, A, B, C, D  2 4 = 16 squares

AB C C C ABC C List combinations in the order 00, 01, 11, 10 C

ABCF Truth Table Karnaugh Map BC A 0 1 A A How to create Karnaugh Map 1.Place 1 in the corresponding square

AB F = AB + AB A B Karnaugh Maps to Represent Boolean Functions

2.Group the adjacent squares: Begin grouping square with 2 n-1 for n variables e.g. 3 variables, A, B, and C = 2 2 = 4 = 2 1 = 2 = 2 0 = BC A 0 1 A A AB BC ABC F = BCABABC + +

BC A 0 1 A A 3 variables: = 2 2 = = 2 1 = = 2 0 = 1 A BC F = A + BC

AB CD variables, A, B, C, D  = 2 3 = 8 ( maximum ); 2 2 = 4; 2 1 = 2; 2 0 = 1 ( minimum ); CD +BDABC+F =

Karnaugh Map Boolean Function Logic Circuit

Chapter 5 Summary

Address Stack segment Data segment Code segment Contains the beginning address of each segment Segment register (in CPU) memory (MM) SS Register DS Register CS Register

MOV AL, 09H AX = ???? 8 bit 32 bits AHAL AX EAX MOV AX,0009H AX = ???? Value in AX = FFFFH, what is the value in AX after the following instruction is executed?

8 bit 32 bits CX CHCL ECX MOV CX, 25H CX = ???? MOV CL, 0 CX = ???? Value in CX = FFFFH, what is the value in CX after the following instruction is executed?

How many bytes/ bits for the following instructions? MOV AX, 0123 MOV AH, 09

What are the values in CS register and IP register? What is the value in IP after MOV CL,42 is executed?

6.1) Assembly Language Program Format 6.2) Features of Assembly Language 6.3) Data Definition CHAPTER 6 ASSEMBLY LANGUAGE PROGRAM FORMAT AND DATA DEFINITION

PAGE directive to establish 60 lines and 132 columns per page TITLE directive to identify the program’s name as A04ASM1 ; symbol is for comment STACK to define the stack segment DATASEG to define the data segment CODESEG to define the code segment

ASSUME directive is used to tell the assembler the starting address of segments with the segment registers Initialize the address of data segment in DS Procedure MAINEND directive to tell the assembler that this is the end of the source program Request to end the program and return to the OS

Ending Program Execution After executing an assembly language program, the programmer must tell the system to terminate the executing program with the help of DOS interrupt services. INT 21H is the commonly used interrupt service. It used the function code in the AH register to determine the next course of action. INT 21H can also be used to control input from the keyboard, control the screen, disk I/O and output to the printer. INT 21H with function code 4CH is used to terminate program execution. The function code 4CH must be priory entered into AH. Example:

Data Definition Assembler offers a few directives that enable programmers to define data according to its type and length. Format for data definition: [name] Data names are optional because in assembly language programming, data is not necessarily reference by its name. Dn Directive Next slide are the common directives to define data and also directives used in MASM 6.0

The following are some examples of numeric and character data definition Page 60,132 TITLEA04DEFIN (EXE)Define data directives.MODELSMALL.DATA ;DB – Define Bytes: ; BYTE1DB?; Uninitialized BYTE2DB48; Decimal constant BYTE3DB30H; Hex constant BYTE4DB B; Binary constant BYTE5DB10 DUP (0); Ten zeros BYTE6DB‘PC FAIR’; Character string BYTE7DB‘12345’; Number as characters BYTE8DB01, ‘Jan’, 02, ‘Feb’; Table of months

;DW – Define Words: ; WORD1DW0FFF0H; Hex constant WORD2DW B; Binary constant WORD3DWBYTE8; Address constant WORD4DW2, 4, 6, 7, 9; Table of 5 constants WORD5DW6 DUP (0); Six zeros ;DQ – Define Doublewords: ; DWORD1DD?; Uninitialized DWORD2DD41562; Decimal value DWORD3DD24, 48; Two constants DWORD4DD BYTE3 – BYTE2; Difference between addresses END

DB or BYTE -to define item with the size of one byte. The range of its value is stated in the table before. DW or WORD -to define item with the size of one word or 2 bytes. The range of its value is stated in the table before. Assembler will change numeric constants into binary object code (presented in hexadecimal) and kept in the memory in reverse bytes. For instance, if the real value is 3039H it will be kept as 3930H in the data segment DD or DWORD - to define item with the size of 4 bytes. Its range of values is stated in the table above. As usual data is kept in reverse byte or reverse sequence. For example, if data is 00BC614EH it will be kept as 4E61BC00H.

Expressions Expressions in operand may specify an uninitialized value or a constant value. Example: DATAX DB?; Uninitialized item, size of 1 bait DATAYDB25; Initialized item, DATAY with value 25 Uninitialized item is used to store a value which size is defined. The value of a data can be used and edited to suit the program’s needs. Expressions can contain a few constants that is separated by the sign ‘,’ and the quantity is limited to the row length. Example: DATAZDB21, 22, 23, 24, 25, 26, … The assembler defines the above constant byte by byte, from left to right. DATAZ or DATAZ+0 contains the value 21, DATAZ+1 contains 22, DATAZ+2 contains 23 and so forth. Example of instruction MOV AL, DATAZ+3 will enter the value 24 into the CL register

Expressions also allows duplication of constants using the format below: Example: DW10DUP(?); Ten words, uninitialized DB5DUP(12); Five bytes containing 0C0C0C0C0C DB3DUP(5 DUP(4)); Fifteen 4s

CHAPTER 7 ASSEMBLY LANGUAGE INSTRUCTIONS 7.1Introduction 7.2Data Transfer Instructions 7.3Arithmetic Instructions 7.4Bit Shifting Instructions 7.5Looping Instructions 7.6Unconditional Transfer Instructions 7.7Conditional Jump Instructions 7.8Other Instructions

Data Transfer Instructions Some examples on MOV: BYTEFLDDB?; define byte WORDFLDDW?; define word … MOV EDX, ECX; register to register MOV BYTEFLD, DH; register to memory MOV WORDFLD, 1234; immediate to memory MOV CH, BYTEFLD; memory to register MOV CX, 40H; immediate to register MOV AX, DS; segment register to register

Example of the ADD and SUB instructions: BYTE1DB24H;Data elements WORD1DW4000H... MOVCL, BYTE1; byte processing MOVDL, 40H ADDCL, DL; register to register SUBCL, 20H; Immediate from register ADD BYTE1, BL; register to memory MOVCX, WORD1; word processing MOV DX, 2000H SUBCX, DX; register from register SUBCX, 124H; Immediate from memory ADDWORD1, DX; register to memory Addition and Subtraction Of Binary Data

MUL  is used for unsigned data Examples on the usage of the MUL instructions using the data as defined below: BYTE1DB80H BYTE2DB40H WORD1DW8000H WORD2DW2000H DWORD1DD H DWORD2DD H (a) MOV AL, BYTE1 ; AL (multiplicand)=80H MULBYTE2 ; byte x byte, product in AX ; 80H x 40H, AX= 2000H (b) MOVAX, WORD1 ; AX (multiplicand)=8000H MULWORD2 ; word x word, product in DX:AX ; 80000H x 2000H, ; DX:AX= H

The following are a few examples of the IDIV instruction using the data definition below: BYTE1DB80H; Byte value BYTE2DB16H WORD1DW2000H ; Word value WORD2DW0010H WORD3DW1000H (a) MOV AX, WORD1 ; AX=2000H IDIV BYTE1 ; 2000H(+ve)/80H (-ve), ; quotient=C0H (-ve), remainder=00H ; AL=C0H, AH=00H (b) MOV DX, WORD2 ;DX=0010H MOV AX, WORD3 ;AX=1000H,dividend in DX:AX (WORD2:WORD3) ;DX:AX = H (+ve) IDIV WORD1 ; H (+ve)/2000H (+ve) ;remainder:quotient in DX:AX ;1000H:0080H

Example of the SHR instruction As in the example above, the SHR instruction will enter the value 0 to the leftmost bit after the shift. Carry flag will contain the last bit shifted out after the shift BH C SHR BH, SHR BH, CL SHR BH,

Example of the SAR instruction The SAR instruction is used on signed number. SAR will enter the sign bit (whether 0 (+ve) or 1 (–ve)) into the leftmost bit after every shift. Examples of SAR instruction BH SAR BH, SAR BH, CL SAR BH,

BH

A few examples on ROR: The difference between ROR and RCR is only the way of operation. In RCR, every bit that is rotated will enter the carry flag before entering the leftmost bit BH

Below are instances of the ROL instruction : BH

LOOP Instruction – example using DEBUG -A 100 4A66:0100MOV CX,5;LOOP COUNTER=5 4A66:0103MOV AX,0 4A66:0106ADD AX,CX 4A66:0108LOOP 106;LOOP TO LOCATION 0106