SWEET16 is an interpreted byte-code instruction set invented by Steve Wozniak and implemented as part of the Integer BASIC ROM in the Apple II series of computers. It was created because Wozniak needed to manipulate 16-bit pointer data, and the Apple II was an 8-bit computer.
SWEET16 was not used by the core BASIC code, but was later used to implement several utilities. Notable among these was the line renumbering routine, which was included in the Programmer's Aid #1 ROM, added to later Apple II models and available for user installation on earlier examples.
- R0 – accumulator
- R12 – subroutine stack pointer
- R13 – stores the result of all comparison operations for branch testing
- R14 – status register
- R15 – program counter
The 16 virtual registers, 32 bytes in total, are located in the zero page of the Apple II's real, physical memory map (at $00–$1F), with values stored as low byte followed by high byte. The SWEET16 interpreter itself is located from $F689 to $F7FC in the Integer BASIC ROM.
According to Wozniak, the SWEET16 implementation is a model of frugal coding, taking up only about 300 bytes in memory. SWEET16 runs at about one-tenth the speed of the equivalent native 6502 code.
|Register Ops||Nonregister Ops|
|00||RTN||Return to 6502 mode|
|1n||SET Rn||Constant set||01||BR ea||Branch always|
|2n||LD Rn||Load||02||BNC ea||Branch if No Carry|
|3n||ST Rn||Store||03||BC ea||Branch if Carry|
|4n||LD @Rn||Load indirect||04||BP ea||Branch if Plus|
|5n||ST @Rn||Store indirect||05||BM ea||Branch if Minus|
|6n||LDD @Rn||Load double-byte indirect||06||BZ ea||Branch if Zero|
|7n||STD @Rn||Store double-byte indirect||07||BNZ ea||Branch if NonZero|
|8n||POP @Rn||Pop indirect||08||BM1 ea||Branch if Minus 1|
|9n||STP @Rn||Store Pop indirect||09||BNM1 ea||Branch if Not Minus 1|
|Bn||SUB Rn||Subtract||0B||RS||Return from Subroutine|
|Cn||POPD @Rn||Pop double-byte indirect||0C||BS ea||Branch to Subroutine|
- Call-A.P.P.L.E. Wozpak II — 1979 Call-A.P.P.L.E. booklet that includes "SWEET 16 Introduction" by Dick Sedgewick and a version of "SWEET 16: The 6502 Dream Machine" by Steve Wozniak with longer descriptions of each opcode
- Strotmann, Carsten (2004-03-21). "Porting Sweet 16". 6502.org. Archived from the original on 2021-07-26. Retrieved 2021-03-03.