Download A Simple Example in VCpp-Assembly Language Programming-Lab Slides and more Slides Assembly Language Programming in PDF only on Docsity!
A Simple Example in VC++
docsity.com
First Glance at Assembly Language
English: Display the sum of A times B plus C.C++: cout << (A * B + C);Assembly Language:mov eax,Amul Badd eax,Ccall WriteInt
Intel Machine Language:A1 00000000F7 25 0000000403 05 00000008E8 00500000
docsity.com
First Glance at Assembly Language
Low-level language
Each instruction performs a much lower-level taskcompared to a high-level language instruction
Most high-level language instructions need more thanone assembly instruction
One-to-one correspondence between assemblylanguage and machine language instructions
For most assembly language instructions, there is amachine language equivalent
Directly influenced by the instruction set andarchitecture of the processor (CPU)
docsity.com
Comparisons with High-level Languages
Advantages of Assembly Languages Space-efficiency (e.g. hand-held device softwares, etc) Time-efficiency(e.g. Real-time applications, etc ) Accessibility to system hardwares(e.g., Network interfaces, device drivers, video games, etc)
Advantages of High-level Languages Development Maintenance (Readability) Portability (compiler, virtual machine) docsity.com
This Course
Why Taking the Course?
Basic Concepts of
Computer
Organization
Computer Design
System
Software
Computer OrganizationComputer Architecture
Assembler, Linker, Loader
Compiler, Operating System, …
AssemblyLanguage
docsity.com
Time Comparison
Number of calls (in millions)
Time (seconds)
Multiplication time comparison on a 2.4-GHz Pentium 4 system
C version
ASM version
docsity.com
Assembly Language
Level 4
Instruction mnemonics that have a one-to-one correspondence to machinelanguage
Calls functions written at the operatingsystem level (Level 3)
Programs are translated into machinelanguage (Level 2)
docsity.com
Operating System
Level 3
Provides services to Level 4 programs
Translated and run at the instruction setarchitecture level (Level 2)
docsity.com
Microarchitecture
Level 1
Interprets conventional machineinstructions (Level 2)
Executed by digital hardware (Level 0)
docsity.com
Digital Logic
Level 0
CPU, constructed from digital logic gates
System bus
Memory
docsity.com
Accessing Parts of Registers
Use 8-bit name, 16-bit name, or 32-bit name
Applies to EAX, EBX, ECX, and EDX
AH AL 16 bits 8 AX EAX 8 8 bits + 8 bits 32 bits docsity.com
Some specialized register uses
General-Purpose
EAX – accumulator (automatically used by divisionand multiplication)
ECX – loop counter
ESP – stack pointer (should never be used forarithmetic or data transfer)
ESI, EDI – index registers (used for high-speedmemory transfer instructions)
EBP – extended frame pointer (stack)
docsity.com
Status Flags
•^
Carry (CF)
unsigned arithmetic out of range
•^
Overflow (OF)
signed arithmetic out of range
•^
Sign (SF)
result is negative
•^
Zero (ZF)
result is zero
•^
Auxiliary Carry (AC)
carry from bit 3 to bit 4 in 8-bit operand
•^
Parity (PF)
sum of 1 bits in least-significant byte is an evennumber
docsity.com
Assembly language Statements
Three types of assembly language statements
Instructions
Directives
Macros
docsity.com