May 17, 2018

A lightning course in ESP32 assembly language

Note: This is a mere beginning, and I have never finished it. You may want to take a look at my executive summary of assembly for the Xtensa processor (which I wrote for my ESP8266 pages). It is entirely relevant, as the ESP32 has two of these as cores. Someday when I do finish this, I will need to add a list of differences between the esp8266 and esp32 processors.

If you have never dealt with assembly language before, this is going to be hopelessly fast. Sorry about that.

The ESP32 has 16 registers (actually more once you get involved with the register window business, but never mind that for now. They are designated a0 through a15.
Two of them are special. a0 is used for subroutine return addresses. a1 is the stack pointer. You can use these as general registers as long as you understand what you are doing.

Instructions are either 16 or 24 bits in size, but you rarely care about that. This is a RISC machine with a load/store architecture. Data flow in the assembler syntax used is right to left, with some exceptions (notably the s32i instruction). Think of it like an assignment statement in C. Here are some examples with C pseudo code in comments

    movi    a0, 0		; a0 = 0
    and	    a3, a3, a2		; a3 = a3 & a2
    sub     a13, a13, a14	; a13 -= a14
    l32i.n  a3, a2, 0		; a3 = *a2
    s32i.n  a3, a2, 0		; *a2 = a3
    addi    a8, a4, -1		; a8 = a4 - 1
The l32r instruction fetches a 32 bit constant that is stored (dumped) someplace nearby (hence the actual address where the constant is dumped is of little real interest).
l32r    a3, [0x0000abab]	; a3 = 0x0000abab

Feedback? Questions? Drop me a line!

Tom's Computer Info /