1

I have a raspberry pi 2 & 4 and I have the same issue on both when I try to compile this assembler code.

filename : first.s

.global _start

_start: 
    mov r1, #20
    mov r2, #10
    mov r3, #90
    ADD r2, r1, r3
    svc 0

I'm using the command:

as -mfpu=vfpv4 -o first.o first.s
ld -o first first.o

using gdb allows me to step through everything and checking the registers with "info registers" everything looks fine. The at the end of the program it gives Illegal Instructions. It give illegal instruction if I comment out the svc line, the ADD line, etc.

Rick Dearman
  • 356
  • 2
  • 12
  • Thanks for posting a detailed list of steps to reproduce your issue! This makes it very easy to help you. Keep up with that! I have linked a duplicate question about the same kind of situation. Despite it being about an x86 program, the answer given there applies to your question exactly the same way. – fuz Sep 03 '20 at 20:47
  • Yes that is the answer. Pity the book I'm reading didn't point this out! – Rick Dearman Sep 03 '20 at 21:38

1 Answers1

2

When your program ends, the CPU just falls off the end and starts executing random crap. To cleanly exit your program, you have to actually call the exit syscall. Take a look at https://peterdn.com/post/2012/01/14/hello-world-in-arm-assembly/