Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic."— Presentation transcript:

1 Chapter 2 Summary

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

3 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

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

5 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)

6 One’s Complement The negative number is represented by flipping the number’s bits E.g., 01001001 becomes 10110110 E.g. consider 103 + -97  01100111 + (-01100001) = 01100111 + 10011110  = 100000101 (9 bits)  00000101 + 1 = 00000110 (8 bits)  103 – 97 = 6 = 00000110  Try 113 + -42 = ?? and –75 + 13 = ??

7 Ones Complement In the ones complement representation, positive numbers are same as that of sign-and-magnitude Example: +5 = 00000101 (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

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

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

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.

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

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

13 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

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

15 Chapter 3 Summary

16 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,…)

17 The package Truth Tables and Boolean Algebra set out the basic principles of logic. A B F 0 0 0 0 1 0 1 0 0 1 1 1 A B F 0 0 0 0 1 1 1 0 1 1 1 1 A B F 0 0 0 0 1 1 1 0 1 1 1 1 A B F 0 0 0 0 1 0 1 0 0 1 1 1 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 0 1 1 0 the symbols, algebra signs and the truth table for the gates

18 1. Identity Elements 2. Inverse Elements 1. A = A A. A = 0 0 + 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

19 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

20 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

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

22 Truth Table

23 A B Q A AB B = AB + B Produce a truth table from the logic circuit ABAABQ 00100 01111 10000 11001

24 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 0001 1011 B A B A B A B A 10 1 0

25 00000001 0100 1100 1000 AB C D A B C D A B CD A B C D 4 variables, A, B, C, D  2 4 = 16 squares

26 000010110100 001011111101 AB C C C 000001 010011 110111 100101 ABC C 00011110 0101 00 01 11 10 01 List combinations in the order 00, 01, 11, 10 C

27 ABCF 0001 0010 0100 0111 1001 1011 1100 1110 Truth Table Karnaugh Map 11 11 0 00 11 11 0 BC A 0 1 A A How to create Karnaugh Map 1.Place 1 in the corresponding square

28 11 0 00 11 11 0 AB F = AB + AB A B Karnaugh Maps to Represent Boolean Functions

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

30 1 1111 0 00 11 11 0 BC A 0 1 A A 3 variables: 2 3-1 = 2 2 = 4 2 2-1 = 2 1 = 2 2 1-1 = 2 0 = 1 A BC F = A + BC

31 11 1 1 111 AB 01 00 CD 11 10 11 4 variables, A, B, C, D  2 4-1 = 2 3 = 8 ( maximum ); 2 2 = 4; 2 1 = 2; 2 0 = 1 ( minimum ); CD +BDABC+F =

32 Karnaugh Map Boolean Function Logic Circuit

33 Chapter 5 Summary

34 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

35

36 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?

37 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?

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

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

40 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

41 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

42 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

43 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:

44 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

45

46 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 BYTE4DB01111010B; Binary constant BYTE5DB10 DUP (0); Ten zeros BYTE6DB‘PC FAIR’; Character string BYTE7DB‘12345’; Number as characters BYTE8DB01, ‘Jan’, 02, ‘Feb’; Table of months

47 ;DW – Define Words: ;------------------------- WORD1DW0FFF0H; Hex constant WORD2DW01111010B; 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

48 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.

49 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

50 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

51 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

52 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

53 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 7.3.1 Addition and Subtraction Of Binary Data

54 MUL  is used for unsigned data Examples on the usage of the MUL instructions using the data as defined below: BYTE1DB80H BYTE2DB40H WORD1DW8000H WORD2DW2000H DWORD1DD00018402H DWORD2DD00012501H (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= 1000 0000H

55 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 = 0010 1000H (+ve) IDIV WORD1 ;00101000H (+ve)/2000H (+ve) ;remainder:quotient in DX:AX ;1000H:0080H

56 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 10110111 BH C 010110111 SHR BH, 01 000101101 SHR BH, CL 000001011 SHR BH, 02 0 00

57 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 10110111 BH 110110111 SAR BH, 01 111101101 SAR BH, CL 111111011 SAR BH, 02 1 11

58 00000101 BH 000001010 000101000 010100000 00 0

59 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 10110111 BH 110110111 011110110 011 1 1 2 3 1 2 3

60 Below are instances of the ROL instruction : 10110111 BH 1 2 3 1 101101111 1 1 2 3 101111011 011

61

62 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


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

Similar presentations


Ads by Google