2

SO, i'm learning assembly on university and there we use Fedora. There we compile programs without any trouble. I got an raspberry pi and i was trying it out with some programs that we have done previously, nothing fancy. But i got some errors that i've never seen before and searched the whole internet and can't seem to figure it out. it's not a 64 x 32 bit problem neither. i've tried using gcc -o lab6 lab6.s as we do during class but got the same error.

The code:

/*
int nums[] = {10, -21, -30, 45};
int main() {
  int i, *p;
  for (i = 0, p = nums; i != 4; i++, p++)
    printf("%d\n", *p);
  return 0;
}
*/

.data
nums:  .int  10, -21, -30, 45
Sf:  .string "%d\n"    ; string de formato para printf

.text
.globl  main
main:

/********************************************************/
/* mantenha este trecho aqui e nao mexa - prologo !!!   */
  pushq   %rbp
  movq    %rsp, %rbp
  subq    $16, %rsp
  movq    %rbx, -8(%rbp)
  movq    %r12, -16(%rbp)
/********************************************************/

  movl  $0, %ebx  /* ebx = 0; */
  movq  $nums, %r12  /* r12 = &nums */

L1:
  cmpl  $4, %ebx  /* if (ebx == 4) ? */
  je  L2          /* goto L2 */

  movl  (%r12), %eax    /* eax = *r12 */

/*************************************************************/
/* este trecho imprime o valor de %eax (estraga %eax)  */
  movq    $Sf, %rdi    /* primeiro parametro (ponteiro)*/
  movl    %eax, %esi   /* segundo parametro  (inteiro) */
  call  printf       /* chama a funcao da biblioteca */
/*************************************************************/

  addl  $1, %ebx  /* ebx += 1; */
  addq  $4, %r12  /* r12 += 4; */
  jmp  L1         /* goto L1; */

L2:  
/***************************************************************/
/* mantenha este trecho aqui e nao mexa - finalizacao!!!!      */
  movq  $0, %rax  /* rax = 0  (valor de retorno) */
  movq  -8(%rbp), %rbx
  movq  -16(%rbp), %r12
  leave
  ret      
/***************************************************************/

error message: pi@raspberrypi:~/Documents/inf1018_LUIZA $ as -o lab6.o lab6.s lab6.s: Assembler messages: lab6.s:13: Error: bad instruction string de formato para printf' lab6.s:21: Error: bad instructionpushq %rbp' lab6.s:22: Error: bad instruction movq %rsp,%rbp' lab6.s:23: Error: bad instructionsubq $16,%rsp' lab6.s:24: Error: bad instruction movq %rbx,-8(%rbp)' lab6.s:25: Error: bad instructionmovq %r12,-16(%rbp)' lab6.s:28: Error: bad instruction movl $0,%ebx' lab6.s:29: Error: bad instructionmovq $nums,%r12' lab6.s:32: Error: bad instruction cmpl $4,%ebx' lab6.s:33: Error: bad instructionje L2' lab6.s:35: Error: bad instruction movl (%r12),%eax' lab6.s:39: Error: bad instructionmovq $Sf,%rdi' lab6.s:40: Error: bad instruction movl %eax,%esi' lab6.s:41: Error: bad instructioncall printf' lab6.s:44: Error: bad instruction addl $1,%ebx' lab6.s:45: Error: bad instructionaddq $4,%r12' lab6.s:46: Error: bad instruction jmp L1' lab6.s:51: Error: bad instructionmovq $0,%rax' lab6.s:52: Error: bad instruction movq -8(%rbp),%rbx' lab6.s:53: Error: bad instructionmovq -16(%rbp),%r12' lab6.s:54: Error: bad instruction leave' lab6.s:55: Error: bad instructionret '

ldncf
  • 21
  • 3
  • 2
    Your RPi has an ARM CPU. You're trying to assemble x86-64 assembly with an ARM assembler, so it's normal that none of the code is valid ARM instructions. Look at `gcc -S` output from a C program on your RPi. – Peter Cordes Sep 25 '18 at 02:46

0 Answers0