Difference between revisions of "Sweet 16"

From SEGGER Wiki
Jump to: navigation, search
(Created page with "Sweet 16 Some programs have been using Sweet 16, a pseudo processor implemented originally by Steve Wozniak https://en.wikipedia.org/wiki/Steve_Wozniak Sweet 16 was a pseudo...")
 
m
Line 1: Line 1:
  +
[[Category:Knowledge Base]]
Sweet 16
 
   
  +
SWEET16 is a pseudo processor implemented originally by Steve Wozniak https://en.wikipedia.org/wiki/Steve_Wozniak.
Some programs have been using Sweet 16, a pseudo processor implemented originally by Steve Wozniak https://en.wikipedia.org/wiki/Steve_Wozniak Sweet 16 was a pseudo 16-bit processor, with 16 16-bit registers. It required 32-bytes in the Zero page of the 6502, to hold the values of these registers and needed less instructions than the 6502 for most programs. Typical programs written in SWEET-16 needed about half the size and 5 to 10 times as much time as pure 6502 assembly code. The Sweet 16 executer was implemented in the ROM of the original Apple ][. 6502 assembler and Sweet 16 could be mixed easily: Sweet 16 code was inlined and simply preceeded by a function call to the executer, which was located at a known address (0xF689 or in Apple speech $F689) could easily be started by a subroutine call. Despite its simplicity, Sweet 16 achieved an amazing code density, which is still hard to beat today. For more information on SWEET-16, see http://www.6502.org/source/interpreters/sweet16.htm
 
  +
  +
SWEET16 code is executed on a pseudo 16-bit CPU with sixteen internal 16-bit registers.
  +
  +
== Registers ==
  +
SWEET16 has 16 internal 16-bit registers, named R0 .. R15.
  +
Some registers have well-defined functions:<ref name="byte-nov77"/>
  +
  +
* R0 – [[Accumulator]
  +
* R12 – Stack Pointer
  +
* R13 – stores the result of all comparison operations
  +
* R14 – Status register
  +
* R15 – Program Counter
  +
  +
  +
It required 32-bytes in the Zero page of the [[6502]], to hold the values of these registers and needed less instructions than the 6502 for most programs. Typical programs written in SWEET-16 needed about half the size and 5 to 10 times as much time as pure 6502 assembly code. The Sweet 16 executer was implemented in the ROM of the original Apple ][. 6502 assembler and Sweet 16 could be mixed easily: Sweet 16 code was inlined and simply preceeded by a function call to the executer, which was located at a known address (0xF689 or in Apple speech $F689) could easily be started by a subroutine call. Despite its simplicity, Sweet 16 achieved an amazing code density, which is still hard to beat today. For more information on SWEET16, see http://www.6502.org/source/interpreters/sweet16.htm
  +
  +
== Memory allocation ==
  +
SWEET16 requires storage in the zero page area for the registers. This has to be 32 consecutive bytes. In the original Apple implementation, the first 32 bytes located from $0 -$1F were used,
  +
however, the code can use any other range.
  +
For program space, about 300 bytes are required for the implementation on the 6502. On the 6502, an 8-bit Jumptable was used, which required all relevant code to be located in the same page (meaning
  +
the high byte of the address to be identical)
  +
The code can of course be ported to any other processor or written in C.
  +
  +
== References ==
  +
https://en.wikipedia.org/wiki/SWEET16
  +
http://amigan.1emu.net/kolsen/programming/sweet16.html

Revision as of 18:43, 8 September 2019


SWEET16 is a pseudo processor implemented originally by Steve Wozniak https://en.wikipedia.org/wiki/Steve_Wozniak.

SWEET16 code is executed on a pseudo 16-bit CPU with sixteen internal 16-bit registers.

Registers

SWEET16 has 16 internal 16-bit registers, named R0 .. R15. Some registers have well-defined functions:[1]

  • R0 – [[Accumulator]
  • R12 – Stack Pointer
  • R13 – stores the result of all comparison operations
  • R14 – Status register
  • R15 – Program Counter


It required 32-bytes in the Zero page of the 6502, to hold the values of these registers and needed less instructions than the 6502 for most programs. Typical programs written in SWEET-16 needed about half the size and 5 to 10 times as much time as pure 6502 assembly code. The Sweet 16 executer was implemented in the ROM of the original Apple ][. 6502 assembler and Sweet 16 could be mixed easily: Sweet 16 code was inlined and simply preceeded by a function call to the executer, which was located at a known address (0xF689 or in Apple speech $F689) could easily be started by a subroutine call. Despite its simplicity, Sweet 16 achieved an amazing code density, which is still hard to beat today. For more information on SWEET16, see http://www.6502.org/source/interpreters/sweet16.htm

Memory allocation

SWEET16 requires storage in the zero page area for the registers. This has to be 32 consecutive bytes. In the original Apple implementation, the first 32 bytes located from $0 -$1F were used, however, the code can use any other range. For program space, about 300 bytes are required for the implementation on the 6502. On the 6502, an 8-bit Jumptable was used, which required all relevant code to be located in the same page (meaning the high byte of the address to be identical) The code can of course be ported to any other processor or written in C.

References

https://en.wikipedia.org/wiki/SWEET16

http://amigan.1emu.net/kolsen/programming/sweet16.html

  1. Cite error: Invalid <ref> tag; no text was provided for refs named byte-nov77