Memory Testing
March Algorithm
Hardware Testing
Memory Diagnostics
Embedded Systems

March memory testing algorithm (March C-) and how to implement it

Codemia Knowledge Hub ·

A March test detects faults in semiconductor memory by stepping through every address in a fixed order and applying a short sequence of reads and writes to each cell. Each read checks that the cell still holds the value written earlier. March C- is a widely used choice: six elements that detect simple stuck-at and coupling faults.

Terminology

  • March element: a sequence of operations applied to each memory cell, with an address order (ascending ↑ or descending ↓).
  • March test: a sequence of March elements applied to all cells in memory.
  • Operation: a write (w0, w1) or a read expecting a value (r0, r1).

March C- sequence

  1. (w0) Write 0 to all memory cells.
  2. ↑ (r0, w1) Read 0 and write 1 while incrementing through memory addresses.
  3. ↑ (r1, w0) Read 1 and write 0 while incrementing.
  4. ↓ (r0, w1) Read 0 and write 1 while decrementing through memory addresses.
  5. ↓ (r1, w0) Read 1 and write 0 while decrementing.
  6. (r0) Read 0 from all memory cells.

It balances simplicity with effective detection of the standard faults.

Other March variants

  • March A: detects simple address faults.
  • March X: detects more complex fault types, including interaction faults between adjacent cells.

Implementation steps

  1. Initialize memory to a known value to establish a baseline.
  2. Execute the sequence of read/write operations. Choose the March test based on the faults you want to detect.
  3. Control the test environment (temperature, voltage variations) to mimic operating conditions.

Fault checks are often expressed in Boolean logic:

  • Stuck-at faults: F0=C(i)∧¬r(i)F_0 = C(i) \land \neg r(i) flags a fault when a '1' was written and a '0' is read.
  • Address decoding faults: combinations of Boolean operations verify that the address lines work correctly.

Making March tests faster and more targeted

  • Parallel testing: test several memory arrays at once to cut test time.
  • Adaptive testing: adjust the test based on the first failures detected.

March sequences are usually chosen from fault models:

  • Stuck-open faults: detected by consecutive opposite operations where a cell fails to hold the desired state.
  • Transition faults: detected by operations that confirm a cell transitions correctly from one state to the other.

March test example

Below is March C- in C, treating each byte of a buffer as one cell. A real test runs on the memory under test with caching disabled:

c
1#include <stddef.h>
2#include <stdint.h>
3
4/* March C-: returns the first failing address, or -1 if memory passes. */
5long march_c_minus(volatile uint8_t *mem, size_t n)
6{
7    size_t i;
8
9    for (i = 0; i < n; i++) mem[i] = 0;                 /* (w0)      */
10
11    for (i = 0; i < n; i++) {                           /* up (r0,w1) */
12        if (mem[i] != 0) return (long)i;
13        mem[i] = 1;
14    }
15    for (i = 0; i < n; i++) {                           /* up (r1,w0) */
16        if (mem[i] != 1) return (long)i;
17        mem[i] = 0;
18    }
19    for (i = n; i-- > 0; ) {                            /* down (r0,w1) */
20        if (mem[i] != 0) return (long)i;
21        mem[i] = 1;
22    }
23    for (i = n; i-- > 0; ) {                            /* down (r1,w0) */
24        if (mem[i] != 1) return (long)i;
25        mem[i] = 0;
26    }
27    for (i = 0; i < n; i++)                             /* (r0)      */
28        if (mem[i] != 0) return (long)i;
29
30    return -1;
31}

Each loop is one March element from the sequence above, and the descending loops use i-- > 0 so the unsigned index stops cleanly at address 0.


Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms