⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asm_tutorial_10.html

📁 介绍用Java解析网络数据的三种特殊方法
💻 HTML
字号:
<!doctype HTML public "-//W3O//DTD W3 HTML 3.0//EN"><HTML><HEAD><TITLE>8086 Assembler Tutorial for Beginners (Part 10)</TITLE><META name="description" content="Macros for 8086 Assembler"><META name="keywords" content="macros, 8086, procedures, tutorial, programming"><META name="robots" content="nofollow"></HEAD><BODY bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#007099" alink="#FF0000"><TABLE WIDTH=80%><TR><TD><FONT FACE="Verdana" SIZE=3><FONT SIZE=+1><B>8086 Assembler Tutorial for Beginners (Part 10)</B></FONT><BR><BR><FONT SIZE=+2><B>Macros</B></FONT><BR><BR>Macros are just like procedures, but not really. Macros look like procedures,but they exist only until your code is compiled, after compilation all macrosare replaced with real instructions. If you declared a macro and never used itin your code, compiler will simply ignore it.<B><A HREF="asm_tutorial_05.html">emu8086.inc</A></B> is a good example of how macros can be used, this filecontains several macros to make coding easier for you.<BR><BR><TABLE BORDER=1 CELLPADDING=10><TR><TD>Macro definition:<BR><PRE><FONT FACE="Fixedsys">name    MACRO  [parameters,...]             &lt;instructions>ENDM</FONT></PRE></TD></TR></TABLE><BR><BR>Unlike procedures, macros should be defined above thecode that uses it, for example:<BR><BR><TABLE BORDER=1 CELLPADDING=10><TR><TD><PRE><FONT FACE="Fixedsys">MyMacro    MACRO  p1, p2, p3     MOV AX, p1     MOV BX, p2     MOV CX, p3ENDMORG 100hMyMacro 1, 2, 3MyMacro 4, 5, DXRET</FONT></PRE></TD></TR></TABLE><BR><BR>The above code is expanded into:<BR><BR><FONT FACE="Fixedsys">MOV AX, 00001h<BR>MOV BX, 00002h<BR>MOV CX, 00003h<BR>MOV AX, 00004h<BR>MOV BX, 00005h<BR>MOV CX, DX<BR></FONT><BR><BR><BR><TABLE BORDER=1 CELLPADDING=10><TR><TD><BR>Some important facts about <B>macros</B> and <B>procedures</B>:<UL><LI>When you want to use a procedure you should use <B>CALL</B> instruction,for example:<BR><BLOCKQUOTE><FONT FACE="Fixedsys">CALL MyProc</FONT></BLOCKQUOTE></LI><LI>When you want to use a macro, you can just type its name.For example:<BR><BLOCKQUOTE><FONT FACE="Fixedsys">MyMacro</FONT></BLOCKQUOTE></LI><LI>Procedure is located at some specific address in memory, and if youuse the same procedure 100 times, the CPU will transfer controlto this part of the memory. The control will be returned back tothe program by <B>RET</B> instruction. The <B>stack</B> is usedto keep the return address. The <B>CALL</B> instruction takesabout 3 bytes, so the size of the output executable filegrows very insignificantly, no matter how many time the procedureis used.<BR><BR></LI><LI>Macro is expanded directly in program's code. So if you use thesame macro 100 times, the compiler expands the macro 100 times, makingthe output executable file larger and larger, each time allinstructions of a macro are inserted.<BR><BR></LI><LI>You should use <B>stack</B> or any general purpose registersto pass parameters to procedure.<BR><BR></LI><LI>To pass parameters to macro, you can just type them after themacro name. For example:<BLOCKQUOTE><FONT FACE="Fixedsys">MyMacro 1, 2, 3</FONT></BLOCKQUOTE></LI><LI>To mark the end of the macro <B>ENDM</B> directive is enough.<BR><BR></LI><LI>To mark the end of the procedure, you should type the name of theprocedure before the <B>ENDP</B> directive.</LI></UL></TD></TR></TABLE><BR><BR>Macros are expanded directly in code, therefore if there are labels inside themacro definition you may get "Duplicate declaration" error when macro is usedfor twice or more. To avoid such problem, use <B>LOCAL</B> directive followedby names of variables, labels or procedure names. For example:<BR><BR><TABLE BORDER=1 CELLPADDING=10 WIDTH=80%><TR><TD><PRE><FONT FACE="Fixedsys">MyMacro2    MACRO	LOCAL label1, label2	CMP  AX, 2	JE label1	CMP  AX, 3	JE label2	label1:		 INC  AX	label2:		 ADD  AX, 2ENDMORG 100hMyMacro2MyMacro2RET</FONT></PRE></TD></TR></TABLE><BR><BR>If you plan to use your macros in several programs, it may be a good idea to placeall macros in a separate file. Place that file in <B>Inc</B> folder anduse <B>INCLUDE <I>file-name</I></B> directive to use macros.See <A HREF="asm_tutorial_05.html"><B>Library of common functions - emu8086.inc</B></A>for an example of such file.<BR><BR><BR><HR><CENTER><A HREF="asm_tutorial_09.html"><B> &lt;&lt;&lt; Previous Part &lt;&lt;&lt; </B></A>&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="asm_tutorial_11.html"><B> >>> Next Part >>> </B></A></CENTER><HR><BR></FONT></TD></TR></TABLE></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -