This file contains a discussion of the source code for lac, the Legible Assembly Converter. lac was written using FreePascal, and has been released under the GNU General Public License.
lac's purpose is to allow programmers to write in an easy-to-read version of assembly language. lac translates this alternative syntax, which I call "legible assembly" into gas (GNU assembler) code. Here's an example of what a legible assembly program might look like:
#bss // section names start with the # character
varname 8 bytes integer
#data
message 14 bytes string 'Hello, world!\n' // quoted strings are enclosed in grave accents
#text
add @reg to @reg // register names start with the @ character, and prepositions connect arguments
nop
mov 1 to @reg
mov %mem to @reg // memory addresses start with the % character
@reg = @reg + 1 // simple expressions are supported
:label // use colons for labels
mov %mem to @reg
.compiler_directive // compiler directives start with periods
Sections must be entered in order, namely bss then data then text. Rather than using ideas like "word" or "double word", I require the programmer to explicitly define the width of their variables in bytes. Section names, registers, memory addresses and labels all have leading sigils, making the text much easier to parse (and easier to visually scan). Instructions use prepositions to connect their arguments, and single-operator expressions are supported. Quoted strings are enclosed in grave accents to avoid clashes with single- and double-quote characters. lac uses C++-style single-line comments.
lac doesn't preserve spacing, comments or case, because lac's output is intended to be assembled right away rather than shared with others.
Here's the gas-like version of the above example:
.section .bss // section names start with the . character
.lcomm varname, 8 // the .lcomm directive tells gas how large the variable should be
.section .data
message: .ascii "Hello, world!\n" // quoted strings are enclosed in double-quotes
.section .text
add %reg, %reg // in gas, arguments are separated by commas rather than by prepositions
nop
mov $1, %reg
mov mem, %reg // memory addresses are bare numbers
add $1, %reg
label: // gas labels end with colons
mov mem, %reg
.compiler_directive // compiler directives start with periods
To install this tool, unzip lac.zip and place its contents into this path: c:\program files\legible assembly converter\
lac is a command-line program, so to use it, follow this format:
path\lac.exe path\inputFileName path\outputFileName
In the above example, "path" should be replaced with the path to the file. For example, if you unzipped the lac files into c:\lac\, then the first term would be this:
c:\lac\lac.exe
If your login ID was someUser, you're running Windows XP, your input file was a file named input.txt and that file is sitting on your desktop, then the second term would be this:
c:\documents and settings\someUser\desktop\input.txt
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/gpl-3.0.html>.