0% found this document useful (0 votes)
19 views

Chapter 1 • Basic Concepts

Uploaded by

hero7862541x
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Chapter 1 • Basic Concepts

Uploaded by

hero7862541x
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Chapter 1 • Basic Concepts

What Are Assemblers and Linkers?


An assembler is a utility program that converts source code programs from
assembly language into machine language. A linker is a utility program that
combines individual files created by an assembler into a single executable program.
A related utility called a debugger, lets you step through a program while it’s running
and examine registers and memory.

How Does Assembly Language Relate to Machine Language?


Machine language is a numeric language specifically understood by a computer’s
processor (the CPU). All x86 processors understand a common machine language.
Assembly language consists of statements written with short mnemonics such as
ADD, MOV, SUB, and CALL. 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?
High-level languages such as C++ and Java have a one-to-many relationship with
assembly language and machine language. A single statement in C++ expands into
multiple assembly languages or machine instructions. We can show how C++
statements expand into machine code. Most people cannot read raw machine code,
so we will use its closest relative, assembly language. The following C++ code carries
out two arithmetic operations and assigns the result to a variable. Assume X and Y
are integers:
int Y;
int X = (Y + 4) * 3;

Following is the equivalent 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
(Registers are named storage locations in the CPU that hold intermediate results of
operations.) The point in this example is not to claim that C++ is superior to assembly
language or vice versa, but to show their relationship.

Portable Code

Portable code can run on different computer systems with little or no modification. It
uses standard programming practices and avoids system-specific features.
Languages like Java achieve portability by running on an intermediate platform like
the JVM.

Non-Portable Code

Non-portable code is designed for a specific hardware or operating system and


cannot be easily transferred to other systems. Assembly language is an example
because it directly corresponds to a processor's unique architecture and instruction
set.

Microcode Interpreter

A microcode interpreter is embedded in a processor to translate higher-level


machine instructions into detailed hardware operations. It acts as an intermediary
layer, enabling flexibility and supporting complex instruction sets while simplifying
hardware design.

Why Learn Assembly Language?

1. Embedded Programming: Ideal for writing efficient, memory-economical


programs for single-purpose devices like telephones or security systems.
2. Real-Time Applications: Offers precise control over machine code, essential
for tasks requiring exact timing.
3. Game Development: Enables optimized, hardware-specific code for fast
execution and small size.
4. Understanding Hardware: Provides insight into hardware, OS, and application
interaction, enhancing computer architecture knowledge.
5. Low-Level Tasks: Simplifies bit manipulation and other tasks where high-level
languages struggle.
6. Device Drivers: Device drivers are programs that translate general operating
system commands into specific references to hardware details. Printer
manufacturers, for example, create a different MS-Windows device driver for
each model they sell. The same is true for Mac OS, Linux, and other operating
systems.

Are There Rules in Assembly Language?

Assembly language rules are based on the processor's limitations, like requiring
operands to be the same size. It has fewer rules than high-level languages like C++
or Java, which restrict low-level access to prevent errors. Assembly allows direct
memory access but requires more debugging effort due to its freedom and
complexity.

Assembly Language Applications

In the past, most programs were written in assembly language due to limited
memory and slow processors. With faster processors and larger memory,
programmers shifted to high-level languages like C, FORTRAN, and later
object-oriented languages like C++ and Java for complex applications. Today,
assembly language is rarely used for entire programs but is employed to optimize
critical sections for speed and hardware access.
Questions 🙂
How do assemblers and linkers work together?
Assemblers translate assembly language code into machine code, producing object
files. Linkers then combine these object files, resolving references between them to
create a single executable program.

How will studying assembly language enhance your understanding of operating


systems?
Learning assembly language provides insight into how operating systems interact
with hardware, manage resources, and execute low-level operations, deepening
your understanding of system-level programming.

What is meant by a one-to-many relationship when comparing a high-level


language to machine language?
A single high-level language statement can translate into multiple machine
language instructions, reflecting a one-to-many relationship between high-level
code and machine code.

Explain the concept of portability as it applies to programming languages.


Portability refers to a program's ability to run on different hardware or operating
systems with minimal modification, achieved by using high-level languages that
abstract hardware-specific details.

Is the assembly language for x86 processors the same as those for computer
systems such as the VAX or Motorola 68x00?
No, assembly languages are specific to each processor's architecture. The x86, VAX,
and Motorola 68x00 have distinct instruction sets and assembly languages.

Give an example of an embedded systems application.


Embedded systems applications include devices like telephones, automobile fuel
and ignition systems, air-conditioning control systems, security systems, data
acquisition instruments, video cards, sound cards, hard drives, modems, and
printers.

What is a device driver?


A device driver is software that translates general operating system commands into
specific instructions for hardware devices, enabling the OS to communicate with
hardware components.

Do you suppose type checking on pointer variables is stronger (stricter) in


assembly language or in C and C++?
Type checking is stricter in C and C++ because these languages enforce type safety,
whereas assembly language allows direct memory access without type constraints.

Name two types of applications that would be better suited to assembly language
than a high-level language.
Applications requiring direct hardware access and those needing highly optimized
code for performance, such as embedded systems and computer games, are better
suited to assembly language.
Why would a high-level language not be an ideal tool for writing a program that
directly accesses a particular brand of printer?
High-level languages may not provide the necessary low-level access to
hardware-specific features of a particular printer, making assembly language more
suitable for such tasks.

Why is assembly language not usually used when writing large application
programs?
Assembly language is time-consuming to write and maintain, making it impractical
for large applications compared to high-level languages that offer more abstraction
and efficiency.

Challenge: Translate the following C++ expression to assembly language, using


the example presented earlier in this chapter as a guide: X = (Y * 4) + 3.

; Assuming Y is in register EAX

MOV EBX, EAX ; Copy Y to EBX

SHL EBX, 2 ; Multiply Y by 4 (shift left by 2)

ADD EBX, 3 ; Add 3

MOV EAX, EBX ; Store result in EAX

Virtual Machine Concept

The virtual machine concept explains how hardware and software interact to
execute programs.

1. Native Language (L0): Computers run programs in their basic machine


language (L0), which is detailed and hard for humans to use.
2. Higher-Level Language (L1): Easier languages (L1) are created to simplify
programming. L1 can work in two ways:
○ Interpretation: An L0 program decodes and executes L1 instructions as
they run.
○ Translation: An L1 program is fully converted into L0 before execution.

A virtual machine is a software program that emulates a physical or virtual


computer. For example, VM1 runs commands written in L1, while VM0 runs L0
commands.

○ Virtual machines (VMs) can be implemented in hardware or software.


○ Programs written for one VM (e.g., VM1) can either run directly on
hardware or be interpreted/translated to run on a lower-level VM (e.g.,
VM0).
○ To make programming easier, higher-level VMs (e.g., VM2, VM3, etc.)
can be added, each supporting more user-friendly languages.

Java Virtual Machine (JVM):

○ Java uses this concept. Java programs are compiled into Java
bytecode (a low-level language).
○ The JVM interprets this bytecode and executes it, making Java
programs system-independent.

Programming Levels in Computers


1. Level 1: Digital Logic Hardware
○ Represents the base hardware of the computer.
2. Level 2: Instruction Set Architecture (ISA)
○ The ISA defines machine language instructions (e.g., move, add,
multiply) that hardware can directly execute.
○ These instructions may run via hardware or an embedded
microprogram.
3. Level 3: Assembly Language
○ Uses mnemonics (e.g., ADD, MOV) that are easier for programmers to
write and read.
○ Assembly code is fully translated (assembled) into machine language
before execution.
4. Level 4: High-Level Languages
○ High-level languages (e.g., C, C++, Java) offer powerful, user-friendly
commands.
○ Each high-level instruction translates into multiple assembly language
instructions, simplifying large-scale software development.
○ Compilers translate high-level programs into assembly and machine
language automatically.
Questions 🙂
Virtual Machine Concept
Virtual machines are layers that emulate computer systems, allowing programs
written at higher levels to run on lower-level hardware or software platforms.
Why not use machine language?
Machine language is too detailed and complex for humans, making it error-prone
and inefficient for developing large applications.
True/False
True: Interpreted programs in L1 are decoded and executed by a program written in
L0.
Translation Technique
Translation converts a program from a higher-level language (e.g., L1) into an
equivalent lower-level language (e.g., L0) before execution.
Assembly Language Level
Assembly language appears at Level 3 in the virtual machine hierarchy.
Java Execution Software
The Java Virtual Machine (JVM) allows compiled Java programs to run on almost
any computer.
Virtual Machine Levels
(From lowest to highest):

1. Digital Logic Hardware (Level 1)


2. Instruction Set Architecture (ISA) (Level 2)
3. Assembly Language (Level 3)
4. High-Level Languages (Level 4)

Why avoid machine language?


It is error-prone, time-consuming, and lacks the abstraction needed for modern
software development.
Machine Language Level
Machine language is used at Level 2 (ISA).
Assembly Language Translation
Assembly language statements are translated into machine language (Level 2).
Data Representation

1. Number Systems:
○ Numbers are represented in different bases: binary (base 2), decimal (base 10),
and hexadecimal (base 16).
○ Binary uses 0 and 1, while hexadecimal uses digits 0-9 and letters A-F (for
values 10-15).
2. Binary Numbers:
○ Binary digits (bits) can be 0 or 1, representing electronic on/off states.
○ MSB (Most Significant Bit) is the leftmost bit; LSB (Least Significant Bit) is the
rightmost bit.

Unsigned Binary Integers

1. Decimal to Binary Conversion:


○ Divide the number by 2 repeatedly, saving remainders. Write the remainders in
reverse to form the binary number.
2. Binary to Decimal Conversion:
○ Use positional notation: multiply each bit by 2^n, where n is its position from right
to left, starting at 0.
Binary Addition

1. Rules for Adding Bits:


2. Steps for Addition:
○ Start from the right (LSB), add bit pairs, and handle carries.

3. Overflow:
○ If the sum exceeds the bit limit (e.g., adding 11111111 + 1), the result wraps
around (e.g., 00000000 for 8 bits).

Integer Storage Sizes


Hexadecimal Integers

● Hexadecimal Representation:
○ Each hexadecimal digit represents 4 binary bits, making it easier to read large
binary numbers.
○ Hexadecimal uses digits 0-9 and letters A-F (for decimal 10-15).
○ Two hexadecimal digits together represent one byte (8 bits).

Converting Hexadecimal to Decimal

● Each hex digit represents a power of 16.

Converting Decimal to Hexadecimal

● To convert from decimal to hexadecimal, divide by 16 repeatedly and record the


remainders.
○ Example: Decimal 422 = Hex 1A6.

Signed Integers

○ These can be positive or negative.


○ On x86 processors, the most significant bit (MSB) indicates the sign: 0 for
positive and 1 for negative.

Two’s-Complement Notation

○ Used to represent negative integers.


○ It’s the additive inverse: adding a number to its two’s complement results in
zero.
○ To find the two’s complement of a binary number:
1. Invert the bits (change 0s to 1s and vice versa).
2. Add 1 to the result.
In hexa decimal 2’s complement

Converting Signed Binary to Decimal

1. If the highest bit is 1 (negative number):


○ Find the two’s complement of the number to get its positive equivalent.
○ Convert the result to decimal as if it were unsigned.
2. If the highest bit is 0 (positive number):
○ Convert directly to decimal as an unsigned binary.

Example:
For signed binary 11110000, the highest bit is 1, so:

● Create the two’s complement (00001111).


● Convert 00001111 to decimal (15), then apply a negative sign: −16.

Converting Signed Decimal to Binary

1. Convert the absolute value of the decimal to binary.


2. If the original number is negative, find the two’s complement of the binary result.

Example:
For −43:

1. Binary of 43: 00101011.


2. Two’s complement of 00101011: 11010101 (representing −43).

Converting Signed Decimal to Hexadecimal

1. Convert the absolute value to hexadecimal.


2. If the original number is negative, find the two’s complement of the hexadecimal
number.

Converting Signed Hexadecimal to Decimal

1. If the hexadecimal number is negative, find its two’s complement.


2. Convert the result to decimal, adding a negative sign if the original value was negative.
Maximum and Minimum Values

A signed integer of n bits uses only n-1 bits to represent the number’s magnitude.

Character Storage

Computers store characters using character sets, which map characters to integers.

1. ASCII (American Standard Code for Information Interchange):


○ Uses 7 bits to represent characters (128 total).
○ The 8th bit in a byte is used for additional symbols in extended ASCII (values
128–255), e.g., graphics or special characters.
2. ANSI (American National Standards Institute):
○ An 8-bit character set with 256 characters.
○ The first 128 characters are standard keyboard symbols, and the next 128
represent special characters (e.g., accented letters, currency symbols).
3. Unicode:
○ A universal character encoding standard for all major languages and scripts,
supporting more characters than ASCII or ANSI.
○ Encoding formats:
■ UTF-8: Variable-length, compatible with ASCII (1 to 4 bytes).
■ UTF-16: 16-bit encoding, used in environments like Windows.
■ UTF-32: Fixed 32-bit encoding, used where space isn't a concern.

ASCII Strings

● ASCII String: A sequence of ASCII characters stored in memory as bytes (e.g.,


"ABC123" is 41h, 42h, 43h, 31h, 32h, 33h).
● Null-Terminated String: Ends with a 0 byte, common in C/C++.

ASCII Control Characters

● Codes 0–31 in ASCII are control characters, used for actions like backspace, line feed,
and carriage return.
Example:
○ Code 8: Backspace
○ Code 10: Line feed

Terminology for Numeric Data Representation

● Binary Integer: A number in raw binary form, ready for computation.


● ASCII Digit String: A string of ASCII characters representing a number, e.g., "123".

For example, decimal 65 is stored as 01000001 in binary, displayed as 41 in hexadecimal, and


represents the letter "A" in ASCII.

Questions 🙂
Least Significant Bit (LSB): The rightmost bit in a binary number, which represents the
smallest value (2^0 or 1).

Most Significant Bit (MSB): The leftmost bit in a binary number, representing the largest value
(highest power of 2).

Decimal representations of unsigned binary numbers:

● a. 11111000 = 248
● b. 11001010 = 202
● c. 11110000 = 240

Decimal representations of unsigned binary numbers:

● a. 00110101 = 53
● b. 10010110 = 150
● c. 11001100 = 204

Sum of binary pairs:

● a. 00001111 + 00000010 = 00010001 = 17


● b. 11010101 + 01101011 = 10100000 = 160
● c. 00001111 + 00001111 = 00011110 = 30

Sum of binary pairs:

● a. 10101111 + 11011011 = 11001010 = 202


● b. 10010111 + 11111111 = 11010110 = 214
● c. 01110101 + 10101100 = 10110001 = 177

Bytes in data types:

● a. Word = 2 bytes
● b. Doubleword = 4 bytes
● c. Quadword = 8 bytes

Bits in data types:

● a. Word = 16 bits
● b. Doubleword = 32 bits
● c. Quadword = 64 bits

Minimum binary bits for unsigned decimals:

● a. 65 = 7 bits
● b. 256 = 9 bits
● c. 32768 = 15 bits

Minimum binary bits for unsigned decimals:

● a. 4095 = 12 bits
● b. 65534 = 16 bits
● c. 2134657 = 22 bits

Hexadecimal representations of binary numbers:

● a. 1100111101010111 = CF57
● b. 0101110010101101 = 5CAD
● c. 1001001111101011 = 93EB

Hexadecimal representations of binary numbers:

● a. 0011010111011010 = 35DA
● b. 1100111010100011 = CEA3
● c. 1111111011011011 = FEDB

Binary representations of hexadecimal numbers:

● a. E5B6AED7 = 11100101101101101010111011010111
● b. B697C7A1 = 10110110100101111000011110100001
● c. 234B6D92 = 00100011010010110110110110010010

Binary representations of hexadecimal numbers:

● a. 0126F9D4 = 00000001001001101111100111010100
● b. 6ACDFA95 = 01101000110011011111101010010101
● c. F69BDC2A = 11110110100110111111001010101010
Unsigned decimal representation of hexadecimal numbers:

● a. 3A = 58
● b. 1BF = 447
● c. 4096 = 16,384

Unsigned decimal representation of hexadecimal numbers:

● a. 62 = 98
● b. 1C9 = 457
● c. 6A5B = 27,339

16-bit hexadecimal representation of signed decimals:

● a. -26 = FFDA
● b. -452 = FFCD

16-bit hexadecimal representation of signed decimals:

● a. -32 = FFE0
● b. -62 = FF9E

Convert 16-bit signed hexadecimal numbers to decimal:

● a. 7CAB = 31,195
● b. C123 = -3,869

Convert 16-bit signed hexadecimal numbers to decimal:

● a. 7F9B = 32,827
● b. 8230 = -31,744

Decimal representation of signed binary numbers:

● a. 10110101 = -75
● b. 00101010 = 42
● c. 11110000 = -16

Decimal representation of signed binary numbers:

● a. 10000000 = -128
● b. 11001100 = -52
● c. 10110111 = -73
8-bit two’s complement binary representation:

● a. -5 = 11111011
● b. -36 = 11011100
● c. -16 = 11110000

8-bit two’s complement binary representation:

● a. -72 = 10111000
● b. -98 = 10011110
● c. -26 = 11100110

Hexadecimal and decimal representations of ASCII "X":

● Hexadecimal: 58
● Decimal: 88

Hexadecimal and decimal representations of ASCII "M":

● Hexadecimal: 4D
● Decimal: 77

Why Unicode was invented:


To provide a universal character encoding standard that supports characters and symbols from
all major world languages and scripts.

Largest value with a 256-bit unsigned integer:

Largest positive value with a 256-bit signed integer:

Boolean Operations

Boolean algebra defines a set of operations on the values true and false. It was invented by
George Boole, a mid-nineteenth-century mathematician. Boolean operations are mathematical
operations used to work with true/false values. They are essential in digital circuits and
programming.

Boolean Expression A boolean expression involves a boolean operator and one or more
operands. Each boolean expression implies a value of true or false. The set of operators
includes the folllowing:

The main operations are:

1. NOT (¬ or ~): Reverses a boolean value (true becomes false, and vice versa).

2. AND (∧): Both operands must be true for the result to be true.

3. OR (∨): At least one operand must be true for the result to be true.
Operator Precedence:

1. NOT has the highest precedence.


2. AND comes next.
3. OR has the lowest precedence.
○ Example: In ¬X ∨ Y, NOT is evaluated first, followed by OR.
Boolean Functions:

A boolean function takes boolean inputs and produces a boolean output. Truth tables show all
input/output combinations.
This boolean function describes a multiplexer, a digital component that uses a selector bit (S)

to select one of two outputs (X or Y). If S false, the function output (Z) is the same as X. If

S true, the function output is the same as Y.

Questions 🙂
1. Describe the following boolean expression: ¬X ∨ Y.
○ This expression means NOT X OR Y. The output is true if either X is false or Y is
true.
2. Describe the following boolean expression: (X ∧ Y).
○ This expression means X AND Y. The output is true only if both X and Y are true.
3. What is the value of the boolean expression (T ∧ F) ∨ T?
○ The value is T. First, (T ∧ F) is F, and then F ∨ T is T.
4. What is the value of the boolean expression ¬(F ∨ T)?
○ The value is F. (F ∨ T) is T, and then NOT T is F.
5. What is the value of the boolean expression ¬F ∨ ¬T?
○ The value is T. ¬F is T and ¬T is F, so T ∨ F is T.
6. Create a truth table to show all possible inputs and outputs for the boolean
function described by ¬(A ∨ B).

7. Create a truth table to show all possible inputs and outputs for the boolean
function described by (¬A ∧ ¬B).

8. If a boolean function has four inputs, how many rows are required for its truth table?

○ A truth table with four inputs will require 16 rows (2^4 = 16).
9. How many selector bits are required for a four-input multiplexer?
○ A four-input multiplexer requires 2 selector bits (since 2^2 = 4).

You might also like