Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!usenet.stanford.edu!news.iecc.com!.POSTED!nerds-end From: Ivan Godard Newsgroups: comp.compilers Subject: Re: Best tools for writing an assembler? Date: Tue, 18 Feb 2014 23:23:29 -0800 Organization: A noiseless patient Spider Lines: 20 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <14-02-021@comp.compilers> References: <14-02-018@comp.compilers> NNTP-Posting-Host: news.iecc.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: miucha.iecc.com 1392848576 93994 64.57.183.58 (19 Feb 2014 22:22:56 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Wed, 19 Feb 2014 22:22:56 +0000 (UTC) Keywords: assembler Posted-Date: 19 Feb 2014 17:22:56 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:1100 On 2/18/2014 4:04 PM, tpphysik@gmail.com wrote: > I want to write an assembler for my own processor architecture. It > would be of middle complexity. ... I strongly recommend the approach we took in the Mill assembler: we use the C++ compiler as the first pass, then execute the resulting program as the second pass. You write a C++ function for each machine operation: "add(regNum r1, regNum r2)" or whatever. The bodies of each of these call the emitters with the bit pattern to use, and the emitters pack the bits into the output. Note that the C++ forms the meta-language which is traditionally a macro language. Thus you can rite: for(int i=0; i < 8; ++i) store(b+4*i, regs[i]); and get the eight stores to flush your registers. We actually generate all the function definitions from our specification machinery, but you can wrte them by hand too, and the work will still be much less than writing, debugging and documenting a traditional assembler.