A while ago I wanted to learn ARM assembly and after some search for existing tools to execute and debug instructions, finally decided that the best way to learn an assembly would be to write an emulator for it.
C seemed a good choice, as being a middle-level language, it provides high-level constructs while still providing low-level details that are closer to assembly language.
If you need more information about ARM assembly Pete Cockerell’s ARM Assembly Language Programming has almost all the information one may need.
This application emulates the following behaviours of an ARM assembler.
- Pipeline: Size 4
- Reserves memory locations for; Interrupt instructions and user instructions.
- Counts the cycles for each instruction and total cycles.
- Data processing instructions: Sets the overflow and carry flags.
- Branch instructions: Uses a stack to store the link data if need.
- Data transfer instructions
- Interrupts instructions: Executes the interrupt instruction in the input instructions set or accepts hardware instruction before fetching a new instruction.
- Prints out the registers, user accessible memory, stack memory and the status flags. “debugEnabled” and “instructionLogEnabled” variables can be switched on for farther information in the output.
The source code is on GitHub. Feel free to use/edit it as you may.
The ‘ArmEmulator.c’ file in the ‘src’ folder includes all the required code. I used gcc to compile the C code, after installing it, you may just edit the folder path in the ‘Compile_ArmEmulator.bat’ and use it to compile the code.