SWEET16

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

Template:Short description Script error: No such module "other uses". 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 computers. It was created because Wozniak needed to manipulate 16-bit pointer data, and the Apple II was an 8-bit computer.[1]

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.[2]

SWEET16 code is executed as if it were running on a 16-bit processor with sixteen internal 16-bit little-endian registers, named <templatestyles src="Mono/styles.css" />R0 through <templatestyles src="Mono/styles.css" />R15. Some registers have well-defined functions:[1]

  • <templatestyles src="Mono/styles.css" />R0 – accumulator
  • <templatestyles src="Mono/styles.css" />R12 – subroutine stack pointer
  • <templatestyles src="Mono/styles.css" />R13 – stores the result of all comparison operations for branch testing
  • <templatestyles src="Mono/styles.css" />R14 – status register
  • <templatestyles src="Mono/styles.css" />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 <templatestyles src="Mono/styles.css" />$00–<templatestyles src="Mono/styles.css" />$1F), with values stored as low byte followed by high byte.[1] The SWEET16 interpreter itself is located from <templatestyles src="Mono/styles.css" />$F689 to <templatestyles src="Mono/styles.css" />$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; however it shaved around 20% off the size of Integer BASIC.[3]

Operators

Register Ops Nonregister Ops
00 <templatestyles src="Mono/styles.css" />RTN Return to 6502 mode
1n <templatestyles src="Mono/styles.css" />SET Rn Constant set 01 <templatestyles src="Mono/styles.css" />BR ea Branch always
2n <templatestyles src="Mono/styles.css" />LD Rn Load 02 <templatestyles src="Mono/styles.css" />BNC ea Branch if No Carry
3n <templatestyles src="Mono/styles.css" />ST Rn Store 03 <templatestyles src="Mono/styles.css" />BC ea Branch if Carry
4n <templatestyles src="Mono/styles.css" />LD @Rn Load indirect 04 <templatestyles src="Mono/styles.css" />BP ea Branch if Plus
5n <templatestyles src="Mono/styles.css" />ST @Rn Store indirect 05 <templatestyles src="Mono/styles.css" />BM ea Branch if Minus
6n <templatestyles src="Mono/styles.css" />LDD @Rn Load double-byte indirect 06 <templatestyles src="Mono/styles.css" />BZ ea Branch if Zero
7n <templatestyles src="Mono/styles.css" />STD @Rn Store double-byte indirect 07 <templatestyles src="Mono/styles.css" />BNZ ea Branch if NonZero
8n <templatestyles src="Mono/styles.css" />POP @Rn Pop indirect 08 <templatestyles src="Mono/styles.css" />BM1 ea Branch if Minus 1
9n <templatestyles src="Mono/styles.css" />STP @Rn Store Pop indirect 09 <templatestyles src="Mono/styles.css" />BNM1 ea Branch if Not Minus 1
An <templatestyles src="Mono/styles.css" />ADD Rn Add 0A <templatestyles src="Mono/styles.css" />BK Break
Bn <templatestyles src="Mono/styles.css" />SUB Rn Subtract 0B <templatestyles src="Mono/styles.css" />RS Return from Subroutine
Cn <templatestyles src="Mono/styles.css" />POPD @Rn Pop double-byte indirect 0C <templatestyles src="Mono/styles.css" />BS ea Branch to Subroutine
Dn <templatestyles src="Mono/styles.css" />CPR Rn Compare 0D Unassigned
En <templatestyles src="Mono/styles.css" />INR Rn Increment 0E Unassigned
Fn <templatestyles src="Mono/styles.css" />DCR Rn Decrement 0F Unassigned

References

<templatestyles src="Reflist/styles.css" />

  1. a b c Script error: No such module "Citation/CS1".
  2. Script error: No such module "citation/CS1".
  3. Script error: No such module "Citation/CS1".

Script error: No such module "Check for unknown parameters".

External links