8288 bus controller. SAP-III Assembly Language.
Transcript of 8288 bus controller. SAP-III Assembly Language.
8288 bus controller
8288 bus controller
SAP-III
SAP-III
Assembly Language
Basic Microcomputer Design
clock synchronizes CPU operations control unit (CU) coordinates sequence of execution steps ALU performs arithmetic and bitwise processing
Introduction
Assembly language is used primarily for direct hardware manipulation, access to specialized processor instructions, or to address critical performance issues. Typical uses are device drivers, low-level embedded systems, and real-time systems.
Reasons for not using assembly
Development time: it takes much longer to develop in assembly. Harder to debug, no type checking, side effects…
Maintainability: unstructured, dirty tricks Portability: platform-dependent
Reasons for using assembly
Educational reasons: to understand how CPUs and compilers work. Better understanding to efficiency issues of various constructs.
Developing compilers, debuggers and other development tools.
Hardware drivers and system code Embedded systems Developing libraries. Accessing instructions that are not available through
high-level languages. Optimizing for speed or space
To sum up
It is all about lack of smart compilers
Faster code, compiler is not good enough Smaller code , compiler is not good enough,
e.g. mobile devices, embedded devices, also Smaller code → better cache performance → faster code
Unusual architecture , there isn’t even a compiler or compiler quality is bad, eg GPU, DSP chips, even MMX.
Overview
Virtual Machine Concept Data Representation Boolean Operations
Translating Languages
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 00000000
F7 25 00000004
03 05 00000008
E8 00500000
Virtual machinesAbstractions for computers
High-Level Language
Level 5 Application-oriented languages Programs compile into assembly language
(Level 4)
cout << (A * B + C);
Assembly Language
Level 4 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) mov eax, Amul Badd eax, Ccall WriteInt
Operating System
Level 3 Provides services Programs translated and run at the instruction
set architecture level (Level 2)
Instruction Set Architecture
Level 2 Also known as conventional machine language Executed by Level 1 program
(microarchitecture, Level 1)
A1 00000000F7 25 0000000403 05 00000008E8 00500000
Microarchitecture
Level 1 Interprets conventional machine instructions
(Level 2) Executed by digital hardware (Level 0)
Digital Logic
Level 0 CPU, constructed from digital logic gates System bus Memory
Segment Registers
Any program has two essential parts Code Data
During execution of program Parameters are passed/returned from one subroutine
to another Processing of interrupts requires storing of program
variables A stack (Data Structure) is essential for passing
parameters and processing of interrupts
Segment Registers
Program Code placed in memory in an area defined as Code Segment (CS)
Program Data placed in memory in an area defined as Data Segment (DS)
Program stack is implemented in memory in an area defined as Stack Segment (SS)
An extra data area is reserved in memory to facilitate data manipulation operations
Extra data area is defined as Extra Segment (ES)
Segment Registers
Code Segment 16-bit Register Holds the start address of the section of the
memory that holds code Data Segment 16-bit Register
Holds the address of the section of the memory that holds data
Stack Segment 16-bit Register Holds the address of section of memory that
holds stack
Segment Registers
Extra Segment 16-bit Register Holds the address of additional data segment
used in string operations to hold destination data
Real-Mode Programming
Allows access to 1 MB of memory DOS OS requires microprocessor to operate
in the real mode All Intel processors begin operation in the real
mode by default when powered up or when reset
Accessing Memory
20 bit address is generated by combining a segment address and an offset address
Segment Register = C000 H Offset Register = 1C78 H 20 bit address = C0000 + 1C78 = C1C78 H
Also written as C000:1C78 Each segment is of size 64KB
Accessing Memory
A rightmost 0 is appended to segment register contents Segment begins on a 16-byte boundary 16-byte boundary known as Paragraph
Some addressing modes combine more than three registers to generate a 20-bit memory address Modulo 16 used to generate address Seg. Reg = 4000 H offset reg = F000 H & 3000 H
Accessing Memory
Offset address = F000 + 3000 = 12000 H Modulo 16 = 2000 H 20-bit address = 40000 + 2000 = 42000 H
Default Segment & Offset Registers
CS and IP SS and SP or BP DS and BX, DI, SI, an 8-bit or 16-bit number ES and DI Segments can be located anywhere in the
memory Segments can overlap Allows relocatable programs
Sample Program
mov ax, 5
add ax, 10H
add ax, 20
mov sum, ax
int 20h
execution
AX=0000 BX=0000 CX=0000 DX=0000 SP=DF12 BP=0000 SI=0000 DI=0000DS=1FDD ES=1FDD SS=1FDD CS=1FDD IP=0100 NV UP EI PL NZ NA PO NC MOV AX,0005
AX=0005 BX=0000 CX=0000 DX=0000 SP=DF12 BP=0000 SI=0000 DI=0000DS=1FDD ES=1FDD SS=1FDD CS=1FDD IP=0103 NV UP EI PL NZ NA PO NC ADD AX,0010
AX=0015 BX=0000 CX=0000 DX=0000 SP=DF12 BP=0000 SI=0000 DI=0000DS=1FDD ES=1FDD SS=1FDD CS=1FDD IP=0106 NV UP EI PL NZ NA PO NC ADD AX,0020
AX=0035 BX=0000 CX=0000 DX=0000 SP=DF12 BP=0000 SI=0000 DI=0000DS=1FDD ES=1FDD SS=1FDD CS=1FDD IP=0109 NV UP EI PL NZ NA PE NC MOV [0120],AX
Addressing Modes
Different ways to access operands Different data structures use different ways to
access data values Stack Queue Tree Array
Instruction Execution Cycle
Fetch Decode Fetch operands Execute Store output
Addressing Modes
The following are the different addressing modes of 8086: Register operand addressing. Immediate operand addressing. Memory operand addressing.
The different memory addressing modes are: Direct Addressing Register Indirect Addressing Based Addressing Indexed Addressing Based Indexed Addressing and Based Indexed with displacement.
Addressing Modes
Operands can be of type Register Immediate Memory
Register Addressing Contents of the register are used MOV AX, BX
Immediate Addressing A constant data value is specified MOV CH, 3AH
Addressing Modes
Six Memory Addressing Modes are supported Direct Addressing
Memory address is directly specified mov [1234H],ax DS x 10H + DISP mov value, ax mov ax, buffer add bl, value cmp cx, count
Addressing Modes
Register Indirect Addressing The effective address of memory is the
contents of a register mov ax, [si] add bl, [di] cmp cx, [bx]
Addressing Modes
Based or Register Relative Addressing The effective memory address is the sum of a
base register and a displacement List[bx], [bp+1] mov cl, [bx+4] DS x 10H + BX + 4 mov ax, list[bx] add bl, [bx+7] cmp cx, [bp-3]
Addressing Modes
Indexed Addressing The effective memory address is the sum of
an index register and a displacement mov [bx+2], bp DS x 10H + BX + 2 List[si], [list + di], [di+2] mov ax, list[si] add bl, [number+di] cmp cx, [di+2]
Addressing Modes
Base Indexed or Base-Plus-Index Addressing The effective memory address is the sum of a
base register and an index register [bx+si], [bx][di], [bp+di] mov [bx+si], bp DS x 10H + BX + SI
will use DS as default seg
mov ax, [bx+si] add bl, [bx][si] cmp cx, [bp+di]
Addressing Modes
Base Indexed with Displacement or Base Relative-Plus-Index Addressing The effective memory address is the sum of
base register, index register and a displacement
[bx+si+2], list[bx+di] mov array[bx + si], dx
DS x 10H + ARRAY + BX + SI
mov ax, array[bx+si] add bl, [bx+di+2] cmp cx, 2[bp+di]
Addressing Modes
Summary
The following are the different addressing modes of 8086: Register operand addressing. Immediate operand addressing. Memory operand addressing.
The different memory addressing modes are: Direct Addressing Register Indirect Addressing Based Addressing Indexed Addressing Based Indexed Addressing and Based Indexed with displacement.
Instruction Set
Data Movement Instructions mov, lea, les, lds, push, pop, pushf, popf
Conversions cbw, cwd, xlat
Arithmetic instructions add, inc, sub, dec, cmp, neg, mul, imul, div,
idiv Logical instructions
and, or, xor, not, shl, shr, rcl, rcr
Instruction Set
I/O instructions in, out
String instructions movs, stos, lods, scas, cmps
Program flow control instructions jmp, call, ret, conditional jumps
Misc instructions clc, stc, cmc, cld, std, cli, sti
Mov Instruction
Limitations CS and IP can not be destination registers Immediate data can not be moved to segment
registers Contents of segment registers can not be
moved to segment registers Source and destination operands have to be
of same size
Mov Instruction
Limitations Immediate data must not exceed 0FFh or
0FFFFh for 8 and 16 bit data Memory to memory transfers are not allowed No flags are affected
Instruction size Number of clocks
Writing and Assembling Programs
Source Program
Sample.asm
Assembler masm.exe
Object Program
sample.obj Listing fileCross-
reference file
sample.lst sample.crf
Optional
Linker link.exe
Executable Program
sample.exe Map file
sample.map
Assembly Program Structure
Assembly Program Structure
.model small
.stack 100h
entr equ 0dhbufsize equ 10h
.code
.startup
mov ax,@datamov ds,axmov si,offset buffer
Assembly Program Structure
mov cx,bufsize
a1: mov ah,1
int 21h
cmp al,entr
je a2
mov [si],al
inc si
loop a1
Assembly Program Structure
a2: sub charstyped,clmov ax,4c00hint 21h
.exit
.datacharstyped db bufsizebuffer db bufsize dup(0)
end
Comparing three numbers
.model small
.stack 100h
.codemain proc
mov ax,@datamov ds,axmov bl,10mov cx,3mov si,offset var1
Comparing three numbers
call get numbers
call compare numbers
call show numbers
mov ax,4c00h
int 21h
main endp
Comparing three numbers
get numbers procagn1: mov ah,1
int 21hsub al,30hmul blmov dl,almov ah,1int 21hsub al,30hadd dl,almov [si],dlinc siloop agn1
get numbers endp
Comparing three numbers
compare numbers procmov cx,2
agn2: mov al,var2cmp var1,aljb l1xchg var1,almov var2,al
l1: cmp al,var3jb l2xchg var3,almov var2,al
l2: loop agn2compare numbers endp
Comparing three numbers
show numbers procshow: mov dl,var1
mov ah,2int 21hmov dl,var2mov ah,2int 21hmov dl,var3mov ah,2int 21h
show numbers endp
Lecture 20
Comparing three numbers
.data
var1 db 0
var2 db 0
var3 db 0
end main