Download presentation
Presentation is loading. Please wait.
1
8288 bus controller
3
SAP-III
5
Assembly Language
6
Basic Microcomputer Design clock synchronizes CPU operations control unit (CU) coordinates sequence of execution steps ALU performs arithmetic and bitwise processing
7
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.
8
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
9
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
10
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.
11
Overview Virtual Machine Concept Data Representation Boolean Operations
12
Translating Languages English: Display the sum of A times B plus C. C++: cout << (A * B + C); Assembly Language: mov eax,A mul B add eax,C call WriteInt Intel Machine Language: A1 00000000 F7 25 00000004 03 05 00000008 E8 00500000
13
Virtual machines Abstractions for computers
14
High-Level Language Level 5 Application-oriented languages Programs compile into assembly language (Level 4) cout << (A * B + C);
15
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, A mul B add eax, C call WriteInt
16
Operating System Level 3 Provides services Programs translated and run at the instruction set architecture level (Level 2)
17
Instruction Set Architecture Level 2 Also known as conventional machine language Executed by Level 1 program (microarchitecture, Level 1) A1 00000000 F7 25 00000004 03 05 00000008 E8 00500000
18
Microarchitecture Level 1 Interprets conventional machine instructions (Level 2) Executed by digital hardware (Level 0)
19
Digital Logic Level 0 CPU, constructed from digital logic gates System bus Memory
20
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
21
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)
22
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
23
Segment Registers Extra Segment 16-bit Register Holds the address of additional data segment used in string operations to hold destination data
24
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
25
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
26
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
27
Accessing Memory Offset address = F000 + 3000 = 12000 H Modulo 16 = 2000 H 20-bit address = 40000 + 2000 = 42000 H
28
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
29
Sample Program mov ax, 5 add ax, 10H add ax, 20 mov sum, ax int 20h
30
execution AX=0000 BX=0000 CX=0000 DX=0000 SP=DF12 BP=0000 SI=0000 DI=0000 DS=1FDD ES=1FDD SS=1FDD CS=1FDD IP=0100NV 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=0000 DS=1FDD ES=1FDD SS=1FDD CS=1FDD IP=0103NV 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=0000 DS=1FDD ES=1FDD SS=1FDD CS=1FDD IP=0106NV 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=0000 DS=1FDD ES=1FDD SS=1FDD CS=1FDD IP=0109NV UP EI PL NZ NA PE NC MOV [0120],AX
31
Addressing Modes Different ways to access operands Different data structures use different ways to access data values Stack Queue Tree Array
32
Instruction Execution Cycle Fetch Decode Fetch operands Execute Store output
33
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.
34
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
35
Addressing Modes Six Memory Addressing Modes are supported Direct Addressing Memory address is directly specified mov [1234H],axDS x 10H + DISP mov value, ax mov ax, buffer add bl, value cmp cx, count
36
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]
37
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]
38
Addressing Modes Indexed Addressing The effective memory address is the sum of an index register and a displacement mov [bx+2], bpDS x 10H + BX + 2 List[si], [list + di], [di+2] mov ax, list[si] add bl, [number+di] cmp cx, [di+2]
39
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], bpDS x 10H + BX + SI will use DS as default seg mov ax, [bx+si] add bl, [bx][si] cmp cx, [bp+di]
40
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]
41
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.
42
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
43
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
44
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
45
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
46
Writing and Assembling Programs
47
Assembly Program Structure
48
.model small.stack 100h entrequ 0dh bufsize equ 10h.code.startup mov ax,@data mov ds,ax mov si,offset buffer
49
Assembly Program Structure mov cx,bufsize a1:mov ah,1 int 21h cmp al,entr je a2 mov [si],al inc si loop a1
50
Assembly Program Structure a2:sub charstyped,cl mov ax,4c00h int 21h.exit.data charstyped db bufsize buffer db bufsize dup(0) end
51
Comparing three numbers.model small.stack 100h.code main proc mov ax,@data mov ds,ax mov bl,10 mov cx,3 mov si,offset var1
52
Comparing three numbers call get numbers call compare numbers call show numbers mov ax,4c00h int 21h main endp
53
Comparing three numbers get numbers proc agn1:mov ah,1 int 21h sub al,30h mul bl mov dl,al mov ah,1 int 21h sub al,30h add dl,al mov [si],dl inc si loop agn1 get numbers endp
54
Comparing three numbers compare numbers proc mov cx,2 agn2:mov al,var2 cmp var1,al jb l1 xchg var1,al mov var2,al l1:cmp al,var3 jb l2 xchg var3,al mov var2,al l2:loop agn2 compare numbers endp
55
Comparing three numbers show numbers proc show: mov dl,var1 mov ah,2 int 21h mov dl,var2 mov ah,2 int 21h mov dl,var3 mov ah,2 int 21h show numbers endp
56
Lecture 20 Comparing three numbers.data var1 db 0 var2 db 0 var3 db 0 end main
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.