📄 compiler.html
字号:
<!doctype HTML public "-//W3O//DTD W3 HTML 3.0//EN"><HTML><HEAD><TITLE>Compiling Assembly Code</TITLE><META name="description" content="Compiling Assembly Code"><META name="keywords" content="compiler, reference, description, hints"></HEAD><BODY bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#007099" alink="#FF0000"><TABLE WIDTH=80%><TR><TD><FONT FACE="Verdana" SIZE=3><FONT SIZE=+2><B>Compiling Assembly Code</B></FONT><BR><BR><BR><IMG SRC="compile01.gif" WIDTH=593 HEIGHT=289><BR><BR>Type your code inside the text area, and click <B>[Compile]</B>button. You will be asked for a place where to save the compiled file.<BR>After successful compilation you can click <B>[Emulate]</B> button toload the compiled file in emulator.<BR><BR><HR>The <B>Output File Type Directives:</B><BR><BR><PRE><FONT FACE="Fixedsys"> #MAKE_COM# #MAKE_BIN# #MAKE_BOOT# #MAKE_EXE#</FONT></PRE>You can insert these directives in the source code to specify therequired output type for the file. Only if compiler cannot find anyof these directives it will ask you for <I>output type</I> before creating the file.<HR><BR><B>Description of Output File Types:</B><BR><BR><UL> <LI> <B>#MAKE_COM#</B> - the oldest and the simplest format of an executable file, such files are loaded with 100h prefix (256 bytes). Select <B>Clean</B> from the <B>New</B> menu if you plan to compile a COM file. Compiler directive <B>ORG 100h</B> should be added before the code. Execution always starts from the first byte of the file.<BR> Supported by DOS and Windows Command Prompt. <BR><BR><BR><BR> </LI> <LI> <B>#MAKE_EXE#</B> - more advanced format of an executable file. Not limited by size and number of segments. Stack segment should be defined in the program. You may select <B>EXE Template</B> from the <B>New</B> menu in to create a simple EXE program with defined Data, Stack, and Code segments.<BR> Entry point (where execution starts) is defined by a programmer.<BR> Supported by DOS and Windows Command Prompt. <BR><BR><BR><BR> </LI> <LI> <B>#MAKE_BIN#</B> - a simple executable file. You can define the values of all registers, segment and offset for memory area where this file will be loaded. When loading "<B>MY.BIN</B>" file to emulator it will look for a "<B>MY.BINF</B>" file, and load "<B>MY.BIN</B>" file to location specified in "<B>MY.BINF</B>" file, registers are also set using information in that file (open this file in a text editor to edit or investigate). <BR> In case emulator is not able to find "<B>MY.BINF</B>" file, current register values are used and "<B>MY.BIN</B>" file is loaded at current <B>CS:IP</B>. <BR> Execution starts from values in <B>CS:IP</B>.<BR> This file type is unique to <I>Emu8086</I> emulator. <BR><BR> <!-- 1.25 --> <B>".BINF</B> file is created automatically by compiler if it finds <B>#MAKE_BIN#</B> directive.<BR> <FONT COLOR=RED>WARNING! any existing ".binf" file is overwritten!</FONT><BR><BR> <TABLE BORDER=1 CELLPADDING=10 WIDTH=80%><TR><TD> <PRE><FONT FACE="Fixedsys"> #LOAD_SEGMENT=1234# #LOAD_OFFSET=0000# #AL=12# #AH=34# #BH=00# #BL=00# #CH=00# #CL=00# #DH=00# #DL=00# #DS=0000# #ES=0000# #SI=0000# #DI=0000# #BP=0000# #CS=1234# #IP=0000# #SS=0000# #SP=0000#</FONT></PRE> </TABLE> <!-- end --><BR> Values must be in HEX!<BR><BR> When not specified these values are set by default:<BR> <FONT COLOR=GREEN> <B>LOAD_SEGMENT = 0100</B><BR> <B>LOAD_OFFSET = 0000</B><BR> <B>CS = ES = SS = DS = 0100</B><BR> <B>IP = 0000</B><BR> </FONT> <BR> If <B>LOAD_SEGMENT</B> and <B>LOAD_OFFSET</B> are not defined, then <B>CS</B> and <B>IP</B> values are used and vice-versa. <BR><BR><!--<HR><BR> Format of a typical <B>".BINF</B>" file:<BR><BR> <TABLE BORDER=1 CELLPADDING=10 WIDTH=80%><TR><TD> <PRE> <FONT FACE="Fixedsys"> 8000 ; Load to segment. 0000 ; Load to offset. 55 ; AL 66 ; AH 77 ; BL 88 ; BH 99 ; CL AA ; CH BB ; DL CC ; DH DDEE ; DS ABCD ; ES EF12 ; SI 3456 ; DI 7890 ; BP 8000 ; CS 0000 ; IP C123 ; SS D123 ; SP </FONT> </PRE> </TD></TR></TABLE> <BR> As you see first goes a number in hexadecimal form and then a comment.<BR> Comments are added just to make some order, when emulator loads a <B>BINF</B> file it does not care about comments it just looks for a values on specific lines, so line order is very important.<HR>--> <BR> In case <B>Load to offset</B> value is not zero (0000), <B>ORG ????h</B> should be added to the source of a <B>.BIN</B> file where <B>????h</B> is the <I>loading offset</I>, this should be done to allow compiler calculate correct addresses. <BR><BR> <BR><BR> </LI> <LI> <B>#MAKE_BOOT#</B> - this type is a copy of the first track of a floppy disk (boot sector). <BR> You can write a boot sector of a virtual floppy (FLOPPY_0) via menu in emulator:<BR> <B>[Virtual Drive] -> [Write 512 bytes at 7C00 to Boot Sector]</B> <BR> First you should compile a "<B>.boot</B>" file and load it in emulator (see "<B>micro-os_loader.asm</B>" and "<B>micro-os_kernel.asm</B>" in "Samples" for more info). <BR><BR> Then select <B>[Virtual Drive] -> [Boot from Floppy]</B> menu to boot emulator from a virtual floppy. <BR><BR> Then, if you are curious, you may write the virtual floppy to real floppy and boot your computer from it, I recommend using "RawWrite for Windows" from: <A HREF="http://uranus.it.swin.edu.au/~jn/linux/rawwrite.htm"> http://uranus.it.swin.edu.au/~jn/linux/rawwrite.htm</A><BR> (note that "<B>micro-os_loader.asm</B>" is not using MS-DOS compatible boot sector, so it's better to use and empty floppy, although it should be IBM (MS-DOS) formatted). <BR> Compiler directive <B>ORG 7C00h</B> should be added before the code, when computer starts it loads first track of a floppy disk at the address 0000:7C00. <BR> The size of a <B>.BOOT</B> file should be less then 512 bytes (limited by the size of a disk sector). <BR> Execution always starts from the first byte of the file.<BR> This file type is unique to <I>Emu8086</I> emulator. <BR><BR> </LI></UL><HR><BR><B>Error Processing</B><BR><BR>Compiler reports about errors in a separate information window:<BR><BR><IMG SRC="compile03.gif" WIDTH=511 HEIGHT=403><BR><BR><FONT FACE="Fixedsys">MOV DS, 100</FONT> - is illegal instruction becausesegment registers cannotbe set directly, general purpose register should be used:<BR><FONT FACE="Fixedsys">MOV AX, 100<BR>MOV DS, AX</FONT><BR><BR><FONT FACE="Fixedsys">MOV AL, 300</FONT> - is illegal instruction because<B>AL</B> register has only 8 bits, and thus maximum value for it is 255 (or 11111111b),and the minimum is -128.<BR><BR><BR><HR><BR>Compiler makes several passes before generating the correctmachine code, if it finds an error and does not complete the requirednumber of passes it may show incorrect error messages. For example:<PRE><FONT FACE="Fixedsys">#make_COM#ORG 100hMOV AX, 0MOV CX, 5m1: INC AXLOOP m1 ; not a real error!MOV AL, 0FFFFh ; error is here.RET</FONT></PRE><FONT FACE="MS Sans Serif" SIZE=2>List of generated errors:<BR>(7) Condition Jump out of range!: LOOP m1<BR>(9) Wrong parameters: MOV AL, 0FFFFh<BR>(9) Operands do not match: Second operand is over 8 bits! <BR></FONT><BR>First error message (7) is incorrect, compiler did not finish calculatingthe offsets for labels, so it presumes that the offset of <B>m1</B> labelis <B>0000</B>, that address is out of the range because we start at offset <B>100h</B>.<BR><BR>Make correction to this line: <B>MOV AL, 0FFFFh</B>(AL cannot hold <B>0FFFFh</B> value). This fixes both errors!For example:<BR><BR><PRE><FONT FACE="Fixedsys">#make_COM#ORG 100hMOV AX, 0MOV CX, 5m1: INC AXLOOP m1 ; same code no error!MOV AL, 0FFh ; fixed!RET</FONT></PRE><HR><BR>When saving a compiled file, compiler also saves 2 other files that are usedfor Emulator to show actual source when you run it, and select corresponding lines.<UL><LI> <B>*.~asm</B> - this file contains the original source code that was used to make an executable file.<BR><BR></LI><LI> <B>*.debug</B> - this file has information that enables the emulator select lines of original source code while running the machine code.<BR><BR></LI><LI> <B>*.symbol</B> - Symbol Table, it contains information that enables to show the "Variables" window. It is a text file, so you may view it in any text editor. <BR><BR></LI><LI> <B>*.binf</B> - this file contains information that is used by emulator to load BIN file at specified location, and set register values prior execution; (created only if an executable is a BIN file). <BR><BR></LI></UL><HR></FONT></TD></TR></TABLE><BR></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -