8288 bus controller. SAP-III Assembly Language.

56
8288 bus controller

Transcript of 8288 bus controller. SAP-III Assembly Language.

Page 1: 8288 bus controller. SAP-III Assembly Language.

8288 bus controller

Page 2: 8288 bus controller. SAP-III Assembly Language.

8288 bus controller

Page 3: 8288 bus controller. SAP-III Assembly Language.

SAP-III

Page 4: 8288 bus controller. SAP-III Assembly Language.

SAP-III

Page 5: 8288 bus controller. SAP-III Assembly Language.

Assembly Language

Page 6: 8288 bus controller. 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

Page 7: 8288 bus controller. SAP-III Assembly Language.

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.

Page 8: 8288 bus controller. SAP-III Assembly Language.

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

Page 9: 8288 bus controller. SAP-III Assembly Language.

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

Page 10: 8288 bus controller. SAP-III Assembly Language.

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.

Page 11: 8288 bus controller. SAP-III Assembly Language.

Overview

Virtual Machine Concept Data Representation Boolean Operations

Page 12: 8288 bus controller. SAP-III Assembly Language.

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

Page 13: 8288 bus controller. SAP-III Assembly Language.

Virtual machinesAbstractions for computers

Page 14: 8288 bus controller. SAP-III Assembly Language.

High-Level Language

Level 5 Application-oriented languages Programs compile into assembly language

(Level 4)

cout << (A * B + C);

Page 15: 8288 bus controller. SAP-III Assembly Language.

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

Page 16: 8288 bus controller. SAP-III Assembly Language.

Operating System

Level 3 Provides services Programs translated and run at the instruction

set architecture level (Level 2)

Page 17: 8288 bus controller. SAP-III Assembly Language.

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

Page 18: 8288 bus controller. SAP-III Assembly Language.

Microarchitecture

Level 1 Interprets conventional machine instructions

(Level 2) Executed by digital hardware (Level 0)

Page 19: 8288 bus controller. SAP-III Assembly Language.

Digital Logic

Level 0 CPU, constructed from digital logic gates System bus Memory

Page 20: 8288 bus controller. SAP-III Assembly Language.

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

Page 21: 8288 bus controller. SAP-III Assembly Language.

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)

Page 22: 8288 bus controller. SAP-III Assembly Language.

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

Page 23: 8288 bus controller. SAP-III Assembly Language.

Segment Registers

Extra Segment 16-bit Register Holds the address of additional data segment

used in string operations to hold destination data

Page 24: 8288 bus controller. SAP-III Assembly Language.

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

Page 25: 8288 bus controller. SAP-III Assembly Language.

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

Page 26: 8288 bus controller. SAP-III Assembly Language.

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

Page 27: 8288 bus controller. SAP-III Assembly Language.

Accessing Memory

Offset address = F000 + 3000 = 12000 H Modulo 16 = 2000 H 20-bit address = 40000 + 2000 = 42000 H

Page 28: 8288 bus controller. SAP-III Assembly Language.

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

Page 29: 8288 bus controller. SAP-III Assembly Language.

Sample Program

mov ax, 5

add ax, 10H

add ax, 20

mov sum, ax

int 20h

Page 30: 8288 bus controller. SAP-III Assembly Language.

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

Page 31: 8288 bus controller. SAP-III Assembly Language.

Addressing Modes

Different ways to access operands Different data structures use different ways to

access data values Stack Queue Tree Array

Page 32: 8288 bus controller. SAP-III Assembly Language.

Instruction Execution Cycle

Fetch Decode Fetch operands Execute Store output

Page 33: 8288 bus controller. SAP-III Assembly Language.

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.

Page 34: 8288 bus controller. SAP-III Assembly Language.

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

Page 35: 8288 bus controller. SAP-III Assembly Language.

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

Page 36: 8288 bus controller. SAP-III Assembly Language.

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]

Page 37: 8288 bus controller. SAP-III Assembly Language.

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]

Page 38: 8288 bus controller. SAP-III Assembly Language.

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]

Page 39: 8288 bus controller. SAP-III Assembly Language.

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]

Page 40: 8288 bus controller. SAP-III Assembly Language.

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]

Page 41: 8288 bus controller. SAP-III Assembly Language.

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.

Page 42: 8288 bus controller. SAP-III Assembly Language.

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

Page 43: 8288 bus controller. SAP-III Assembly Language.

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

Page 44: 8288 bus controller. SAP-III Assembly Language.

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

Page 45: 8288 bus controller. SAP-III Assembly Language.

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

Page 46: 8288 bus controller. SAP-III Assembly Language.

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

Page 47: 8288 bus controller. SAP-III Assembly Language.

Assembly Program Structure

Page 48: 8288 bus controller. SAP-III Assembly Language.

Assembly Program Structure

.model small

.stack 100h

entr equ 0dhbufsize equ 10h

.code

.startup

mov ax,@datamov ds,axmov si,offset buffer

Page 49: 8288 bus controller. SAP-III Assembly Language.

Assembly Program Structure

mov cx,bufsize

a1: mov ah,1

int 21h

cmp al,entr

je a2

mov [si],al

inc si

loop a1

Page 50: 8288 bus controller. SAP-III Assembly Language.

Assembly Program Structure

a2: sub charstyped,clmov ax,4c00hint 21h

.exit

.datacharstyped db bufsizebuffer db bufsize dup(0)

end

Page 51: 8288 bus controller. SAP-III Assembly Language.

Comparing three numbers

.model small

.stack 100h

.codemain proc

mov ax,@datamov ds,axmov bl,10mov cx,3mov si,offset var1

Page 52: 8288 bus controller. SAP-III Assembly Language.

Comparing three numbers

call get numbers

call compare numbers

call show numbers

mov ax,4c00h

int 21h

main endp

Page 53: 8288 bus controller. SAP-III Assembly Language.

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

Page 54: 8288 bus controller. SAP-III Assembly Language.

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

Page 55: 8288 bus controller. SAP-III Assembly Language.

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

Page 56: 8288 bus controller. SAP-III Assembly Language.

Lecture 20

Comparing three numbers

.data

var1 db 0

var2 db 0

var3 db 0

end main