Download presentation
Presentation is loading. Please wait.
Published byBennett Franklin Barnett Modified over 8 years ago
1
1 Chapter 1: Introduction Appendix A: Binary and Hexadecimal Tutorial Assembly Language for Intel-Based Computers, 3rd edition Kip R. Irvine
2
Introduction 1.1 Context of assembly language (Important: Read this section!) 1.2 Data representation A.1 Binary numbers A.2 Hexadecimal numbers A.3 Arithmetic 1.3 Introducing assembly language
3
1.1 Context of assembly language: Why study assembly language (ASM)? n To learn how high-level language (HLL) code gets translated into machine language Assembly language: machine- specific language with a one-to- one correspondence with the machine language for that computer Machine language: The language a particular processor understands
4
1.1 Context of assembly language: Example High-Level Language: 10 + 20; Machine language: B8 1000 05 3000 MOV AX, 10 ADD AX, 20 Assembly Language: Immediate operand op code
5
n To learn the computer (i.e., architecture, hardware, operating system…) u by direct access to memory, video controller, sound card, keyboard… u by communicating with the operating system n To speed up applications u direct access to hardware (ex: writing directly to I/O ports instead of doing a system call) u good ASM code is faster and smaller u Avoid restrictions of high level languages 1.1 Context of assembly language: Why study assembly language (ASM)?
6
1.1 Context of assembly language: Problems with assembly language Provides no structure Is not portable Applications can be very long “Hard” to read and understand Lots of detail required
7
1.2 Data representation: Binary Numbers Digital computers store information in binary Binary allows two states –On yes true 1 –Off no false 0 Each digit in a binary number is called a bit 0 1 1 0 0ff on on off bit
8
1.2 Data representation: Data types byte: 8 bits: 10010101 word: 16 bits or __ bytes: 1110101101100010 double word: __ bits or __ bytes : 11010110111001011101011011001011 quad word: __ bits or __ bytes: 01011110110101011101010011001011 11110110110001011101011011001101 2 324 64 8
9
1.2 Data representation: Range of a unsigned number Question: What is the range of numbers that can be represented with ? 2 bits? 4 bits? 1 bit? n bit?
10
1.2 Data representation: Range of the data types byte: 0 to 2 8 - 1 = 255 word: 0 to 2 16 - 1 = 64k - 1 = 65,535 double word: 0 to 2 32 - 1 quad word: 0 to 2 64 - 1 Unsigned integers:
11
1.2 Data representation: Numbering Systems A number system of base n is a system that uses distinct symbols for n digits
12
A written number is meaningful only with respect to a base 1.2 Data representation: Numbering Systems To tell the assembler which base we use: –Hexadecimal 25 is written as 25h –Octal 25 is written as 25o or 25q –Binary 1010 is written as 1010b –Decimal 1010 is written as 1010 or 1010d
13
1.2 Data representation: Number systems (bases) Number systems used –Binary: The internal representation inside the computer. They may be represented in binary, octal, or hexadecimal. –Decimal: The system people use. ASCII representations of numbers used for I/O: –ASCII binary –ASCII octal –ASCII decimal –ASCII hexadecimal
14
1.2 Data representation: Number systems (bases) Example
15
A.1 Binary numbers : Addition & Multiplication Binary multiplication * 0 1 0 0 0 1 0 1 Binary addition table + 0 1 0 0 1 1 1 10
16
A.1 Binary numbers : Addition & Multiplication Examples: 1001100b 1110b + 1101011b * 1101b 10110101b 111101b + 1101101b * 1111b 10110111 10110110 1001000101110010011
17
A.2 Hexadecimal numbers : Addition & Multiplication Hex addition and multiplication tables are large We can still do simple calculations by hand B852h 23Ah + 5A65h * 100h ABCh 2B3h + E F 0 h * 102h
18
A.3 Arithmetic: Converting to decimal Binary to Decimal 1010b =1 * 2 3 + 0 * 2 2 + 1 * 2 1 + 0*10 0 =10 Hex to Decimal ABCh = 10 * 16 2 + 11 * 16 1 + 12 * 16 0 = 10 * 256 + 11 * 16 + 12 * 1 = 2560 + 176 + 12 = 2748
19
A.3 Arithmetic: Converting to decimal Octal to Decimal 256o = 2 * 8 2 + 5 * 8 1 + 6 * 8 0 =174 Conclusion: (Number) n = (multiply each digit by an integer power of n)
20
A.3 Arithmetic: Conversion problems 1234 base 5 or (1234) 5 =_________ 111010b = ________ 45677h = ________ 736.4o = ________
21
A.3 Arithmetic: Conversion from decimal Decimal integer to Binary 54 = 27 * 2+ 0 27 = 13 * 2 + 113 = 6 * 2 +1 1 1 0 remainder quotient 1 = 0 * 2 + 1 3 = 1 * 2 + 1 6 = 3 * 2 + 0
22
A.3 Arithmetic: Conversion from decimal Decimal integer to Hex : Decimal integer to octal 54 = 6 * 8+ 6 6 = 0 * 8 + 6 6 6 o 54= 3 * 16 + 6 3 = 0 * 16 + 3 3 6 h
23
Decimal fraction to Binary (Octal, Hex) A.3 Arithmetic: Conversion from decimal (0. 6 8 7 5) 10 2X 1. 3 7 5 0 2X 1. 0 0 0 0 0. 7 5 0 0 2X 1. 5 0 0 0 2X = (0.1011) 2 0.1 0 1 1 integer
24
A.3 Arithmetic: Conversion from decimal Conclusion a decimal integer to a base n representation successive division by n accumulation of the remainders a decimal fraction to a base n representation successive multiplication by n accumulation of the integer digits
25
A.3 Arithmetic: Conversion problems (1234) 10 =(________) 2 (41.6875) 10 =(________) 2 (1234) 10 =(________) 8 (1234) 10 =(________) 16
26
A.3 Arithmetic: Conversions: hex, octal and binary Conversion between base 2 and base 8 = 2 3 111010b = 111 010 = 72o Conversion between base 2 and base 16 = 2 4 111010b = 11 1010 = 3Ah Note: we often write binary numbers in hex: –binary numbers can be very long –it is easy to convert back and forth
27
A.3 Arithmetic: Conversion problems Write ABCh in binary. Write 101110100010100b in hex. Write 101110100010100b in octal
28
A.3 Arithmetic: Comments See appendix A for more information. It is EXTREMELY important to get good at hex and binary –conversion –addition.
29
A.3 Arithmetic: Signed numbers Signed numbers: The number of bits must be fixed. In every case, the highest bit is the sign bit. 0 means + 1 means - Example: Unsigned number: 1101b = 13 Signed number: 1101b = ?
30
A.3 Arithmetic: Two’s complement 1101 b (signed binary number) 0010 b (reverse all bits) + 1 0011 b (unsigned value = 3) - 3d = One’s complement Two’s complement two’s complement of n = NOT(n) +1 reversible
31
A.3 Arithmetic: Practice problems Find the 8 bit two’s complement representation of -2Ch Find the 8 bit two’s complement representation of 2Ch What is decimal representation of the two’s complement number 11110100?
32
A.3 Arithmetic: Range of signed numbers Two's complement: Sizes Signed byte: -128 to +127 = 2 7 - 1 Signed word: -32,768 to +32,767 = 2 15 - 1 Singed double word: -2,147,483,648 to +2,147,483,647 = 2 31 - 1 Comments: There is one more negative than positive value There are (about) half as many positive signed values as unsigned values
33
A.3 Arithmetic: Addition & Subtraction (signed) Algorithm to add in signed decimal (sign and magnitude) If both numbers have the same sign Add the two magnitudes Prefix with the common sign else Subtract the number with smaller magnitude from the number with the larger magnitude Prefix with the sign of the number with the larger magnitude.
34
A.3 Arithmetic: Addition & Subtraction (signed) Two's complement: 1) add two numbers including their sign bits 2) discard any carry out of the sign position Addition + 6 0 0 0 0 0 1 1 0 + 13 0 0 0 0 1 1 0 1 + 19 0 0 0 1 0 0 1 1 Example: - 19 1 1 1 0 1 1 0 1 - 6 1 1 1 1 1 0 1 0 - 13 1 1 1 1 0 0 1 1
35
A.3 Arithmetic: Addition & Subtraction (signed) Example: 6 0 0 0 0 0 1 1 0 - 13 - 7 1 1 1 1 1 0 0 1 Subtraction 1) Take the 2’s complement of the subtrahend (including the sign bit) 2) Add it to the minuend (including the sign bit) - 6 13 0 0 0 0 1 1 0 1 + 7 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0
36
A.3 Arithmetic: Character Storage Characters are stored as numbers Coding schemes –ASCII (7 or 8 bit) –EBCDIC (8 bit) –Unicode (16 bit) ASCII Examples: “A” = 65d = 41h “a” = 97d = 61h “B” = 66d = 42h “b” = 98d = 62h “0” = 48d = 30h “1” = 49d = 31h “ “ = 32d = 20h “*” = 42d = 2Ah
37
1.3 Introducing Assembly Language: MASM Installation Insert CD in CD-Rom Go to Desktop, select My Computer Select CD-Rom directory (\IRVINE) Double click “index.html” On the new screen, follow the links, install MASM613, sample program, link library etc.
38
Select Start | Programs (| Accessories) |MS-DOS (Command) Prompt Type edit autoexec.bat Add the following commands in the file: SET HELPFILES=c:\masm613\help\*.hlp PATH=c:\masm613\bin;c:\masm613\binr;%PATH% Save and Exit edit Type autoexec 1.3 Introducing Assembly Language: Setup System Environment
39
1.3 Introducing Assembly Language: A simple Debug program MOV AX, 10 ADD AX, 20 SUB AX, 5 MOV [130], AX INT 20 Store 10 into register AX Terminate program Assembler: converts programs from assembly language to machine language Store AX in memory location 130h
40
1.3 Introducing Assembly Language: Running a Debug program Select Start | Programs (| Accessories) |MS-DOS (Command) Prompt Type Debug Type A 100, type the program, press return Type R (registers) to display the registers Type T (trace) as needed to step through program Type G (go) to execute the rest of program Type D 130 131 to display locations 130 and 131 Type Q (quit) to exit Debug
41
1.3 Introducing Assembly Language: Debug register display Next instruction Contents of AX (hex) -R AX=0030 BX=0000 CX=0000 SP=FFEE... DS=1FA6 ES=1FA6 SS=1FA6 CS=0106... 1FA6:0106 2D0500 SUB AX, 0005
42
1.3 Introducing Assembly Language: Debug memory display Contents of locations 130 and 131. Namely 002Bh -D 130 131 1FA6:0130 2B 00 Note: The individual bytes in binary are reversed when stored in memory Example: 234567 would be stored in memory as 674523
43
1.3 Introducing Assembly Language: Debug disassembly -U 100 1FA6:0100 B81000 MOV AX, 0010 1FA6:0103 052000 ADD AX, 0020 1FA6:0106 2D0500 SUB AX, 0005 1FA6:0109 A33001 MOV [0130],AX 1FA6:010C CD20 INT 20 1FA6:010E 1F POP DS Memory locations Machine code Disassembled assembly code
44
CSCE 380 Department of Computer Science and Computer Engineering Pacific Lutheran University 2/2/2000
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.