[go: up one dir, main page]

0% found this document useful (0 votes)
173 views18 pages

Basic Concepts: 1.1 Welcome To Assembly Language 1

This chapter introduces basic concepts of assembly language programming. It discusses the history and applications of assembly language, as well as the hardware and software needed. Key topics covered include data representation, boolean logic, virtual machine concepts, and the relationship between assembly language and higher-level languages like C++. Assembly language provides low-level access to hardware but lacks portability, while higher-level languages are more portable but less efficient.

Uploaded by

shakra chaudhry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
173 views18 pages

Basic Concepts: 1.1 Welcome To Assembly Language 1

This chapter introduces basic concepts of assembly language programming. It discusses the history and applications of assembly language, as well as the hardware and software needed. Key topics covered include data representation, boolean logic, virtual machine concepts, and the relationship between assembly language and higher-level languages like C++. Assembly language provides low-level access to hardware but lacks portability, while higher-level languages are more portable but less efficient.

Uploaded by

shakra chaudhry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Chapter 1

Basic Concepts

1.1 Welcome to Assembly Language 1


1.1.1 Good Questions to Ask 2
1.1.2 Assembly language Applications 5
1.1.3 Section Review 6
1.2 Virtual Machine Concept 7
1.2.1 History of PC Assemblers 9
1.2.2 Section Review 9
1.3 Data Representation 9
1.3.1 Binary Numbers 10
1.3.2 Binary Addition 11
1.3.3 Integer Storage Sizes 12
1.3.4 Hexadecimal Integers 13
1.3.5 Signed Integers 14
1.3.6 Character Storage 16
1.3.7 Section Review 18
1.4 Boolean Operations 20
1.4.1 Truth Tables for Boolean Functions 22
1.4.2 Section Review 23
1.5 Chapter Summary 23

CMPS293&290 Class Notes (Chap 01) Page 1 /18 Kuo-pao Yang


Chapter 1
Basic Concepts

1.1 Welcome to Assembly Language 1

• Assembly Language for Intel-Based computers focuses on programming microprocessors


compatible with the Intel IA-32 processor family on the MS-Windows platform.
• You can use an Intel or AMD 32-bit/64-bit processor to run all program in this book.
• The IA-32 family began with the Intel 80386, continuing to (and including) the Pentium4.
• Microsoft MASM (Macro Assembler) 8.0 is our assembler of choice, running under MS-
Windows.

1.1.1 Good Questions to Ask 2

• What background should I have?


o You will better understand high-level programming constructs such as IF statements,
loops, and arrays when implemented in assembly language.
• What are assemblers and Linkers?
o An assembler is a utility program that converts source code programs from assembly
language into machine language.
o A linker is a utility program that combines individual files created by an assembler into a
single executable program.
o A related utility called a debugger; lets you to step through a program while it’s running
and examine registers and memory.
• What hardware and software do I need?
o MASM (the assembler) is compatible with all 32-bit versions of MS Windows.
o Editor: Microsoft Visual C++ 2005 Express
o 32-bit Debugger: The debugger supplied with Visual C++ 2005 Express is excellent.
o 16-Bit Real-Address Mode: 16-bit real-address mode programs run under MS-DOS and
in the console window under MS-Windows. Also known as real mode programs, they
use a segmented memory model required of programs written for the Intel 8086 and 8088
processors.
o 32-Bit protected Mode: 32-bit protected mode programs run under all 32-bit versions
of MS Windows.
• What do I get with this book?
o Online Help File
o Assembly Language Workbook
o Irvine32 and Irvine16 link libraries
o Example programs
o Corrections
o Tutorials
o Articles
o Discussion Group

CMPS293&290 Class Notes (Chap 01) Page 2 /18 Kuo-pao Yang


• What will I learn?
o Basic principles of computer architecture as applied to the Intel IA-32 processor family
o Basic Boolean logic and how it applies to programming and computer hardware
o How IA-32 processors manage memory, using real mode, protected mode, and virtual
mode.
o How high-level language compilers (such as C++) translate statements from their
language into assembly language and native machine code.
o How high-level languages implement arithmetic expressions, loops, and logical structures
at the machine level.
o Data representation, including signed and unsigned integers, real numbers, and character
data.
o How to debug programs at the machine level. The need for this skill is vital when you
work in language such as C and C++, which provide access to low-level data and
hardware.
o How application programs communicate with the computer’s operating system via
interrupt handlers, system calls, and common memory areas.
o How to interface assembly language code to C++ programs.
o How to create assembly language application programs.
• How Does Assembly Language Relate to Machine Language?
o Assembly language has a one-to-one relationship with machine language: Each assembly
language instruction corresponds to a single machine-language instruction.
• How Do C++ and Java Relate to Assembly Language?
o High-level languages such as C++ and Java have a one-to-many relationship with
assembly language and machine language.
o The following C++ statement caries out two arithmetic operations and assigns the result
to a variable. Assume X and Y are integer:

int Y;
int X = (Y + 4) * 3;

o Following is the statement’s translation to assembly language. The translation requires


multiple statements because assembly language works at a detailed level:

mov eax, Y ; move Y to the EAX register


add eax, 4 ; add 4 to the EAX register
mov ebx, 3 ; move 3 to the EBX register
imul ebx ; multiply EAX by EBX
mov X, eax ; move EAX to X

• Is Assembly Language Portable?


o A language whose source programs can be compiled and run on a wide variety of
computer systems is said to be portable. C++ programs, for example.
o Assembly language is not portable because it is designed for a specific processor family.

CMPS293&290 Class Notes (Chap 01) Page 3 /18 Kuo-pao Yang


• Why Learn Assembly Language?
o If you study computer engineering, you may likely be asked to write embedded
programs. They are short programs stored in a small amount of memory in single-
purposed devices such as telephones, automobile fuel and ignition systems, air-
conditioning control systems, security systems, data acquisition instruments, video cards,
sound cards, hard drives, modems, and printers. Assembly language is ideal for writing
embedded programs because of its economical use of memory.
o Real-time applications such as simulations and hardware monitoring require precise
timing and responses.
o Computer game consoles require their software to be highly optimized for small code
size and fast execution. It permits direct access to computer hardware and code can be
hand optimized for speed.
o Assembly language helps you to gain an overall understanding of the interaction
between computer hardware, operating system, and application programs.
o Application programmers occasionally find that limitations in high-level languages
prevent then from efficiently performing low-level task such as bitwise manipulation and
data encryption.
o Hardware manufactures create device drivers for the equipment they sell. Device drivers
are programs that translate general operating system commands into specific references
to hardware details.
• Are There Rules in Assembly Language?
o Most rules in assembly language are based on physical limitations of the target
processor and its machine language.
o Java, for example, does not permit access to specific memory address.
o Assembly language, on the other hand, can access any memory address.

CMPS293&290 Class Notes (Chap 01) Page 4 /18 Kuo-pao Yang


1.1.2 Assembly language Applications 5

• Some representative types of applications:


o Business application for single platform: High-level language is better
o Hardware device driver: Assembly language is better
o Business application for multiple platforms: High-level language is better
o Embedded systems & computer games: Assembly language is better

Table 1-1 Comparing Assembly Language to High-Level Languages

CMPS293&290 Class Notes (Chap 01) Page 5 /18 Kuo-pao Yang


1.2 Virtual Machine Concept 7

• Programming Language analogy:


o Each computer has a native machine language (language L0) that runs directly on its
hardware
o A more human-friendly language is usually constructed above machine language, called
Language L1
• Programs written in L1 can run two different ways:
o Interpretation: L0 program interprets and executes L1 instructions one by one
o Translation: L1 program is completely translated into an L0 program, which then
runs on the computer hardware
• Java programming language is based on the virtual machine concept.
o A program written in the Java language is translated by a Java compiler into Java byte
code.
o The latter is a low-level language interprets and executed at run time by a program
known as a Java Virtual Machine (JVM).
o The JVM has been implemented on many different computer systems, making Java
programs relatively system independent.
• Translating Languages

CMPS293&290 Class Notes (Chap 01) Page 6 /18 Kuo-pao Yang


• Specific Machine Levels
o High-Level Language (Level 5):
ƒ Application-oriented languages such as C++, Java, Pascal, Visual Basic.
ƒ Programs in these languages contain powerful statements that translate into multiple
instructions at assembly language (Level 4)
o Assembly Language (Level 4):
ƒ Instruction mnemonics such as ADD, SUB, and MOV, which are easily translated to
machine language (Level 2). Instruction mnemonics that have a one-to-one
correspondence to machine language.
ƒ Calls functions written at the operating system level (Level 3)
ƒ Programs are translated into machine language (Level 2) before execution
o Operating System (Level 3):
ƒ Provides services to Level 4 programs
ƒ Translated and run at the instruction set architecture level (Level 2)
ƒ Operating System understands interactive commands by users to load and execute
programs, display directories, and so forth.
o Instruction Set Architecture (Level 2):
ƒ Also known as conventional machine language
ƒ Executed by microarchitecture (Level 1) program
ƒ Computer chip manufactures design into the processor an instruction set to carry out
basic operations, such as move, and, or multiply. Each machine-language instruction
is executed by several microinstructions.
o Microarchitecture (Level 1):
ƒ Interprets conventional machine instructions (Level 2)
ƒ Executed by digital hardware (Level 0)
ƒ The specific microarchitecture commands are often a proprietary secret.
o Digital Logic (Level 0):
ƒ CPU, Memory: Constructed from digital logic gates

Figure 1-1 Virtual Mahine Levels 0 through 5

CMPS293&290 Class Notes (Chap 01) Page 7 /18 Kuo-pao Yang


1.3 Data Representation 9

• Binary Numbers
o Translating between binary and decimal
• Binary Addition
• Integer Storage Sizes
• Hexadecimal Integers
o Translating between decimal and hexadecimal
o Hexadecimal subtraction
• Signed Integers
o Binary subtraction
• Character Storage

1.3.1 Binary Numbers 10

• Digits are 1 and 0: 1 = true; 0 = false


• MSB: Most Significant Bit
• LSB: Least Significant Bit
• Bit numbering:

• Each digit (bit) is either 1 or 0


• Each bit represents a power of 2:

• Every binary number is a sum of powers of 2

CMPS293&290 Class Notes (Chap 01) Page 8 /18 Kuo-pao Yang


• Translating Unsigned Binary to Decimal
o Weighted positional notation shows how to calculate the decimal value of each binary
bit:
dec = (Dn-1 ×2n-1)  (Dn-2 × 2n-2)  ...  (D1 × 21)  (D0 × 20)
D = binary digit

binary 00001001 = decimal 9:


(1 × 23) + (1 × 20) = 9

• Translating Unsigned Decimal to Binary


o Repeatedly divide the decimal integer by 2. Each remainder is a binary digit in the
translated value:

CMPS293&290 Class Notes (Chap 01) Page 9 /18 Kuo-pao Yang


1.3.2 Binary Addition 11

• Starting with the LSB, add each pair of digits, include the carry if present.

1.3.3 Integer Storage Sizes 12

• Large Measurements when referring to both memory and disk space

CMPS293&290 Class Notes (Chap 01) Page 10 /18 Kuo-pao Yang


1.3.4 Hexadecimal Integers 13

• Binary values are represented in hexadecimal.

• Translating Binary to Hexadecimal


o Each hexadecimal digit corresponds to 4 binary bits.
o Example: Translate the binary integer 000101101010011110010100 to hexadecimal:

• Converting Hexadecimal to Decimal


o Multiply each digit by its corresponding power of 16:

dec = (D3 × 163) + (D2 × 162) + (D1 × 161) + (D0 × 160)

o Example: Hex 1234 equals (1 × 163) + (2 × 162) + (3 × 161) + (4 × 160), or decimal 4,660.
o Example: Hex 3BA4 equals (3 × 163) + (11 * 162) + (10 × 161) + (4 × 160), or decimal
15,268.

• The power of 16 from 160 to 167

CMPS293&290 Class Notes (Chap 01) Page 11 /18 Kuo-pao Yang


• Converting Decimal to Hexadecimal

decimal 422 = 1A6 hexadecimal

• Hexadecimal Addition
o Divide the sum of two digits by the number base (16). The quotient becomes the carry
value, and the remainder is the sum digit.

• Hexadecimal Subtraction
o When a borrow is required from the digit to the left, add 16 (decimal) to the current
digit's value:

CMPS293&290 Class Notes (Chap 01) Page 12 /18 Kuo-pao Yang


1.3.5 Signed Integers 14

• The highest bit indicates the sign. 1 = negative,


0 = positive
o If the highest digit of a hexadecimal integer is > 7, the value is negative.
o Examples: 8A, C5, A2, 9D

• Forming the Two's Complement


o Negative numbers are stored in two's complement notation
o Represents the additive Inverse
o Note that 00000001 + 11111111 = 00000000

• Binary Subtraction
o When subtracting A – B, convert B to its two's complement
o Add A to (–B)

00001100 00001100
– 00000011 + 11111101
00001001
• Ranges of Signed Integers
o The highest bit is reserved for the sign. This limits the range:

CMPS293&290 Class Notes (Chap 01) Page 13 /18 Kuo-pao Yang


1.3.6 Character Storage 16

• Character sets
o Standard ASCII (0 – 127)
o Extended ASCII (0 – 255)
o ANSI (0 – 255)
o Unicode (0 – 65,535)
• Null-terminated String
o Array of characters followed by a null byte
• Numeric Data Representation
o pure binary can be calculated directly
o ASCII binary string of digits: "01010101"
o ASCII decimal string of digits: "65"
o ASCII hexadecimal string of digits: "9C"

CMPS293&290 Class Notes (Chap 01) Page 14 /18 Kuo-pao Yang


1.4 Boolean Operations 20

• Boolean algebra defines a set of operations on the values true and false.
• Boolean expression involves a Boolean operator and one or more operands.
• Boolean Algebra
o Based on symbolic logic, designed by George Boole
o Boolean expressions created from: NOT, AND, OR

• NOT
o Inverts (reverses) a boolean value
o Truth table for Boolean NOT operator:

Digital gate diagram for NOT:

• AND
o Truth table for Boolean AND operator:

Digital gate diagram for AND:

CMPS293&290 Class Notes (Chap 01) Page 15 /18 Kuo-pao Yang


• OR
o Truth table for Boolean OR operator:

Digital gate diagram for OR:

OR

• Operator Precedence
o The NOT operator has the highest precedence followed by AND and OR.
o To avoid ambiguity, use parentheses to force the initial evaluation of an expression.
o Examples showing the order of operations:

CMPS293&290 Class Notes (Chap 01) Page 16 /18 Kuo-pao Yang


1.4.1 Truth Tables for Boolean Functions 22

• A Boolean function has one or more Boolean inputs, and returns a single Boolean output.
• A truth table shows all the inputs and outputs of a Boolean function
o Example: ¬X ∨ Y

o Example: X ∨ ¬Y

o Example: (Y ∧ S) ∨ (X ∧ ¬S)

This Boolean function describes a multiplexer: two-input multiplexer

CMPS293&290 Class Notes (Chap 01) Page 17 /18 Kuo-pao Yang


1.5 Chapter Summary 23

• This book focuses on programming microprocessors compatible with the Intel IA-32
processor family, using the MS-Windows platform.
• Assembly language helps you learn how software is constructed at the lowest levels
• Assembly language has a one-to-one relationship with machine language.
• Assembly language is not portable because it is tied to a specific processor family.
• Virtual machine concept can be related to real-world computer layers, including digital logic,
microarchitecture, instruction set architecture, operating system, assembly language,
and high-level languages.
• Each layer in a computer's architecture is an abstraction of a machine. Layers can be
hardware or software.
• Boolean expressions are essential to the design of computer hardware and software
• A truth table is an effective way to show all possible inputs and output of a Boolean
function.

CMPS293&290 Class Notes (Chap 01) Page 18 /18 Kuo-pao Yang

You might also like