This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Why cannot the cross-assembler work on this asm code?

Hi,

I am working on assembler code with arm-linux-gnueabihf-as with a third part code project. I find that the assembler has errors:

> arm-linux-gnueabihf-as test_sp0.s

test_sp0.s: Assembler messages:

test_sp0.s:1: Error: junk at end of line, first unrecognized character is `='

test_sp0.s:3: Error: bad instruction `arm'

test_sp0.s:5: Error: bad instruction `area ||.text||,CODE,READONLY,ALIGN=2'

test_sp0.s:7: Error: bad instruction `export fl_array_m_ic32'

test_sp0.s:9: Error: bad instruction `input'

test_sp0.s:10: Error: bad instruction `r0 -p_i0_left'

test_sp0.s:11: Error: bad instruction `r1 -p_i0_right'

test_sp0.s:12: Error: bad instruction `r2 -p_i1_left'

test_sp0.s:13: Error: bad instruction `r3 -p_i1_right'

test_sp0.s:14: Error: bad instruction `sp -p_ot_left'

test_sp0.s:15: Error: bad instruction `sp +4-p_ot_right'

test_sp0.s:16: Error: bad instruction `sp +8-count'

test_sp0.s:17: Error: bad instruction `sp +12-shift'

test_sp0.s:19: Error: bad instruction `return'

test_sp0.s:20: Error: bad instruction `n/A'

test_sp0.s:22: Error: bad instruction `global Variables Accessed'

test_sp0.s:23: Error: bad instruction `none'

test_sp0.s:24: Error: bad instruction `cortex_a8'

for the code:

                    ARM
                    AREA ||.text||, CODE, READONLY, ALIGN=2
                    EXPORT  fl_array_m_ic32

;   Input

;   r0 - p_i0_left
;   r1 - p_i0_right
;   r2 - p_i1_left
;   r3 - p_i1_right
;   sp - p_ot_left
;   sp + 4  - p_ot_right
;   sp + 8  - count
;   sp + 12 - shift

;

;   Return

;   N/A

;

;   Global Variables Accessed

;   None
;;;;;;;;;;;;;;;;;;;;;;;;;;;;                    IF  :DEF:CORTEX_A8

;................................................................................

fl_array_m_ic32     PROC

It is obvious that the assembler treats the comment char ';' as asm instruction. I used other compiler before, but not arm-linux-gnueabihf-as. From the asm code format, do you think what assembler can work on it? or are there some switches with arm-linux-gnueabihf-as to work on this asm code?

Thanks,

Parents Reply Children
  • Unfortunately, it's not possible to emulate all the directives, and I cannot test any of my theories on ARMASM, because I do not have a computer, which can run this assembler.

    That said, I'll try and give you some ideas on how you can emulate and work-around some problems using macros and #define directives.

    For instance, it's not possible to emulate IF, ELSE and ENDIF using assembler macros.

    You could write an external include file, which you then can include at either the top of your source file or from the command-line.

    Using .include at the top of your source file might not be a good idea, as ARMASM would most likely choke on this directive.

    Another option is to use the C Pre-Processor with the GNU assembler. If you do this, you will be able to use the #define directive, which is usually available in C.

    As far as I understand, the '#' character start a comment line in ARMASM. If I'm right, it would be possible to make a more intelligent solution. For example:

    At the top of your source file:

    #include "GNU-Macros.i"

         GET ARM-Macros.i

    ... other code...

    In GNU-Macros.i, you would then mix #define and .macro/.endm directives. Here #define allows you to emulate the IF, ELSE and ENDIF directives, since the pre-processor works like a 'find/replace' function.

    So you'd probably want these 3 lines in GNU-Macros.i:

    #define IF .if

    #define ELSE .else

    #define ENDIF .endif

    #define END .end

    When we're including GNU-Macros.i, we do not want our ARM-Macros.i include file, so we will ignore ARMASM's GET directive and use this only for our ARM-Macros.i. We'll add this macro:

         .macro GET     ignore:vararg

         .endm

    At this point, we can start adding some simple macros for emulation; this ALIGN directive is incomplete, but it allows you to use ALIGN with both zero and one parameter; the offset, pad and padsize parameters are all ignored:

         .macro ALIGN     expr,offset,pad,padsize

         .align     \expr,

         .endm

         .macro     ARM

         .arm

         .endm

         .macro     THUMB

         .thumb

         .endm

         .macro     DCB     data:vararg

         .byte     \data

         .endm

         .macro     EXPORT     labels

         .global     \labels

         .endm

         .macro     ALIAS     name,value

         .equ     \name,\value

         .endm

    You can add more if necessary. Now let's have a look at workarounds.

    The EQU directive has a problem: It requires a label at the beginning of the line. The GNU Assembler's .macro directive does not provide a way to fetch the label name, so we'll have to roll our own 'compatibility macro'.

         .macro     ENUM     label,value

         .equ     \label,\value

         .endm

    -But that's not all. because if we use ENUM, then ARMASM will choke on it, so we'll need to create an INCLUDE file for ARMASM as well.

         MACRO

         ENUM     $label,$value

    $label     EQU     $value

         ENDM

    ... This means that you should not use the EQU directive in your sources, but the ENUM macro should be used instead.

    The same kind of workaround would be required for the AREA directive. This is called .section on the GNU Assembler, but it has a different syntax, so you'll have to agree with yourself on a better way.

    ... Finally, your source file should contain two lines at the top:

    #include "GNU-Macros.i"

         GET ARM-Macros.i