From @mail.uunet.ca:beejay@micor Wed Aug 5 14:15:03 1992 Received: from calvin.sfasu.edu by umaxc.weeg.uiowa.edu (5.61.jnf/920629) on Wed, 5 Aug 92 14:14:59 -0500 id AA22447 with SMTP Received: from mail.uunet.ca (uunet.ca) by calvin.sfasu.EDU with SMTP (5.59/25-eef) id AA03754; Wed, 5 Aug 92 13:52:09 CDT Return-Path: <@mail.uunet.ca:beejay@micor> Received: from ocunix by mail.uunet.ca with UUCP id <10563>; Wed, 5 Aug 1992 15:01:34 -0400 Received: by micor.OCUnix.On.Ca (smail2.5) id AA28005; 5 Aug 92 11:12:21 EDT (Wed) To: hyperc-l@calvin.sfasu.edu Subject: HyperC hint Date: Wed, 5 Aug 1992 07:12:21 -0400 Message-Id: <9208051112.AA28003@micor.OCUnix.On.Ca> From: beejay@micor.OCUnix.On.Ca (Basil Johnson) Status: R A HyperC hint ------------- There have been a few occasions in the hyperc-l mail where people have said that they are aware of the routine 'setup', but see no reason for using it. None of the source code of applications I have seen use it either; everybody seems to follow the Andy Werner model of taking parameters directly off the stack and eschew the use of 'setup'. Allow me to introduce you to Mr. setup. Consider the C function 'peekb' char peekb(address) /* address is any location 0x0000 - 0xffff [excluding video page 0x400 - 0x7ff]. peekb calls the assembly language program _peekb and returns the value of the byte at address in r1. Below are two alternate approaches using the Andy Werner model and 'setup'. You'll see that even though there's only one parm for this function, the most efficient version of the Werner model, including the use of 65c02 code, is 42% larger than the version that uses 'setup'. In a situation with more parameters, the efficiency in transferring the parm bytes to usable addresses would be greater. The number of bytes for the version using 'setup' would not change, while the other would with every additional parameter. This doesn't mean that setup is the best approach in _every_ situation. If _all_ the parms are to be used as self-modifying code and that's the only way to accomplish your task, then direct picks from the stack is very appropriate. But if at least one parm is a pointer, an address or a data byte that you have to make reference to more than once; if indirect access using the y index is needed, then you are much better off using 'setup'. Now, go do your setups. ;-) Basil Johnson ======================================= ;This version of peekb uses the Werner model ; - it picks parameters from the stack. ; ; peekb.a ; Callable from C - Syntax: peekb(addr); ; Returns the value of the byte at memory address 'addr'. ; .entry _peekb _peekb: ldy #0 sty r1h ; returning 8 bit value so zero high byte lda [sp],y ; get lsb of address into ./batchmail0 sta 0 iny lda [sp],y ; msb of address into ./batchmail1 sta 1 lda (0) ; get the byte ( 65c02 code ) sta r1 ; return 8 bits in r1 rts ; ======================================= ; This version of pekb uses setup ; ; peekb.a ; ; by Basil Johnson 92/08/04 ; ; Callable from C - Syntax: peekb(addr); ; Returns the value of the byte at memory address 'addr'. ; .entry _peekb _peekb: ldy #1 ; get 2 bytes jsr setup ; y = 0xff on completion iny lda [0],y ; get lsb of addr into r1 sta r1 sty r1h ; returning 8 bit value so zero high byte rts ; _ Basil Johnson UUCP: micor!beejay |Oh, Fate! ... Nepean, Ontario InterNet: |Such a stupid thing: CANADA K2B 8E9 beejay@micor.ocunix.on.ca |Command a bird to fly (613) 820-0804 |Then clip its wing! __