This is an Assembly language converter from 16-bit Intel (ASM) to 32-bit AT&T (S) syntax.
This article is intended to serve as an example of a practical, large application of SR. Similar techniques can be used to convert between other computer languages or file formats. After you gain an understanding of how this converter works, you can change it to meet your specific needs.
The input is expected to be an ASM assembly file that had been assembled in the 1980’s using the old Borland Turbo Assembler for a 16-bit MCS-86 program. It must use lower-case mnemonics & operands with tabbed columns.
The output will be close to the equivalent S assembly source file for a modern 32-bit Intel processor using AT&T syntax.
There is no automated total converter. The result of this converter will need many details fixed, but the tedious part will be finished for you in a few minutes.
The command line needs you to just type 2 file names without extensions. The first is the name of the batch file below. I called it “Intel2ATT.BAT”. The second is the name of the old ASM file that you want to convert. For example:
This converter uses the following rules to target the GNU AS (GAS) assembler:
Byte registers require a “$” prefix.
Tabs, CR/LF and trailing white-space are OK, but trailing white-space is removed, anyway.
Register: AS: No extra punctuation; for example loc. Intel: Square brackets; for example [loc].
Address: AS: Prefix with ‘$’; for example $loc. Intel: No extra punctuation; for example loc.
Memory: AS: Parentheses; for example (%eax). Intel: Square brackets; for example [eax].
size: AS: Explicit in op-code; for example movw for word. Intel: Implicit, deduced by assembler; for example mov.
? is no longer accepted as a value.
The process includes a tab ending each line and before comments.
Click here and copy the listing, paste it into a text editor and save it as “Intel2ATT.BAT”. NOTEPAD can do it.
– Gareth B. Dolby