Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!cbmvax!daveh From: daveh@cbmvax.cbm.UUCP (Dave Haynie) Newsgroups: comp.sys.apple Subject: Re: Re: 65C816 programming weirdness; is it true? Message-ID: <1162@cbmvax.cbmvax.cbm.UUCP> Date: Tue, 23-Dec-86 00:27:40 EST Article-I.D.: cbmvax.1162 Posted: Tue Dec 23 00:27:40 1986 Date-Received: Tue, 23-Dec-86 18:47:33 EST References: <2504@ecsvax.UUCP> Organization: Commodore Technology, West Chester, PA Lines: 84 > Keywords: IIGS, 65C816, assembly language, 8/16 bit modes > Summary: I think 65816 is easier... >> I would appreciate any information regarding 65C816 assembly language >> difficulties on the Apple IIGS. If there are such difficulties, I wonder >> what that will mean for development of IIGS specific software. > I think that programming the 65816 is easier than programming the 6502. > There are two modes, 8 and 16 bit. The 8 bit mode exists primarily to > run older software. There is no real need to use it idf you use Prodos 16 > The '816 comes up in the 8 bit mode for > compatibility purposes, so the first thing you can do on a gs is switch into > the 16 bit mode. I think you will like the power of the '816 once you > get used to it, you won't want to go back to the restrictions of the > 6502. > Aim Flames at: > > Rick Fincher > ranger@ecsvax *Minor incoming flames* While you probably understand the '816/'802 architecture better than your posting woul indicate, I thought I'd clear up a few things that appear misleading in your article, especially in reference to the weirdness of programming the chip that first surfaced in the original article. The first clarification I'd like to make is that of MODES. The '816 chip actually has two levels of modes. The first is what most folks refer to as the 8/16 bit mode change, but this is really misleading. What you really have is two modes, the 8 bit _emulation_ mode, in which things look like a cross between a 6502 and a 65C02, with extensions (8 bit only, pretty 6502 compatible), and the 8/16 bit _native_ mode, where older code will only work if you're lucky. The emulation mode is certainly for using older code only, and its about as 6502 compatible as a 65C02, even better in a few cases. Now we move to native mode. In native mode, there's a choice of submodes. You can make things 8 bits long, or 16 bits long. Both of these are important, and changing between them is generally regarded as the "weird" part of the '816 chip. A new bit in the status register indicates whether the accumulator is 8 or 16 bits wide. And this is very important. 'Cause just about ANY instruction I execute will need to know whether I want an 8 or a 16 bit operation to occur. If I'm dealing with characters, or perhaps some kinds of graphic screens, I'll choose the 8 bit mode. When I want to do integer math, I'll choose the 16 bit mode. The thing is, in either case, I'm using EXACTLY the same instructions. The effect of each instruction varies based in the setting of this mode bit. And of course, the reason its in the status register is interrupts: if I get an interrupt, the interrupt service routine will have to choose which mode it wants to run in. Changing the mode bit could have dire consequences on the code that was running before the interrupt. But since the bit-width bit is in the status register, its saved on an interrupt, and restored by RTI. Thus, there's no problem with interrupts. There is a difficulty, however, with an assembler. Lets assume, for instance, I want to code an instruction, say an LDA #$00 or something. A 6502 assembler would give me two bytes, one for the LDA instruction, one for the immediate data value of $00. Now we go into native mode. I get the same assembly if I'm in 8 bit mode, 2 bytes. But if I go to 16 bit mode, my LDA codes one op-code, plus 2 data bytes, since I'm loading a 16 bit value now. Thus, the output of the assembler MUST be based on the value of a flag that can be set at run time. This is extremely weird, and will really depend on the programmer to keep the Assembler honest. Note that other microprocessors handle the bit width problem by providing different op-codes. A 68000 will give you one op-code for a BYTE valued MOVE immediate (LDA # equivalent), one op-code for a WORD (16 bit) MOVE immediate, and one op-code for a LONG WORD (32 bit) MOVE immediate. No register width status bit to worry about. That's the problem with the 65C816 that everyone's wondering about these days. It doesn't prevent the '816 from being a useful chip, but it does make it a very non-conventional architecture which will certainly complicate programming of the thing. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Dave Haynie {caip,ihnp4,allegra,seismo}!cbmvax!daveh Why look here for inspiration, when its all around you anyway. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~