Path: utzoo!attcan!uunet!husc6!m2c!wpi!dseah From: dseah@wpi.wpi.edu (David I Seah) Newsgroups: comp.sys.apple Subject: Sweet 16 Message-ID: <2077@wpi.wpi.edu> Date: 28 Apr 89 02:12:55 GMT Organization: Worcester Polytechnic Institute, Worcester, Mass. Lines: 71 This is kind of old stuff, but I ran across the issue of Byte that had the Apple II system description by Steve Wozniak: 00 1 Return to 6502 mode 01 2 Branch Always 02 2 Branch no Carry 03 2 Branch on Carry 04 2 Branch on Positive 05 2 Branch on Negative 06 2 Branch if equal 07 2 Branch not equal 08 2 Branch on negative 1 09 2 Branch not negative 1 0A 1 Break to Monitor 0B-0F 1 No operation 1R 3 R<-2 byte constant (load register immediate) 2R 1 ACC<-R 3R 1 ACC->R 4R 1 ACC<-@R, R<-R+1 5R 1 ACC->@R, R<-R+1 6R 1 ACC<-@R double 7R 1 ACC->@R double 8R 1 R<-R-1, ACC<-@R (pop) 9R 1 R<-R-1, ACC->@R AR 1 ACC<-@R(pop) double BR 1 compare ACC to R CR 1 ACC<-ACC+R DR 1 ACC<-ACC-R ER 1 R<-R+1 FR 1 R<-R-1 notes 1. All braches are followed by a 1 byte relative displacement. Works identically to 6502 branches. 2. Only ADD,SUB, and COMPARE can set carry 3. Notation: R = a 16 bit "Register" operand designation, one of 16 labelled 0 to 15 (decimal), 0 to F (hexidecimal) ACC = register operand R0 @R = indicrect reference, using the register R as the pointer <-, -> = assignment of values 4. Length of instructions: Branches are always two bytes: opcodes followed by relative displacement. Load register immediate (1R) is three bytes: the hexadecimal opcode 10 to 1F followed by the 2 byte literal value of a 16 bit number. All other instructions are one byte in length. And from that issue of Byte (Apr 1977, I think)...some words from the Woz himself. Retyped without permission. The Story of Sweet Sixteen While writing Apple BASIC, I ran into the problem of manipulating the 16 bit pointer data and its arithmetic in an 8 bit machine. My solution to this problem of handling 16 bit data, notably pointers, with an 8 bit microprocessor was to implement a non-existent 16 bit processor in software, interpreter fashion, which I refer to as SWEET16. SWEET16 contains sixteen internal 16 bit registers, actually the first 32 bytes in main memory, labelled R0 through R15. R0 is defined as the accumulator, R15 as the program counter, and R14 as a status register. R13 stores the result of all COMPARE operations for branch testing. The user acceses SWEET16 with a subroutine call to hexadecimal address F689. Bytes stored after the subroutine call are thereafter interpreted and executed by SWEET16. One of SWEET16's commands returns the user back to 6502 mode, even restoring the original register contents. Implemented in only 300 bytes of code, SWEET16 has a very simple instruction set tailored to operations such as memory moves and stack manipulation. ost opcodes are only one byte long, but since she runs approximately ten times slower than equivalent 6502 code, SWEET16 should be employed only when code is at a premium or execution is not. As an example of her usefulness, I have estimated that about 1K byte could be weeded out of my 5K byte Apple-II BASIC interpreter with no observable performance degradation by selectively applying SWEET16. []