Newsgroups: comp.sys.apple2.programmer Path: news.weeg.uiowa.edu!news.uiowa.edu!hobbes.physics.uiowa.edu!math.ohio-state.edu!wupost!waikato!comp.vuw.ac.nz!actrix.gen.nz!dempson From: dempson@swell.actrix.gen.nz (David Empson) Subject: Re: 65816 register sizes Organization: Actrix Information Exchange Date: Thu, 12 Aug 1993 09:34:54 GMT Message-ID: <1993Aug12.093454.9841@actrix.gen.nz> References: <1993Aug11.165215.7631@exu.ericsson.se> Sender: dempson@actrix.gen.nz (David Empson) Lines: 41 In article <1993Aug11.165215.7631@exu.ericsson.se> exuhag@exu.ericsson.se writes: > ... > > To the point: What is the most common strategy for handling register > sizes (A, X, Y)? Switching between them is a pain, so I assume that > they are usually kept at 16 bits, even if this means storing byte > sized values as words, just to make things cleaner. I could ramble, > but I'll just leave this question open-ended. Your assumption is basically correct. The technique commonly used by compilers is to remain in 16-bit mode as much as possible. When reading from a byte-sized variable, a word read is used, and the high order byte discarded by doing an AND #$00FF. This is fine for general memory locations, but may cause problems with I/O locations (ORCA/C will read two adjacent I/O locations simultaneously when reading through a byte pointer, so you should always use assembly language to access an I/O location). When writing to a byte-sized variable, the compiler generates code to switch to 8-bit mode, store the byte, and restore 16-bit mode. When I'm writing assembly language code, I try to organise code in such a way that 8-bit accesses are handled in a group, surrounded by SEP #$30 and REP #$30. I usually use 16-bit variables, even if they only contain a byte-sized value. The variable can then be accessed in either 8-bit or 16-bit mode without problems. (Data structures such as arrays and strings involving byte-sized data are an obvious exception.) One other technique I frequently use (especially in string processing) is to set the accumulator to 8 bits, and the index registers to 16 bits (using an SEP #$20 instruction to get into this state, and REP #$20 to get out of it again). -- David Empson dempson@swell.actrix.gen.nz Snail mail: P.O. Box 27-103, Wellington, New Zealand