The MSP430 Time Machine
A simulation of the MSP430G2553, the chip on TI's LaunchPad: a 16-bit CPU with 16 registers, 512 bytes of RAM and 16 KB of flash. Every instruction you run is recorded, so you can step backwards, scrub the timeline, and find the exact moment any byte changed.
Getting around
| → | step one instruction | ← | step back in time |
| Space | run / pause | Shift→ | step over a CALL |
| Home End | start / end of history | Ctrl⏎ | assemble & restart |
| B (hold) | press button S2 | gutter click | toggle a breakpoint |
Drag the timeline to travel; scroll on it to zoom. Its green dots are the program counter over time, so loops show up as patterns and calls as jumps between labels. The red and green lanes underneath are the LEDs. Click any RAM byte to see who wrote it last, jump there, or set a watch that pauses the moment it changes. Double-click a byte or register to change its value.
Sharing
Share ↗ stores your program and gives you a short link to it, no account needed. Whoever opens it gets their own copy to run, rewind and change, and can share their version the same way. Anyone who has the link can open a shared program. As you edit, the address bar also keeps your work, so reloading never loses it.
Addressing modes
Every source operand uses one of seven modes. Destinations can use the first four.
| Write | Mode | Means | Extra word? |
R5 | register | the value in R5 | no |
4(R5) | indexed | memory at R5 + 4 | yes (the 4) |
total | symbolic | memory at a label, stored relative to the PC | yes |
&P1OUT | absolute | memory at a fixed address | yes |
@R5 | indirect | memory at the address in R5 | no |
@R5+ | auto-increment | the same, then R5 += 2 (or 1 for .b) | no |
#42 | immediate | the number itself | yes, unless it's 0, 1, 2, 4, 8 or −1 |
The constant generator (R2 and R3) supplies 0, 1, 2, 4, 8 and −1 for free, which is why inc, clr and friends are only 2 bytes.
The 27 instructions
| Two operands | mov add addc sub subc cmp dadd bit bic bis xor and |
| One operand | rrc rra swpb sxt push call reti |
| Jumps (±1 KB) | jmp jeq/jz jne/jnz jc/jhs jnc/jlo jn jge jl |
| Emulated | nop ret pop br clr inc incd dec decd tst inv rla rlc adc sbc dadc setc clrc setz clrz setn clrn eint dint — names for one of the above (the “Up next” card shows which) |
Add .b to work on a byte; .w (or nothing) works on a 16-bit word.
Memory map
0x0000–0x000F | special function registers (IE1, IFG1…) |
0x0010–0x01FF | peripheral registers: ports, Timer_A, watchdog… |
0x0200–0x03FF | RAM — variables at the bottom, the stack grows down from the top |
0x1000–0x10FF | information flash (calibration constants) |
0xC000–0xFFDF | flash: your program |
0xFFE0–0xFFFF | interrupt vectors; 0xFFFE holds the reset address |
Assembler
TI (Code Composer) syntax: labels in column 1 or ending in :, comments after ;. The msp430g2553.h names (P1OUT, BIT3, WDTPW, TASSEL_1, LPM3, GIE…) are always defined. Directives: .text .data .bss .sect .org .word .byte .string .cstring .space .align .equ. $ is the current address, so jmp $ stops. Put the start address in the reset vector with .sect ".reset" / .short RESET (if you don't, it starts at 0xC000). Numbers: 42, 0x2A, 2Ah, 0b101010, '*'.
What's simulated
The full CPU (every instruction, addressing mode, flag and cycle count), ports P1 and P2 with the LaunchPad's LEDs and buttons, pin interrupts, Timer0_A3 (up, continuous and up/down modes, CCR0–2 and TAIV), the watchdog (including the reset when you forget it), low-power modes, and resets. MCLK and SMCLK run at 1 MHz, ACLK at 32,768 Hz. Not simulated: the second timer, serial, ADC, comparator, flash writes and clock configuration. For convenience SP starts at 0x0400 and .data is preloaded into RAM; on a real chip your startup code does both.