Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Converting ARM assembly to GNU assembly

577 views
Skip to first unread message

Joy Kull

unread,
Oct 24, 2001, 12:23:11 PM10/24/01
to
I am looking for a way to convert handwritten ARM assembly files to
GNU assembly. The application I am working on will be running on
Linux. Is it possible to accomplish this without modifying the
original ARM assembly source files, i.e., maybe by using GNU tools
options? Is there an existing utility that would do this conversion?

Daniel Andersson

unread,
Oct 25, 2001, 8:51:32 AM10/25/01
to
Hi,

I looked at this a few month ago and the conclusion is that it will take a
lot of work to succed. The ARMASM and GNUASM differs a lot, both in
functioncall and parameters. However, is it a small file you shall convert
then it will probably go with a macro since you manually can check the
resulting code afterwards but in my case i wanted to convert a whole bunch
of file at the same time and that was a disaster. But as a start there are
some difference in the language that are easy to write in a macro and those
are:

';' -> '@'
IMPORT -> .globl
EXPORT -> .globl
Labels skall ha semicolon efter sig
:AND: -> &
:NOT: -> ~
:OR: -> |
:SHL: -> <<
LABEL EQU 1 -> #define LABEL 1
INCLUDE file.inc -> #include "file.inc"
END -> .end

Regards, Daniel


Joy Kull <jo...@pv.com> wrote in message
news:11431ee2.01102...@posting.google.com...

Eric Fung

unread,
Oct 25, 2001, 9:31:49 AM10/25/01
to
I wrote a little Perl script to do some of the conversion. It doesn't
handle everything, and it will get fooled by some constructs, but it's
a start, IMHO.

---8<---8<---8<---
# ads2gas.pl
# Author: Eric Fung (efung (at) acm.org)
#
# Convert ARM Developer Suite 1.0.1 syntax assembly source to GNU as format
#
# Usage: cat inputfile | perl ads2gas.pl > outputfile
#

while (<STDIN>) {

# Comment character
s/;/@/g;

# Hexadecimal constants prefaced by 0x
s/#&/#0x/g;

# Code directive (ARM vs Thumb)
s/CODE([0-9][0-9])/.code $1/;

# No AREA required
s/^\s*AREA.*$/.text/;

# Make function visible to linker, and make additional symbol with
# prepended underscore
s/EXPORT\s+\|(\w*)\|/.global _$1\n.global $1/;

# No vertical bars required; make additional symbol with prepended
# underscore
s/^\|(\w+)\|/_$1\n$1:/g;

# Labels need trailing colon
s/^(\w+)/$1:/ if !/EQU/;

# EQU directive
s/(.*)EQU(.*)/.equ $1, $2/;

# Begin macro definition
if (/MACRO/) {
$_ = <STDIN>;
s/^/.macro/;
s/\$//g; # remove formal param reference
s/;/@/g; # change comment characters
}

# For macros, use \ to reference formal params
s/\$/\\/g;

# End macro definition
s/MEND/.endm/;

# No need to tell it where to stop assembling
next if /^\s*END\s*$/;

print;

}
---8<---8<---8<---

In article <11431ee2.01102...@posting.google.com>,


--

..
Eric

Joy Kull

unread,
Oct 29, 2001, 5:21:46 PM10/29/01
to
e2f...@student.math.uwaterloo.ca (Eric Fung) wrote in message news:<9r9485$mhk$1...@watserv3.uwaterloo.ca>...

Thanks for your help. We ended up using a Perl script (much like
Eric's) to do the conversion.

Regards,
Joy

0 new messages