Program execution by an ARM processor?

Thread Starter

gogo00

Joined Oct 28, 2023
37
I'm trying to understand how ARM microcontrollers execute programs, but I'm encountering some confusion regarding two key concepts: instruction set and clock cycle. Despite reviewing numerous PDF files, I still lack clarity.

My current understanding is that we write C code, the compiler transforms it into an executable file, and then we use a programmer to load the hex file into the microcontroller's memory. The program counter points to the starting location, and the processor sequentially executes operations for instructions at the given address. I believe that the time taken for the processor to execute an operation is referred to as a clock cycle.
 

Papabravo

Joined Feb 24, 2006
21,227
I'm trying to understand how ARM microcontrollers execute programs, but I'm encountering some confusion regarding two key concepts: instruction set and clock cycle. Despite reviewing numerous PDF files, I still lack clarity.

My current understanding is that we write C code, the compiler transforms it into an executable file, and then we use a programmer to load the hex file into the microcontroller's memory. The program counter points to the starting location, and the processor sequentially executes operations for instructions at the given address. I believe that the time taken for the processor to execute an operation is referred to as a clock cycle.
Which ARM processor are we talking about?
 

MrChips

Joined Oct 2, 2009
30,823
I'm trying to understand how ARM microcontrollers execute programs, but I'm encountering some confusion regarding two key concepts: instruction set and clock cycle. Despite reviewing numerous PDF files, I still lack clarity.

My current understanding is that we write C code, the compiler transforms it into an executable file, and then we use a programmer to load the hex file into the microcontroller's memory. The program counter points to the starting location, and the processor sequentially executes operations for instructions at the given address. I believe that the time taken for the processor to execute an operation is referred to as a clock cycle.
You are only partially correct.

(1) In doesn't matter if it is an ARM or not an ARM. It applies to any MCU.

(2) The compiler does not create an executable file. The compiler converts the C code to ASM code. An assembler converts ASM code to machine code or object code which is binary. The linker converts the collection of object codes into another file which is also binary. A hex file is still a binary file. A hex file means that the binary is encoded using hexadecimal characters. The programmer does not necessarily need a hex file to load the firmware to the MCU's memory. It uses whatever file format it is designed to use.

(3) A clock cycle usually refers to the frequency of the processor's functional clock frequency. A processor could be running off an 8MHz crystal. Yet, the internal clock could be much higher, for example, 250MHz.

(4) Some processors will execute one instruction in one cycle. Other processors will require n cycles to complete the instruction.
 

Thread Starter

gogo00

Joined Oct 28, 2023
37
I believe the Arm processor executes instructions in one cycle, while the PIC microcontroller takes more cycles. Is this correct? If no, could someone explain why Arm is generally considered faster than PIC architecture? My choice of ARM is cortexM0
 

Irving

Joined Jan 30, 2016
3,897
Arm is generally considered faster than PIC architecture
Depends on PIC chosen and which/whose implementation of ARM M0, not all ARMs are created equal. ARM is 32bit so cant compare to 8 or 16bit PICs. PIC32MZ can go to 252MHz core clock.

Forgive me, but your questions suggest you have little experience working with advanced microcontrollers at the hardware level. Choice of MPU isn't just about clock speed, but a slew of other requirements, eg on-chip peripherals, interrupt latency, memory sizing & interfacing, cache sizing, pipeline depth, etc, etc.

Regarding instruction set, specifically the ARM is a load & store architecture so all math operation work between CPU registers, but the registers have to be loaded from, and saved to, memory explicitly. These take extra cycles.

To process

int a,b,c;

c = a + b ;


in ARM is:

LOAD reg1, a
LOAD reg2, b
ADD reg1, reg2 -> reg3
STO reg3, c

each takes 2 clock cycles. Accessing peripherals adds sync cycles to align with peripheral bus speed.
 

nsaspook

Joined Aug 27, 2009
13,312
Even the lowly PCI18 has an instruction pipeline. An idle clock is a terrible thing to waste.
https://onlinedocs.microchip.com/ox...UID-D4CF9DB8-0959-4477-A150-3F8B34FD3D30.html
1705594886818.png
An “Instruction Cycle” consists of four Q cycles: Q1 through Q4. The instruction fetch and execute are pipelined in such a manner that a fetch takes one instruction cycle, while the decode and execute take another instruction cycle. However, due to the pipelining, each instruction effectively executes in one cycle. If an instruction causes the Program Counter to change (e.g., GOTO), then two cycles are required to complete the instruction as shown in the figure below.
 

Ian0

Joined Aug 7, 2020
9,842
I believe the Arm processor executes instructions in one cycle, while the PIC microcontroller takes more cycles. Is this correct? If no, could someone explain why Arm is generally considered faster than PIC architecture? My choice of ARM is cortexM0
Cortex M executes most instructions in one cycle, but memory fetches take two.PICs execute all instructions except GOTOs in one cycle, GOTOs take 2.
Cortex LDM instructions take one cycle per register.
Have you read Joseph Yiu’s book “the definitive guide to the Cortex M”. It’s all in there.
 
Top