<html xmlns="http://www.w3.org/1999/xhtml"><head><meta charset="utf-8"><meta name="generator" content="pdf2htmlEX"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><link rel="stylesheet" href="https://csdnimg.cn/release/download_crawler_static/css/base.min.css"><link rel="stylesheet" href="https://csdnimg.cn/release/download_crawler_static/css/fancy.min.css"><link rel="stylesheet" href="https://csdnimg.cn/release/download_crawler_static/1018907/raw.css"><script src="https://csdnimg.cn/release/download_crawler_static/js/compatibility.min.js"></script><script src="https://csdnimg.cn/release/download_crawler_static/js/pdf2htmlEX.min.js"></script><script>try{pdf2htmlEX.defaultViewer = new pdf2htmlEX.Viewer({});}catch(e){}</script><title></title></head><body><div id="sidebar" style="display: none"><div id="outline"></div></div><div id="pf1" class="pf w0 h0" data-page-no="1"><div class="pc pc1 w0 h0"><img class="bi x0 y0 w1 h1" alt="" src="https://csdnimg.cn/release/download_crawler_static/1018907/bg1.jpg"><div class="c x0 y1 w2 h2"><div class="t m0 x1 h3 y2 ff1 fs0 fc0 sc0 ls0 ws0">Internals of the Netwide Assembler</div><div class="t m0 x1 h3 y3 ff1 fs0 fc0 sc0 ls0 ws0">==================================</div><div class="t m0 x1 h3 y4 ff1 fs0 fc0 sc0 ls0 ws0">The Netwide Assembler is intended to be a modular, re-usable x86</div><div class="t m0 x1 h3 y5 ff1 fs0 fc0 sc0 ls0 ws0">assembler, which can be embedded in other programs, for example as</div><div class="t m0 x1 h3 y6 ff1 fs0 fc0 sc0 ls0 ws0">the back end to a compiler.</div><div class="t m0 x1 h3 y7 ff1 fs0 fc0 sc0 ls0 ws0">The assembler is composed of modules. The interfaces between them</div><div class="t m0 x1 h3 y8 ff1 fs0 fc0 sc0 ls0 ws0">look like:</div><div class="t m0 x2 h3 y9 ff1 fs0 fc0 sc0 ls0 ws0"> +--- preproc.c ----+</div><div class="t m0 x2 h3 ya ff1 fs0 fc0 sc0 ls0 ws0"> |<span class="_ _0"> </span> |</div><div class="t m0 x2 h3 yb ff1 fs0 fc0 sc0 ls0 ws0"> +---- parser.c ----+</div><div class="t m0 x2 h3 yc ff1 fs0 fc0 sc0 ls0 ws0"> |<span class="_ _1"> </span> | |</div><div class="t m0 x2 h3 yd ff1 fs0 fc0 sc0 ls0 ws0"> | float.c |</div><div class="t m0 x2 h3 ye ff1 fs0 fc0 sc0 ls0 ws0"> |<span class="_ _0"> </span> |</div><div class="t m0 x2 h3 yf ff1 fs0 fc0 sc0 ls0 ws0"> +--- assemble.c ---+</div><div class="t m0 x2 h3 y10 ff1 fs0 fc0 sc0 ls0 ws0"> | | |</div><div class="t m0 x3 h3 y11 ff1 fs0 fc0 sc0 ls0 ws0">nasm.c ---+ insnsa.c +--- nasmlib.c</div><div class="t m0 x2 h3 y12 ff1 fs0 fc0 sc0 ls0 ws0"> |<span class="_ _0"> </span> |</div><div class="t m0 x2 h3 y13 ff1 fs0 fc0 sc0 ls0 ws0"> +--- listing.c ----+</div><div class="t m0 x2 h3 y14 ff1 fs0 fc0 sc0 ls0 ws0"> |<span class="_ _0"> </span> |</div><div class="t m0 x2 h3 y15 ff1 fs0 fc0 sc0 ls0 ws0"> +---- labels.c ----+</div><div class="t m0 x2 h3 y16 ff1 fs0 fc0 sc0 ls0 ws0"> |<span class="_ _0"> </span> |</div><div class="t m0 x2 h3 y17 ff1 fs0 fc0 sc0 ls0 ws0"> +--- outform.c ----+</div><div class="t m0 x2 h3 y18 ff1 fs0 fc0 sc0 ls0 ws0"> |<span class="_ _0"> </span> |</div><div class="t m0 x2 h3 y19 ff1 fs0 fc0 sc0 ls0 ws0"> +----- *out.c -----+</div><div class="t m0 x1 h3 y1a ff1 fs0 fc0 sc0 ls0 ws0">In other words, each of `preproc.c', `parser.c', `assemble.c',</div><div class="t m0 x1 h3 y1b ff1 fs0 fc0 sc0 ls0 ws0">`labels.c', `listing.c', `outform.c' and each of the output format</div><div class="t m0 x1 h3 y1c ff1 fs0 fc0 sc0 ls0 ws0">modules `*out.c' are independent modules, which do not directly</div><div class="t m0 x1 h3 y1d ff1 fs0 fc0 sc0 ls0 ws0">inter-communicate except through the main program.</div><div class="t m0 x1 h3 y1e ff1 fs0 fc0 sc0 ls0 ws0">The Netwide *Disassembler* is not intended to be particularly</div><div class="t m0 x1 h3 y1f ff1 fs0 fc0 sc0 ls0 ws0">portable or reusable or anything, however. So I won't bother</div><div class="t m0 x1 h3 y20 ff1 fs0 fc0 sc0 ls0 ws0">documenting it here. :-)</div><div class="t m0 x1 h3 y21 ff1 fs0 fc0 sc0 ls0 ws0">nasmlib.c</div><div class="t m0 x1 h3 y22 ff1 fs0 fc0 sc0 ls0 ws0">---------</div><div class="t m0 x1 h3 y23 ff1 fs0 fc0 sc0 ls0 ws0">This is a library module; it contains simple library routines which</div><div class="t m0 x1 h3 y24 ff1 fs0 fc0 sc0 ls0 ws0">may be referenced by all other modules. Among these are a set of</div><div class="t m0 x1 h3 y25 ff1 fs0 fc0 sc0 ls0 ws0">wrappers around the standard `malloc' routines, which will report a</div><div class="t m0 x1 h3 y26 ff1 fs0 fc0 sc0 ls0 ws0">fatal error if they run out of memory, rather than returning NULL.</div><div class="t m0 x1 h3 y27 ff1 fs0 fc0 sc0 ls0 ws0">preproc.c</div><div class="t m0 x1 h3 y28 ff1 fs0 fc0 sc0 ls0 ws0">---------</div><div class="t m0 x1 h3 y29 ff1 fs0 fc0 sc0 ls0 ws0">This contains a macro preprocessor, which takes a file name as input</div><div class="t m0 x1 h3 y2a ff1 fs0 fc0 sc0 ls0 ws0">and returns a sequence of preprocessed source lines. The only symbol</div><div class="t m0 x1 h3 y2b ff1 fs0 fc0 sc0 ls0 ws0">exported from the module is `nasmpp', which is a data structure of</div><div class="t m0 x1 h3 y2c ff1 fs0 fc0 sc0 ls0 ws0">type `Preproc', declared in nasm.h. This structure contains pointers</div><div class="t m0 x1 h3 y2d ff1 fs0 fc0 sc0 ls0 ws0">to all the functions designed to be callable from outside the</div><div class="t m0 x1 h3 y2e ff1 fs0 fc0 sc0 ls0 ws0">module.</div><div class="t m0 x1 h3 y2f ff1 fs0 fc0 sc0 ls0 ws0">parser.c</div><div class="t m0 x1 h3 y30 ff1 fs0 fc0 sc0 ls0 ws0">--------</div><div class="t m0 x1 h3 y31 ff1 fs0 fc0 sc0 ls0 ws0">This contains a source-line parser. It parses `canonical' assembly</div><div class="t m0 x1 h3 y32 ff1 fs0 fc0 sc0 ls0 ws0">source lines, containing some combination of the `label', `opcode',</div><div class="t m0 x1 h3 y33 ff1 fs0 fc0 sc0 ls0 ws0">`operand' and `comment' fields: it does not process directives or</div><div class="t m0 x1 h3 y34 ff1 fs0 fc0 sc0 ls0 ws0">macros. It exports two functions: `parse_line' and `cleanup_insn'.</div><div class="t m0 x1 h3 y35 ff1 fs0 fc0 sc0 ls0 ws0">`parse_line' is the main parser function: you pass it a source line</div></div></div><div class="pi" data-data='{"ctm":[1.611850,0.000000,0.000000,1.611850,0.000000,0.000000]}'></div></div></body></html>