1 Chapter 1: Basic Concepts Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine 9/6/2003
2 Introduction u 1.1 Welcome to Assembly Language (Important: Read this section!) u 1.2 Virtual Machine Concept u 1.3 Data Representation u 1.4 Boolean Operations
3 1.1 Welcome to Assembly Language: Why study assembly language? u Learn about computers –Computer architecture –Operating systems –Data representation –Hardware devices u Learn about assembly languages u Learn about compiling u Learn how to write embedded programs u Learn the assemble language for Intel 80x86
4 1.1 Welcome to Assembly Language: Uses of assembly language u Communicating with the operating system u Optimize critical areas of applications –Minimize size –Maximize speed u Avoid restrictions of high level languages u Access to hardware (drivers)
5 1.1 Welcome to Assembly Language: Definitions u Assembly language: machine-specific language with a one-to-one correspondence with the machine language for that computer u Machine language: The language a particular processor understands u Assembler: converts programs from assembly language to machine language
6 1.1 Welcome to Assembly Language: Example u u u u Assembly Language: High-Level Language: Machine language: x = a + b; MOV AX, a ADD AX, b MOV x, AX A A3 0000
7 1.1 Welcome to Assembly Language: Problems with assembly language u Provides no structure u Is not portable u Applications can be very long u “Hard” to read and understand u Lots of detail required
8 1.3 Data representation: Binary Numbers u Digital computers store information in binary u Binary allows two states –On yes true 1 –Off no false 0 u All information on digital computers is ultimately 0’s and 1’s
9 1.3 Data representation: Data types u byte: 8 bits: u word: 16 bits or __ bytes: u double word: __ bits or __ bytes : u quad word: __ bits or __ bytes:
Data representation: Range of a unsigned byte u Question: What is the range of numbers that can be represented with u 1 bit? u 2 bits? u 3 bits? u 4 bits? u 6 bits?
Data representation: Range of the data types u byte: 0 to = 255 u word: 0 to = 64K - 1 = 65,535 u double word: 0 to 4G - 1 = _____ u quad word: 0 to 18x10 18 Unsigned integers:
Data representation: Different bases u System Digits u Binary __ u Octal u Decimal _______________ u Hexadecimal A B C D E F
Data representation: Number systems (bases) u Number systems used –Binary: The internal representation inside the computer. They may be represented in binary, decimal, or hexadecimal. –Decimal: The system people use. u ASCII representations of numbers used for I/O: –ASCII binary –ASCII octal –ASCII decimal –ASCII hexadecimal
Data representation: Binary Addition & Multiplication u Binary addition table u Binary multiplicaton *
Data representation: Binary Addition & Multiplication u Examples: b 1010b b * 1101b u b b b * 1011b
Data representation: Hex Addition & Multiplication u Hex addition and multiplication tables are large u We can still do simple calculations by hand B852h 23Ah + 5A65h * 100h u ABCh 2B3h + E F 0 h * 102h
Data representation: Converting to decimal u = 1 * * * * *10 0 u (Human) conversions: hex to decimal ABCh = 10* * *16 0 = 10* * *1 = = 2748
Data representation: Converting to decimal u (Human) conversions to decimal ABCDh = (((10*16+11)*16+12)*16+13 = (easier on calculator)
Data representation: Conversion problems u b = ________ 10 u 1234 base 5 or (1234) 5 =_________ 10
Data representation: Conversion from decimal u (Human) conversions from decimal = ??? In hex u 2748 = 171 * u 171 = 10 * = 0 * so value is ABCh 2748 = 171 * = (10* ) * = 10 * * * 16 0 = ABCh How do we know this is the Hex representation?
Data representation: Conversion problems u Write decimal 58 in binary. u Write decimal 194 in base 5
Data representation: Conversions: hex and binary u Conversion between base 10 and base 1000 = 10 3 u 1,234,567 = 1* * * u Conversion between base 2 and base 16 = b = = 3Ah u 3Ah = b u Note: we often write binary numbers in hex because: –binary numbers can be very long –it is easy to convert back and forth
Data representation: Conversion problems u Write ABCh in binary. u Write b in hex. u Write b in octal
Data representation: Comments u It is EXTREMELY important to get good at hex and binary –conversion –addition.
Data representation: Signed numbers u Signed numbers: The number of bits must be fixed. In every case, the left hand bit is the sign bit. u 0 means + u 1 means -
Data representation: Signed numbers u We will look at 3 representations in 6 bits. u sign and magnitude 10d = b -10d = b u one’s complement 10d = b -10d = b (one’s complement)
Data representation: Two’s complement u two’s complement 10d = b (one’s complement) d = b (two’s complement) u (one’s complement) d = b (two’s complement) u Two’s complement is used for signed integers on most computers
Data representation: Practice problems u Find the 8 bit two’s complement representation of -2Ch u Find the 8 bit two’s complement representation of 2Ch u What is decimal representation of the two’s complement number ?
Data representation: Signed numbers - Comments u The representation of positive numbers is the same in all three systems u The representation of negative numbers differs between the 3 systems u There are two ways to write 0 in sign and magnitude representations and in one’s complement
Data representation: Signed numbers - Comments u Two's complement: Sizes Signed byte: -128 to +127 = Signed word: -32,768 to +32,767 = Singed double word: -2,147,483,648 to +2,147,483,647 = u Observe there is one more negative than positive value u There are (about) half as many positive signed values as unsigned values
Data representation: Signed numbers - Comments u Vocabulary: “Find the two’s complement of” vs. “Find the two’s complement representation of”
Data representation: Signed numbers - Comments u Why is two’s complement the most popular way of representing signed integers?
Data representation: Signed numbers - Comments u 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.
Data representation: Signed numbers - Comments u Two's complement: Just add numbers even if one or both are negative u (Assume 6 bit two’s complement) = = = = = = -5 u To subtract, take the two’s complement of the number being subtracted and add
Data representation: Character Storage u Characters are stored as numbers u Coding schemes –ASCII (7 or 8 bit) –EBCDIC (8 bit) –Unicode (16 bit) u ASCII Examples: “A” = 65d = 41h “a” = 97d = 61h “B” = 66d = 42h “b” = 98d = 62h “0” = 48d = 30h “1” = 49d = 31h “ “ = 32d = 20h “*” = 42d = 2Ah
Data representation: What does a number represent? u What is CD21h ( b)? u Unsigned integer: u Signed integer (two’s complement): u (one’s complement): u (sign and magnitude): u Instruction: INT 21h u MS-DOS characters: ! u Windows characters: Í! u Two 1 byte numbers: CDh, 21h Line drawing character
Boolean Operations Boolean Algebra u Values: true and false u Invented by George Boole u Boolean operations NOT AND OR
Boolean Operations Boolean Algebra u X Not X false true true false X Y X and Y X or Y false false false false false true false true true false true true true true true true
Boolean Operations Boolean Algebra Example: X and not Y X Y Not Y X and not Y false false true false false true false false true false true true true true false false
Boolean Operations Boolean Algebra u Problem: not (X and Y) or Z
41 u CSCE 380 u Department of Computer Science and Computer Engineering u Pacific Lutheran University u 9/6/2003