《AssemblyLanguageforIntelBasedComputers5editionchapt16章节》由会员分享,可在线阅读,更多相关《AssemblyLanguageforIntelBasedComputers5editionchapt16章节(58页珍藏版)》请在金锄头文库上搜索。
1、Assembly Language for Intel-Based Computers, 5th Edition,Chapter 16: Expert MS-DOS Programming,(c) Pearson Education, 2006-2007. All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the authors name, and
2、 the title are not changed.,Slide show prepared by the author Revision date: June 4, 2006,Kip R. Irvine,Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.,2,Chapter Overview,Defining Segments Runtime Program Structure Interrupt Handling Hardware Control Using I/O Ports,Irvine, Kip
3、 R. Assembly Language for Intel-Based Computers 5/e, 2007.,3,Defining Segments,Simplified Segment Directives Explicit Segment Definitions Segment Overrides Combining Segments,Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.,4,Simplified Segment Directives,.MODEL program memory m
4、odel .CODE code segment .CONST define constants .DATA near data segment .DATA? uninitialized data .FARDATA far data segment .FARDATA? far uninitialize data .STACK stack segment .STARTUP initialize DS and ES .EXIT halt program,Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.,5,Me
5、mory Models,Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.,6,NEAR and FAR Segments,NEAR segment requires only a 16-bit offset faster execution than FAR FAR segment 32-bit offset: requires setting both segment and offset values slower execution than NEAR,Irvine, Kip R. Assembly
6、 Language for Intel-Based Computers 5/e, 2007.,7,.MODEL Directive,The .MODEL directive determines the names and grouping of segments .model tiny code and data belong to same segment (NEAR) .com file extension .model small both code and data are NEAR data and stack grouped into DGROUP .model medium c
7、ode is FAR, data is NEAR,Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.,8,.MODEL Directive,.model compact code is NEAR, data is FAR .model huge & .model large both code and data are FAR .model flat both code and data are 32-bit NEAR,Irvine, Kip R. Assembly Language for Intel-B
8、ased Computers 5/e, 2007.,9,.MODEL Directive,Syntax: .MODEL type, language, stackdistance Language can be: C, BASIC, FORTRAN, PASCAL, SYSCALL, or STDCALL (details in Chapters 8 and 12). Stackdistance can be: NEARSTACK: (default) places the stack segment in the group DGROUP along with the data segmen
9、t FARSTACK: stack and data are not grouped together,Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.,10,.STACK Directive,Syntax: .STACK stacksize Stacksize specifies size of stack, in bytes default is 1024 Example: set to 2048 bytes: .stack 2048,Irvine, Kip R. Assembly Language
10、for Intel-Based Computers 5/e, 2007.,11,.CODE Directive,Syntax: .CODE segname optional segname overrides the default name Small, compact memory models NEAR code segment segment is named _TEXT Medium, large, huge memory models FAR code segment segment is named modulename_TEXT,Whenever the CPU execute
11、s a FAR call or jump, it loads CS with the new segment address.,Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.,12,Calling Library Procedures,You must use .MODEL small, stdcall (designed for the small memory model) You can only call Irvine16 library procedures from segments nam
12、ed _TEXT. (default name when .CODE is used) Advantages calls and jumps execute more quickly simple use of dataDS never needs to change Disadvantages segment names restricted limited to 64K code, and 64K data,Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.,13,Multiple Code Segme
13、nts,.code main PROC mov ax,data mov ds,ax call WriteString call Display .exit main ENDP,Example, p. 585, shows calling Irvine16 procedures from main, and calling an MS-DOS interrupt from Display.,.code OtherCode Display PROC mov ah,9 mov dx,OFFSET msg2 int 21h ret Display ENDP,Irvine, Kip R. Assembl
14、y Language for Intel-Based Computers 5/e, 2007.,14,Near Data Segments,.DATA directive creates a Near segment Up to 64K in Real-address mode Up to 512MB in Protected mode (Windows NT) 16-bit offsets are used for all code and data automatically creates segment named DGROUP can be used in any memory mo
15、del Other types of data: .DATA? (uninitialized data) .CONST (constant data),Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.,15,Far Data Segments,.FARDATA creates a FAR_DATA segment .FARDATA? creates a FAR_BSS segment Code to access data in a far segment:,.FARDATA myVar .CODE mo
16、v ax,SEG myVar mov ds,ax,The SEG operator returns the segment value of a label. Similar to data.,Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.,16,Data-Related Symbols,data returns the group of the data segment DataSize returns the size of the memory model set by the .MODEL directive WordSize returns the size attribute of the current segment CurSeg returns the name of the current segment,Irvine, Kip R. Assembly Language for Intel-Based Com