1

I am trying to compile a project with multiple c files and an assembly file written in ARMv8, which I have not done before, so I am having some trouble understanding a few error messages I am getting.

I consistently receive the "unknown mnemonic" error throughout, for almost every single line. For example, for the following snippet of code,

100    ## Save oSum to the stack.
101    pushq %rdx
102
103    ## unsigned long ulCarry
104    subq $8, %rsp
105 
106    ## unsigned long ulSum
107    subq $8, %rsp
108
109    ## long lIndex
110    subq $8, %rsp
111
112    ## long lSumLength
113    subq $8, %rsp

I receive the following messages,

file.s:101: Error: unknown mnemonic `pushq' -- `pushq %rdx'
file.s:104: Error: unknown mnemonic `subq' -- `subq $8,%rsp'
file.s:107: Error: unknown mnemonic `subq' -- `subq $8,%rsp'
file.s:110: Error: unknown mnemonic `subq' -- `subq $8,%rsp'
file.s:113: Error: unknown mnemonic `subq' -- `subq $8,%rsp'

What I am I doing wrong here? How can I fix this?

Your help is much appreciated.

Rose Ben Ann
  • 69
  • 1
  • 1
  • 5
  • 4
    I'm no assembler expert (especially wrt ARM) but they don't look like ARM instructions, to me. They look more like x86-x64 codes. – Adrian Mole Dec 07 '22 at 10:03
  • 1
    You will not be able to assemble this code for armv8 as it is written for amd64. You'll have to rewrite it from scratch or find a way to compile the project without using this file. – fuz Dec 07 '22 at 10:53
  • That hand-written asm is for x86-64 (aka AMD64), not AArch64. And BTW, it's ridiculously inefficient. One `subq $32, %rsp` would have the same effect in one instruction, reserving space for multiple local vars. If the rest of the asm is written that inefficiently, you might be better off with a pure C fallback implementation compiled with an optimizing compiler, if the project has one. – Peter Cordes Dec 07 '22 at 14:57

1 Answers1

0

Problem is actually really simple, what you were typing was 64-bit x86 Assembly, not ARM. The code you've written does have an equivalent in ARM Assembly, but the register names and instruction names will be different. I believe armv8 is a 32-bit architecture (there's a 64-bit version, commonly called AArch64 or arm64.) I'm not familiar with that unfortunately. Try this:

push {r4,r5,r6,lr}  //ARM calling convention requires an even number of regs to be pushed
sub sp,sp,32
puppydrum64
  • 1,598
  • 2
  • 15
  • ARMv8 introduces 64-bit mode, as well as adding some new instructions for 32-bit mode. When people say "armv8" in a context like this, talking about an architecture, they usually mean it as a synonym for AArch64, even though it doesn't necessarily imply that. If so, the question is mis-tagged as [arm] instead of [arm64]. Doesn't really change the key point of the answer, though, that x86-64 AT&T syntax isn't any kind of ARM. – Peter Cordes Dec 09 '22 at 15:38
  • Maybe the person asking was used to using a cross-assembler and got confused? – puppydrum64 Dec 09 '22 at 15:40