资源预览内容
第1页 / 共58页
第2页 / 共58页
第3页 / 共58页
第4页 / 共58页
第5页 / 共58页
第6页 / 共58页
第7页 / 共58页
第8页 / 共58页
第9页 / 共58页
第10页 / 共58页
亲,该文档总共58页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
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 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 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 model .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,Memory 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 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 code 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-Based 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 segment 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 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 executes 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 named _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 Segments,.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. Assembly 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 model 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 mov 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
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号