Upload
vungoc
View
231
Download
6
Embed Size (px)
Citation preview
Assembly Disc
Eng Alaa.I.Haniya
Assembly and Machine Language
Machine language Native to a processor: executed directly by hardware
Instructions consist of binary code: 1s and 0s
Assembly language
Slightly higher-level language Readability of instructions is better than machine language
Assembly and Machine Language
Assemblers translate assembly to machine code
Compilers translate high-level programs to machine code
Either directly, or Indirectly via an assembler
Compiler and Assembler
Faster
Easier
Portable.
So
Why Learn Assembly Language?
Advantages of High-Level
Languages
Programs in high level language are portable; However,
Assembly language programs are not portable.
A portable application (portable app), sometimes also called standalone, is a computer program designed to run independently from an operating system.
Portable versions of applications can usually also be used instead of the normal installable version, which some users find useful
• Machine code or machine language is a system of impartible instructions executed directly by a computer's central processing unit (CPU).
• Instructions consist of binary code: 1s and 0s
• An assembly language: is a low-level programming language that is very similar to machine language, but uses symbols instead of binary numbers.
• Slightly higher-level language
Basic Concepts
An assembler is a program that converts source-code programs written in assembly language into object files in machine language.
Assembler Examples:
• MASM (Macro Assembler from Microsoft),
• TASM (Turbo Assembler from Borland)
• NASM (Netwide Assembler for both Windows and Linux),
Basic Concepts
A linker is a program that combines individual files created by an assembler into a single executable program .
A debugger is a program that allows you to trace the execution of a program and examine the content of registers and memory.
Compilers translate high-level programs to machine code either directly or indirectly via an assembler.
Basic Concepts
Storage Sizes
Integer Storage Sizes
Standard sizes:
byte 8
word 16
doubleword 32
quadword 64
What is the largest unsigned integer that may be stored in 20 bits?
Ranges of Signed Integers
The unsigned range is divided into two signed ranges for positive
and negative numbers
Practice: What is the range of signed values that may be stored in 20 bits?
Carry and Overflow
Overflow occurs when
Adding two positive numbers and the sum is negative
Adding two negative numbers and the sum is positive
Can happen because of the fixed number of sum bits
Carry and Overflow Examples
We can have carry without overflow and vice-versa
Four cases are possible
1
1
1
1
1
1
0
0
0
0
1
1
1
1
15
0
0
0
0
1
1
1
1
15 +
+ 0
0
0
0
1
0
0
0
8
1
1
1
1
1
0
0
0
245 (-8)
0
0
0
1
0
1
1
1
23
0
0
0
0
0
1
1
1
7
Carry = 0 Overflow = 0
Carry = 1 Overflow = 0
1
1
1
1
0
1
0
0
1
1
1
1
79
1
1
0
1
1
0
1
0
218 (-38) +
+ 0
1
0
0
0
0
0
0
64
1
0
0
1
1
1
0
1
157 (-99)
1
0
0
0
1
1
1
1
143
0
1
1
1
0
1
1
1
119 (-113)
Carry = 0 Overflow = 1
Carry = 1 Overflow = 1
Character Storage
• Standard ASCII: 7-bit character codes (0 – 127)
• Extended ASCII: 8-bit character codes (0 – 255)
ASCII code
ASCII code for space character ? = 20 H= 32 D. ASCII code for 'L' ? 4C H= 76 D. ASCII code for 'a' ? 61 H= 97 D
Control character codes = 00 to 1F (hex)
Examples of Control Characters
• Character 0 is the NULL character, used to terminate a string
• Character 9 is the Horizontal Tab (HT) character
• Character 0A (hex) = 10 (decimal) is the Line Feed (LF)
• Character 0D (hex) = 13 (decimal) is the Carriage Return (CR)
• The LF and CR characters are used together , they advance the cursor to the beginning of next line
Control Characters
What is the largest value you can represent using a 256-bit unsigned integer?
Sol: (2^ 256)-1
What is the largest positive value you can represent using a 256-bit signed integer?
Sol: + 2255-1
Question