In our university we have a computer's technology subject in which we have to program in ARM's assembly language.

We have the chance to use a simulator but I was wondering if I was able to execute them in my own Raspberry Pi and to check how the registers are changing. Like on the left of the attached image.



You may be able to do what you want with the debugger gdb.

Compile and link a small test program.


#include <stdio.h>

int main(int argc, char *argv[])
   int i;
   for (i=0; i<10; i++) printf("%d\n", i*i);
   return 0;

gcc -o q q.c

gdb q

Enter the commands

layout asm

layout reg


and then si to single step

┌──Register group: general─────────────────────────────────────────────────────┐
│rax            0x5555555546b0   93824992233136                                │
│rbx            0x0      0                                                     │
│rcx            0x0      0                                                     │
│rdx            0x7fffffffe1d8   140737488347608                               │
│rsi            0x7fffffffe1c8   140737488347592                               │
│rdi            0x1      1                                                     │
│rbp            0x7fffffffe0e0   0x7fffffffe0e0                                │
│rsp            0x7fffffffe0e0   0x7fffffffe0e0                                │
│r8             0x555555554770   93824992233328                                │
│r9             0x7ffff7de8a50   140737351944784                               │
│r10            0x2      2                                                     │
│r11            0x1      1                                                     │
│r12            0x555555554580   93824992232832                                │
   │0x5555555546b0 <main>           push   %rbp                                │
   │0x5555555546b1 <main+1>         mov    %rsp,%rbp                           │
B+>│0x5555555546b4 <main+4>         sub    $0x20,%rsp                          │
   │0x5555555546b8 <main+8>         mov    %edi,-0x14(%rbp)                    │
   │0x5555555546bb <main+11>        mov    %rsi,-0x20(%rbp)                    │
   │0x5555555546bf <main+15>        movl   $0x0,-0x4(%rbp)                     │
   │0x5555555546c6 <main+22>        jmp    0x5555555546e6 <main+54>            │
   │0x5555555546c8 <main+24>        mov    -0x4(%rbp),%eax                     │
   │0x5555555546cb <main+27>        imul   -0x4(%rbp),%eax                     │
   │0x5555555546cf <main+31>        mov    %eax,%esi                           │
   │0x5555555546d1 <main+33>        lea    0xac(%rip),%rdi        # 0x555555554│
   │0x5555555546d8 <main+40>        mov    $0x0,%eax                           │
   │0x5555555546dd <main+45>        callq  0x555555554560 <printf@plt>         │
native process 4701 In: main                           L??   PC: 0x5555555546b4 
(gdb) layout reg
(gdb) start
Temporary breakpoint 1 at 0x6b4
Starting program: /home/common/code/q

Temporary breakpoint 1, 0x00005555555546b4 in main ()

You can use gdb to debug assembly code and check the registers. It is available for Raspbian and likely for most other Linux distributions that run on the Pi. It also supports ARM as a target processor.

See also: ARM assembler in Raspberry Pi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.