Assembly Language Programming
Chapter 1
Introduction
Analyze the program segment
beta = 5;
alpha = beta + 3;
mov byte ptr beta, 5
mov al, beta
add al, 3
mov alpha, al
C606000105
A00001
0403
A20002
High Level
Language
Assembly
Language
Machine
Language
Analyze the program segment
External Memory
03000 C6
03001 06
}mov byte ptr <address>, <value>
}
03002 00
03003 01
}0100 or beta
}
03004 05 }05
03005 A0}mov al, <address>
03006 00
03007 01
}0100 or beta
}
03008 04}add al, <value>
03009 03 }03
0300A A2}mov <address>, al
0300B 00
0300C 02
}0200 or alpha
}
mov byte ptr beta, 5
mov al, beta
add al, 3
mov alpha, al
C606000105
A00001
0403
A20002
Von Neumann architecture
External
Memory
MPUI/O
• has three basic hardware subsystems
control bus
data bus
address busaddress bus
data bus
control bus
Von Neumann architecture
External
Memory
MPUI/O
• the three basic hardware subsystems are
interconnected by three buses
control bus
data bus
address busaddress bus
data bus
control bus
Von Neumann architecture
External
Memory
MPUI/O
• program (actual code or instructions) and
data (i.e. variables) are stored in the main memory and
not in the MPU
control bus
data bus
address busaddress bus
data bus
control bus
Von Neumann architecture
External
Memory
MPUI/O
• instructions in the main memory are
fetched, decoded, and executed sequentially
MEM READ
03000
Von Neumann architecture
FETCH
MPU fetches the next instruction by specifying its
location in the address bus and specifying a
MEMORY READ control signal in the control bus
External Memory
03000 C6
03001 06
03002 00
03003 01
03004 05
03005 A0
03006 00
03007 01
03008 04
03009 03
0300A A2
0300B 00
0300C 02
control bus
data bus
address bus
MPU
Instruction
Fetched:
MEM READ
C6
03000
Von Neumann architecture
FETCH
External Memory will give data (which in this case
is actually part of an instruction) based on the
address specified by the MPU thru the address bus
External Memory
03000 C6
03001 06
03002 00
03003 01
03004 05
03005 A0
03006 00
03007 01
03008 04
03009 03
0300A A2
0300B 00
0300C 02
control bus
data bus
address bus
MPU
Instruction
Fetched:
Von Neumann architecture
DECODE
MPU will try to decode the instruction fetched. If
the instruction is already complete, it will proceed
with the execute phase, otherwise it will do
additional fetch(es) until instruction is complete
External Memory
03000 C6
03001 06
03002 00
03003 01
03004 05
03005 A0
03006 00
03007 01
03008 04
03009 03
0300A A2
0300B 00
0300C 02
control bus
data bus
address bus
MPU
Instruction
Fetched:
C6
this is not
yet
complete
Von Neumann architecture
DECODE
MPU will try to decode the instruction fetched. If
the instruction is already complete, it will proceed
with the execute phase, otherwise it will do
additional fetch(es) until instruction is complete
External Memory
03000 C6
03001 06
03002 00
03003 01
03004 05
03005 A0
03006 00
03007 01
03008 04
03009 03
0300A A2
0300B 00
0300C 02
control bus
data bus
address bus
MPU
Instruction
Fetched:
C606000105
mov byte
ptr [0100],
05
Von Neumann architecture
EXECUTE
the MPU will start to execute the instruction
previously decoded
External Memory
03000 C6
03001 06
03002 00
03003 01
03004 05
03005 A0
03006 00
03007 01
03008 04
03009 03
0300A A2
0300B 00
0300C 02
control bus
data bus
address bus
MPU
Instruction
Fetched:
C606000105
executing:
mov byte
ptr [0100],
05
Why Assembly Language
TITLE Hello World Program
DOSSEG
.MODEL SMALL
.STACK 100h
.DATA
GREET DB "Hello World!", 10, 13, "$"
.CODE
BEGIN:MOV AX, @DATA
MOV DS, AX
MOV ES, AX
LEA DX, [GREET]
MOV AH, 09h
INT 21h
MOV AL, 00h
MOV AH, 4Ch
INT 21h
END BEGIN
#include <stdio.h>
void main()
{
printf(“Hello World!”);
}
High Level LanguageAssembly Language
Why Assembly Language
TITLE Hello World Program
DOSSEG
.MODEL SMALL
.STACK 100h
.DATA
GREET DB "Hello World!", 10, 13, "$"
.CODE
BEGIN:MOV AX, @DATA
MOV DS, AX
MOV ES, AX
LEA DX, [GREET]
MOV AH, 09h
INT 21h
MOV AL, 00h
MOV AH, 4Ch
INT 21h
END BEGIN
#include <stdio.h>
void main()
{
printf(“Hello World!”);
}
High Level LanguageAssembly Language
COMPACT CODE
Why Assembly Language
TITLE Hello World Program
DOSSEG
.MODEL SMALL
.STACK 100h
.DATA
GREET DB "Hello World!", 10, 13, "$"
.CODE
BEGIN:MOV AX, @DATA
MOV DS, AX
MOV ES, AX
LEA DX, [GREET]
MOV AH, 09h
INT 21h
MOV AL, 00h
MOV AH, 4Ch
INT 21h
END BEGIN
#include <stdio.h>
void main()
{
printf(“Hello World!”);
}
High Level LanguageAssembly Language
SPEED
Why Assembly Language
TITLE Hello World Program
DOSSEG
.MODEL SMALL
.STACK 100h
.DATA
GREET DB "Hello World!", 10, 13, "$"
.CODE
BEGIN:MOV AX, @DATA
MOV DS, AX
MOV ES, AX
LEA DX, [GREET]
MOV AH, 09h
INT 21h
MOV AL, 00h
MOV AH, 4Ch
INT 21h
END BEGIN
#include <stdio.h>
void main()
{
printf(“Hello World!”);
}
High Level LanguageAssembly Language
FLEXIBLE
Why NOT Assembly Language
TITLE Hello World Program
DOSSEG
.MODEL SMALL
.STACK 100h
.DATA
GREET DB "Hello World!", 10, 13, "$"
.CODE
BEGIN:MOV AX, @DATA
MOV DS, AX
MOV ES, AX
LEA DX, [GREET]
MOV AH, 09h
INT 21h
MOV AL, 00h
MOV AH, 4Ch
INT 21h
END BEGIN
#include <stdio.h>
void main()
{
printf(“Hello World!”);
}
High Level LanguageAssembly Language
EASY TO LEARN
Why NOT Assembly Language
TITLE Hello World Program
DOSSEG
.MODEL SMALL
.STACK 100h
.DATA
GREET DB "Hello World!", 10, 13, "$"
.CODE
BEGIN:MOV AX, @DATA
MOV DS, AX
MOV ES, AX
LEA DX, [GREET]
MOV AH, 09h
INT 21h
MOV AL, 00h
MOV AH, 4Ch
INT 21h
END BEGIN
#include <stdio.h>
void main()
{
printf(“Hello World!”);
}
High Level LanguageAssembly Language
PREDEFINED FUNCTIONS
Why NOT Assembly Language
TITLE Hello World Program
DOSSEG
.MODEL SMALL
.STACK 100h
.DATA
GREET DB "Hello World!", 10, 13, "$"
.CODE
BEGIN:MOV AX, @DATA
MOV DS, AX
MOV ES, AX
LEA DX, [GREET]
MOV AH, 09h
INT 21h
MOV AL, 00h
MOV AH, 4Ch
INT 21h
END BEGIN
#include <stdio.h>
void main()
{
printf(“Hello World!”);
}
High Level LanguageAssembly Language
PORTABILITY
History of Microprocessor
Name Date Transistors Microns
Clock
speed
Data
width MIPS
8080 1974 6,000 6 2 MHz 8 bits 0.64
16 bits
8-bit bus
80286 1982 134,000 1.5 6 MHz 16 bits 1
80386 1985 275,000 1.5 16 MHz 32 bits 5
80486 1989 1,200,000 1 25 MHz 32 bits 20
32 bits
64-bit bus
32 bits
64-bit bus
32 bits
64-bit bus
32 bits
64-bit bus
8088 1979 29,000 3
Pentium 1993 3,100,000 0.8
7,500,000 0.35
5 MHz 0.33
60 MHz 100
233
MHz ~300
Pentium III 1999 9,500,000 0.25
450
MHz ~510
Pentium II 1997
1.5 GHz ~1,700Pentium 4 2000 42,000,000 0.18

Introduction to 8088 microprocessor

  • 1.
  • 2.
    Analyze the programsegment beta = 5; alpha = beta + 3; mov byte ptr beta, 5 mov al, beta add al, 3 mov alpha, al C606000105 A00001 0403 A20002 High Level Language Assembly Language Machine Language
  • 3.
    Analyze the programsegment External Memory 03000 C6 03001 06 }mov byte ptr <address>, <value> } 03002 00 03003 01 }0100 or beta } 03004 05 }05 03005 A0}mov al, <address> 03006 00 03007 01 }0100 or beta } 03008 04}add al, <value> 03009 03 }03 0300A A2}mov <address>, al 0300B 00 0300C 02 }0200 or alpha } mov byte ptr beta, 5 mov al, beta add al, 3 mov alpha, al C606000105 A00001 0403 A20002
  • 4.
    Von Neumann architecture External Memory MPUI/O •has three basic hardware subsystems
  • 5.
    control bus data bus addressbusaddress bus data bus control bus Von Neumann architecture External Memory MPUI/O • the three basic hardware subsystems are interconnected by three buses
  • 6.
    control bus data bus addressbusaddress bus data bus control bus Von Neumann architecture External Memory MPUI/O • program (actual code or instructions) and data (i.e. variables) are stored in the main memory and not in the MPU
  • 7.
    control bus data bus addressbusaddress bus data bus control bus Von Neumann architecture External Memory MPUI/O • instructions in the main memory are fetched, decoded, and executed sequentially
  • 8.
    MEM READ 03000 Von Neumannarchitecture FETCH MPU fetches the next instruction by specifying its location in the address bus and specifying a MEMORY READ control signal in the control bus External Memory 03000 C6 03001 06 03002 00 03003 01 03004 05 03005 A0 03006 00 03007 01 03008 04 03009 03 0300A A2 0300B 00 0300C 02 control bus data bus address bus MPU Instruction Fetched:
  • 9.
    MEM READ C6 03000 Von Neumannarchitecture FETCH External Memory will give data (which in this case is actually part of an instruction) based on the address specified by the MPU thru the address bus External Memory 03000 C6 03001 06 03002 00 03003 01 03004 05 03005 A0 03006 00 03007 01 03008 04 03009 03 0300A A2 0300B 00 0300C 02 control bus data bus address bus MPU Instruction Fetched:
  • 10.
    Von Neumann architecture DECODE MPUwill try to decode the instruction fetched. If the instruction is already complete, it will proceed with the execute phase, otherwise it will do additional fetch(es) until instruction is complete External Memory 03000 C6 03001 06 03002 00 03003 01 03004 05 03005 A0 03006 00 03007 01 03008 04 03009 03 0300A A2 0300B 00 0300C 02 control bus data bus address bus MPU Instruction Fetched: C6 this is not yet complete
  • 11.
    Von Neumann architecture DECODE MPUwill try to decode the instruction fetched. If the instruction is already complete, it will proceed with the execute phase, otherwise it will do additional fetch(es) until instruction is complete External Memory 03000 C6 03001 06 03002 00 03003 01 03004 05 03005 A0 03006 00 03007 01 03008 04 03009 03 0300A A2 0300B 00 0300C 02 control bus data bus address bus MPU Instruction Fetched: C606000105 mov byte ptr [0100], 05
  • 12.
    Von Neumann architecture EXECUTE theMPU will start to execute the instruction previously decoded External Memory 03000 C6 03001 06 03002 00 03003 01 03004 05 03005 A0 03006 00 03007 01 03008 04 03009 03 0300A A2 0300B 00 0300C 02 control bus data bus address bus MPU Instruction Fetched: C606000105 executing: mov byte ptr [0100], 05
  • 13.
    Why Assembly Language TITLEHello World Program DOSSEG .MODEL SMALL .STACK 100h .DATA GREET DB "Hello World!", 10, 13, "$" .CODE BEGIN:MOV AX, @DATA MOV DS, AX MOV ES, AX LEA DX, [GREET] MOV AH, 09h INT 21h MOV AL, 00h MOV AH, 4Ch INT 21h END BEGIN #include <stdio.h> void main() { printf(“Hello World!”); } High Level LanguageAssembly Language
  • 14.
    Why Assembly Language TITLEHello World Program DOSSEG .MODEL SMALL .STACK 100h .DATA GREET DB "Hello World!", 10, 13, "$" .CODE BEGIN:MOV AX, @DATA MOV DS, AX MOV ES, AX LEA DX, [GREET] MOV AH, 09h INT 21h MOV AL, 00h MOV AH, 4Ch INT 21h END BEGIN #include <stdio.h> void main() { printf(“Hello World!”); } High Level LanguageAssembly Language COMPACT CODE
  • 15.
    Why Assembly Language TITLEHello World Program DOSSEG .MODEL SMALL .STACK 100h .DATA GREET DB "Hello World!", 10, 13, "$" .CODE BEGIN:MOV AX, @DATA MOV DS, AX MOV ES, AX LEA DX, [GREET] MOV AH, 09h INT 21h MOV AL, 00h MOV AH, 4Ch INT 21h END BEGIN #include <stdio.h> void main() { printf(“Hello World!”); } High Level LanguageAssembly Language SPEED
  • 16.
    Why Assembly Language TITLEHello World Program DOSSEG .MODEL SMALL .STACK 100h .DATA GREET DB "Hello World!", 10, 13, "$" .CODE BEGIN:MOV AX, @DATA MOV DS, AX MOV ES, AX LEA DX, [GREET] MOV AH, 09h INT 21h MOV AL, 00h MOV AH, 4Ch INT 21h END BEGIN #include <stdio.h> void main() { printf(“Hello World!”); } High Level LanguageAssembly Language FLEXIBLE
  • 17.
    Why NOT AssemblyLanguage TITLE Hello World Program DOSSEG .MODEL SMALL .STACK 100h .DATA GREET DB "Hello World!", 10, 13, "$" .CODE BEGIN:MOV AX, @DATA MOV DS, AX MOV ES, AX LEA DX, [GREET] MOV AH, 09h INT 21h MOV AL, 00h MOV AH, 4Ch INT 21h END BEGIN #include <stdio.h> void main() { printf(“Hello World!”); } High Level LanguageAssembly Language EASY TO LEARN
  • 18.
    Why NOT AssemblyLanguage TITLE Hello World Program DOSSEG .MODEL SMALL .STACK 100h .DATA GREET DB "Hello World!", 10, 13, "$" .CODE BEGIN:MOV AX, @DATA MOV DS, AX MOV ES, AX LEA DX, [GREET] MOV AH, 09h INT 21h MOV AL, 00h MOV AH, 4Ch INT 21h END BEGIN #include <stdio.h> void main() { printf(“Hello World!”); } High Level LanguageAssembly Language PREDEFINED FUNCTIONS
  • 19.
    Why NOT AssemblyLanguage TITLE Hello World Program DOSSEG .MODEL SMALL .STACK 100h .DATA GREET DB "Hello World!", 10, 13, "$" .CODE BEGIN:MOV AX, @DATA MOV DS, AX MOV ES, AX LEA DX, [GREET] MOV AH, 09h INT 21h MOV AL, 00h MOV AH, 4Ch INT 21h END BEGIN #include <stdio.h> void main() { printf(“Hello World!”); } High Level LanguageAssembly Language PORTABILITY
  • 20.
    History of Microprocessor NameDate Transistors Microns Clock speed Data width MIPS 8080 1974 6,000 6 2 MHz 8 bits 0.64 16 bits 8-bit bus 80286 1982 134,000 1.5 6 MHz 16 bits 1 80386 1985 275,000 1.5 16 MHz 32 bits 5 80486 1989 1,200,000 1 25 MHz 32 bits 20 32 bits 64-bit bus 32 bits 64-bit bus 32 bits 64-bit bus 32 bits 64-bit bus 8088 1979 29,000 3 Pentium 1993 3,100,000 0.8 7,500,000 0.35 5 MHz 0.33 60 MHz 100 233 MHz ~300 Pentium III 1999 9,500,000 0.25 450 MHz ~510 Pentium II 1997 1.5 GHz ~1,700Pentium 4 2000 42,000,000 0.18

Editor's Notes

  • #21 The date is the year that the processor was first introduced. Many processors are re-introduced at higher clock speeds for many years after the original release date. Transistors is the number of transistors on the chip. You can see that the number of transistors on a single chip has risen steadily over the years. Microns is the width, in microns, of the smallest wire on the chip. For comparison, a human hair is 100 microns thick. As the feature size on the chip goes down, the number of transistors rises. Clock speed is the maximum rate that the chip can be clocked at. Clock speed will make more sense in the next section. Data Width is the width of the ALU. An 8-bit ALU can add/subtract/multiply/etc. two 8-bit numbers, while a 32-bit ALU can manipulate 32-bit numbers. An 8-bit ALU would have to execute four instructions to add two 32-bit numbers, while a 32-bit ALU can do it in one instruction. In many cases, the external data bus is the same width as the ALU, but not always. The 8088 had a 16-bit ALU and an 8-bit bus, while the modern Pentiums fetch data 64 bits at a time for their 32-bit ALUs. MIPS stands for &amp;quot;millions of instructions per second&amp;quot; and is a rough measure of the performance of a CPU. Modern CPUs can do so many different things that MIPS ratings lose a lot of their meaning, but you can get a general sense of the relative power of the CPUs from this column.