chapter 2 summary. overview numbers –decimal, binary, octal, hexadecimal –their relationship...
Post on 21-Dec-2015
245 views
TRANSCRIPT
![Page 1: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/1.jpg)
Chapter 2
Summary
![Page 2: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/2.jpg)
Overview
• Numbers– Decimal, Binary, Octal, Hexadecimal– Their relationship
• Sign-magnitude
• One’s complement
• Two’s complement
• Arithmetic operation
![Page 3: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/3.jpg)
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
![Page 4: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/4.jpg)
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)
![Page 5: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/5.jpg)
One’s Complement
• The negative number is represented by flipping the number’s bits
• E.g., 01001001 becomes 10110110• E.g. consider 103 + -9701100111 + (-01100001) = 01100111 + 10011110 = 100000101 (9 bits)00000101 + 1 = 00000110 (8 bits)103 – 97 = 6 = 00000110Try 113 + -42 = ?? and –75 + 13 = ??
![Page 6: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/6.jpg)
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. • –510 in ones complement is
111110102
![Page 7: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/7.jpg)
Exercise:Get the representation of ones complement (6 bit) for the following numbers:
i) +710 ii) –1010
Solution:
(+7) = 0001112
Solution:
(+10)10 = 0010102
So,
(-10)10 = 1101012
![Page 8: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/8.jpg)
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.
![Page 9: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/9.jpg)
Example:Convert –5 into twos complement representation and give the answer in 8 bits.
Solution: First, obtain +5 representation in 8 bits 000001012
Obtain ones complement for –5
111110102
Add 1 to the ones complement number:
111110102 + 12 = 111110112
–5 in twos complement is 111110112
![Page 10: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/10.jpg)
Exercise:• Obtain representation of twos complement (6 bit) for the following numbers
i) +710 ii)–1010
Solution:
(+7) = 0001112(same as sign-magnitude)
Solution:
(+10) 10 = 0010102
(-10) 10 = 1101012 + 12
= 1101102
So, twos compliment for –10 is 1101102
![Page 11: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/11.jpg)
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
![Page 12: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/12.jpg)
Chapter 3
Summary
![Page 13: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/13.jpg)
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,…)
![Page 14: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/14.jpg)
• The package Truth Tables and Boolean Algebra set out the basic principles of logic.
A B F0 0 00 1 01 0 01 1 1
A B F0 0 00 1 11 0 11 1 1
A B F0 0 00 1 11 0 11 1 1
A B F0 0 00 1 01 0 01 1 1
F
F
F
F
Name Graphic Symbol Boolean Algebra Truth Table
AB
AB
AB
AB
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
![Page 15: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/15.jpg)
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) = A A + (B + C) = (A + B) + C A . (A + B) = A A . (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
![Page 16: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/16.jpg)
Relationship Between Boolean Function and Logic Circuit
A
B Q
Boolean function Q = AB + B = (NOT A AND B) OR B
Logic circuitA
AB
B= AB + B
![Page 17: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/17.jpg)
Relationship Between Boolean Function and Logic Circuit
• Any Boolean function can be implemented in electronic form as a network of gates called logic circuit
AB
F
A.B = AB
CD C + D
= AB + C + D
![Page 18: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/18.jpg)
G = A . (B + C + D)
A
B
CD
G = A . (B + C + D)
C + D
B + C + D
![Page 19: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/19.jpg)
Truth Table
![Page 20: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/20.jpg)
A
B Q
AAB
B= AB + B
Produce a truth table from the logic circuit
A B A AB Q
0 0 1 0 0
0 1 1 1 1
1 0 0 0 0
1 1 0 0 1
![Page 21: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/21.jpg)
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 2n squares, representing all possible combination of values of n binary variables
• Example: 2 variables, A and B
A B A B
A B A B
00 01
10 11
BA B
A
B
A
BA
1 0
1
0
![Page 22: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/22.jpg)
0000 0001
0100
1100
1000
AB C D
A B
C D
A B
CD
A B
A B
C DC D
4 variables, A, B, C, D 24 = 16 squares
![Page 23: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/23.jpg)
000 010 110 100
001 011 111 101
AB
C
A B
C
A BC A B A B
000 001
010 011
110 111
100 101
AB C
A B
C
A B
A B
A B
00 01 11 10
0
1
00
01
11
10
0 1
• List combinations in the order 00, 01, 11, 10
C
![Page 24: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/24.jpg)
A B C F
0 0 0 1
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 0
Truth Table
Karnaugh Map
1 1
1 1
0 0 0 1 1 1 1 0BC
A
0
1
A
A
B CB C B C B C
How to create Karnaugh Map
1. Place 1 in the corresponding square
![Page 25: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/25.jpg)
1 1
0 0 0 1 1 1 1 0AB
F = AB + AB
A BA B A B A B
Karnaugh Maps to Represent Boolean Functions
![Page 26: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/26.jpg)
2. Group the adjacent squares:Begin grouping square with 2n-1 for n variables• e.g. 3 variables, A, B, and C
23-1 = 22 = 4 = 21 = 2 = 20 = 1
1 1
1 1
0 0 0 1 1 1 1 0BC
A
0
1
A
A
B CB C B C B C
ABBC ABC F = BC AB ABC+ +
![Page 27: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/27.jpg)
1
1 1 1 1
0 0 0 1 1 1 1 0BC
A
0
1
A
A
B CB C B C B C3 variables: 23-1 = 22 = 4 22-1 = 21 = 2 21-1 = 20 = 1
A
BC
F = A + BC
![Page 28: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/28.jpg)
1 1
1
1
1 1 1
AB 01
01
00
00
CD
11
10
1011
4 variables, A, B, C, D 24-1 = 23 = 8 (maximum); 22 = 4;21 = 2; 20 = 1 (minimum);
CD + BD ABC+F =
![Page 29: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/29.jpg)
Karnaugh Map
Boolean Function
Logic Circuit
![Page 30: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/30.jpg)
Chapter 5
Summary
![Page 31: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/31.jpg)
Address
Address
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
![Page 32: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/32.jpg)
![Page 33: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/33.jpg)
MOV AL, 09HAX = ????
8 bit 8 bit
32 bits
AH AL
AX
EAX
MOV AX,0009HAX = ????
Value in AX = FFFFH, what is the value in AX after the following instruction is executed?
![Page 34: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/34.jpg)
8 bit 8 bit
32 bits
CX
CH CL
ECX
MOV CX, 25HCX = ????
MOV CL, 0CX = ????
Value in CX = FFFFH, what is the value in CX after the following instruction is executed?
![Page 35: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/35.jpg)
How many bytes/ bits for the following instructions?
MOV AX, 0123
MOV AH, 09
![Page 36: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/36.jpg)
What are the values in CS register and IP register?
What is the value in IP after MOV CL,42 is executed?
![Page 37: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/37.jpg)
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 38: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/38.jpg)
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 segmentCODESEG to
define the code segment
![Page 39: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/39.jpg)
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 MAIN
END directive to tell the assembler that this is the end of the source program
Request to end the program and return to the OS
![Page 40: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/40.jpg)
Ending Program ExecutionAfter 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:
![Page 41: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/41.jpg)
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
![Page 42: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/42.jpg)
![Page 43: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/43.jpg)
The following are some examples of numeric and character data definition
Page 60, 132TITLE A04DEFIN (EXE) Define data directives
.MODEL SMALL
.DATA;DB – Define Bytes:;-----------------------BYTE1 DB ? ; UninitializedBYTE2 DB 48 ; Decimal constantBYTE3 DB 30H ; Hex constantBYTE4 DB 01111010B ; Binary constantBYTE5 DB 10 DUP (0) ; Ten zerosBYTE6 DB ‘PC FAIR’ ; Character stringBYTE7 DB ‘12345’ ; Number as charactersBYTE8 DB 01, ‘Jan’, 02, ‘Feb’ ; Table of months
![Page 44: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/44.jpg)
;DW – Define Words:;-------------------------WORD1 DW 0FFF0H ; Hex constantWORD2 DW 01111010B ; Binary constantWORD3 DW BYTE8 ; Address constantWORD4 DW 2, 4, 6, 7, 9 ; Table of 5 constantsWORD5 DW 6 DUP (0) ; Six zeros
;DQ – Define Doublewords:;---------------------------------DWORD1 DD ? ; UninitializedDWORD2 DD 41562 ; Decimal valueDWORD3 DD 24, 48 ; Two constantsDWORD4 DD BYTE3 – BYTE2 ; Difference between addressesEND
![Page 45: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/45.jpg)
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.
![Page 46: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/46.jpg)
Expressions
Expressions in operand may specify an uninitialized value or a constant value. Example:
DATAX DB ? ; Uninitialized item, size of 1 baitDATAY DB 25 ; 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: DATAZ DB 21, 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
![Page 47: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/47.jpg)
Expressions also allows duplication of constants using the format below:
Example:DW 10 DUP(?) ; Ten words, uninitializedDB 5 DUP(12) ; Five bytes containing
0C0C0C0C0CDB 3 DUP(5 DUP(4)) ; Fifteen 4s
![Page 48: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/48.jpg)
CHAPTER 7 ASSEMBLY LANGUAGE
INSTRUCTIONS
7.1 Introduction
7.2 Data Transfer Instructions
7.3 Arithmetic Instructions
7.4 Bit Shifting Instructions
7.5 Looping Instructions
7.6 Unconditional Transfer Instructions
7.7 Conditional Jump Instructions
7.8 Other Instructions
![Page 49: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/49.jpg)
Data Transfer InstructionsSome examples on MOV:
BYTEFLD DB ? ; define byteWORDFLD DW ? ; define word
…MOV EDX , ECX ; register to registerMOV BYTEFLD , DH ; register to memoryMOV WORDFLD , 1234 ; immediate to memoryMOV CH , BYTEFLD ; memory to registerMOV CX , 40H ; immediate to register
MOV AX , DS ; segment register to register
![Page 50: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/50.jpg)
Example of the ADD and SUB instructions:
BYTE1 DB 24H ;Data elements WORD1 DW 4000H
. . .MOV CL , BYTE1 ; byte processing MOV DL , 40HADD CL , DL ; register to register SUB CL , 20H ; Immediate from register ADD BYTE1 , BL ; register to memory MOV CX , WORD1 ; word processing MOV DX , 2000HSUB CX , DX ; register from registerSUB CX , 124H ; Immediate from memoryADD WORD1 , DX ; register to memory
7.3.1 Addition and Subtraction Of Binary Data
![Page 51: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/51.jpg)
MUL is used for unsigned data Examples on the usage of the MUL instructions using the data as defined below:
BYTE1 DB 80HBYTE2 DB 40HWORD1 DW 8000HWORD2 DW 2000HDWORD1 DD 00018402HDWORD2 DD 00012501H
(a) MOV AL, BYTE1 ; AL (multiplicand)=80HMUL BYTE2 ; byte x byte, product in AX
; 80H x 40H, AX= 2000H
(b) MOV AX, WORD1 ; AX (multiplicand)=8000HMUL WORD2 ; word x word, product in DX:AX
; 80000H x 2000H, ; DX:AX= 1000 0000H
![Page 52: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/52.jpg)
The following are a few examples of the IDIV instruction using the data definition below:
BYTE1 DB 80H ; Byte valueBYTE2 DB 16HWORD1 DW 2000H ; Word valueWORD2 DW 0010HWORD3 DW 1000H
(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
![Page 53: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/53.jpg)
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
1 0 1 1 0 1 1 1BH
C
0 1 0 1 1 0 1 1 1
SHR BH, 01
0 0 0 1 0 1 1 0 1
SHR BH, CL
0 0 0 0 0 1 0 1 1
SHR BH, 02
0
00
00
![Page 54: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/54.jpg)
Example of the SAR instructionThe 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
1 0 1 1 0 1 1 1BH
1 1 0 1 1 0 1 1 1
SAR BH, 01
1 1 1 1 0 1 1 0 1
SAR BH, CL
1 1 1 1 1 1 0 1 1
SAR BH, 02
1
11
11
![Page 55: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/55.jpg)
0 0 0 0 0 1 0 1 BH
0 0 0 0 0 1 0 1 0
0 0 0 1 0 1 0 0 0
0 1 0 1 0 0 0 0 0
00
0
00
![Page 56: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/56.jpg)
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
1 0 1 1 0 1 1 1BH
1 1 0 1 1 0 1 1 1
0 1 1 1 1 0 1 1 0011
1
011
1
2
3
1
2
3
![Page 57: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/57.jpg)
Below are instances of the ROL instruction :
1 0 1 1 0 1 1 1 BH1
2
3
1
1 0 1 1 0 1 1 1 11
1
2
3
1 0 1 1 1 1 0 1 1
011
011
![Page 58: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/58.jpg)
![Page 59: Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic](https://reader033.vdocuments.site/reader033/viewer/2022061616/56649d6a5503460f94a486c4/html5/thumbnails/59.jpg)
LOOP Instruction – example using DEBUG
-A 1004A66:0100 MOV CX,5 ;LOOP COUNTER=54A66:0103 MOV AX,04A66:0106 ADD AX,CX4A66:0108 LOOP 106 ;LOOP TO LOCATION 0106