Emulate ARM x32 architecture
Emulate ARM x64 architecture https://934.medium.com/emulate-arm-x64architecture-99fb880de90b
This is a guide step by step to compile and debug ARM x32 code with other CPU architecture on Linux.
Install some GNU and Linux tools:
$ sudo apt-get update && sudo apt-get upgrade -y
$ sudo apt-get install build-essential
Compilers for each ARM architecture
ARM X32
$ sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
Install other tool for executing and debugging:
$ sudo apt-get install qemu qemu-user qemu-user-static
Degub:
$ sudo apt-get install gdb-multiarch
Example ARM x32 :
create a file called hello_armx32.s
$ vim hello_armx32.s

Assemble and Link
$ arm-linux-gnueabihf-as -g hello_armx32.s -o hello_armx32.o
Note: don’t forget flag -g for debugging
$ arm-linux-gnueabihf-ld hello_armx32.o -o hello_armx32
execute:
./hello_armx32
or
qemu-arm ./hello_armx32
Debugging:
We go to use qemu-arm and gdb-multiarch for debugging program because ARM processor use different registers and qemu helps to emulate them.
First step:
Create a gdb server with qemu and its port with this command:
$ qemu-arm -g 1234 ./hello_armx32
Note: you can use another number for the port but it must be the same in gdb-multiarch.
It waits for response. Then, start gdb-multiarch with next commands:
$ gdb-multiarch -q — nh -ex ‘set architecture arm’ -ex ‘file hello_arm32’ -ex ‘target remote :1234’ -ex ‘layout split’ -ex ‘layout regs’
- -q : Do not print version number on startup.
- — nh: Do not read ~/.gdbinit.
- -ex: Execute a single GDB command.
- Set architecture arm: specifies type of architecture
- Layout split: Divide screen to show code.
- Layout reges: Shows all registers of ARM achitecture.
Note: You can remove some flags used for gdb-multiarch like layout split or layout regs but never -ex ‘target remote : 1234’ it binds with qemu port.

start to debug :
(gdb)b _start
Note: dont use gdb command: run
(gdb) next
Note: gdb uses normal commands for debugging.
That’s all. Now to learn to program in ARM x32
Emulate ARM x64 architecture https://934.medium.com/emulate-arm-x64architecture-99fb880de90b