Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Basic Misc > Re: 1980 Basic ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 28 of 51 Topic 1442 of 1492
Post > Topic >>

Re: 1980 Basic Sought

by ArarghMail804NOSPAM@[EMAIL PROTECTED] Apr 8, 2008 at 11:18 PM

On Tue, 8 Apr 2008 08:29:29 -0400, "Tom Lake" <tlake@[EMAIL PROTECTED]
>
wrote:
<snip>
>Oh, you want *easy* do you?  8^)
Old programming rule: KISS.  :-)

I'm an old programmer. :-)

>My simple example was just to show how SSEG and SADD work.
>In practice, you'd use those functions to store ML routines in the
>string or to do string manipulation without fear of garbage
>collection (just make sure you DON'T change the string length!)
Or do anything else to any string. :-)

>Here's a more practical example:
>
>To change "him" to "her" you could do this:
>
>a$ = "him"
>MID$(a$, 2) = "er"
>
>but this would cause BASIC to make temp strings and
>possibly move a$ around in memory. and trigger a garbage
>collection.
It doesn't seem to, try this in QBasic:

a$ = "him"
PRINT HEX$(SADD(a$))
MID$(a$, 2) = "er"
PRINT HEX$(SADD(a$))

IIRC, the MID$ sub only does inplace operations, and I don't think it
will ever change the length of a string (but I am not sure).

FROM PDS HELP:
Usage Notes
  The optional length refers to the number of characters from the
argument stringexpression$ that are used in the replacement. If
length% is omitted, all of stringexpression$ is used. However,
regardless of whether length% is omitted or included, the replacement
of characters never goes beyond the original length of
stringvariable$.

In BCET, the MID$ sub will only change characters already existing in
a string and will never change the length.

>If you do this:
>
>a$ = "him"
>Segment = SSEG(a$)
>Offset = SADD(a$)
>DEF SEG = Segment
>POKE Offset + 1, ASC("e")
>POKE Offset + 2, ASC("r")
>
>This won't trigger garbage collection and is actually
>faster than the MID$ method.

Other than taking about twice the code space, all very true.

However, you need a 'DEFINT A-Z' or some approximate DIMs in front
else QBasic & QB will use SINGLEs, and a 'DEF SEG' after to restore.


Back in the late 80's  and early 90's I wrote a lot of assembler to
these kind of speed ups and code size reduction.  The routine to do
what your sample was 'MidAsc' and was used like this:

MidAsc a$, 2, ASC("e")
MidAsc a$, 3, ASC("r")

Although I would normally have coded it as 

MidAsc a$, 2, 101 ' ASC("e")
MidAsc a$, 3, 114 ' ASC("r")

which saves an additional 16 bytes of code space & 2 string constants.

A quick look at that library source shows:

; MidAsc                                      Written on 09/16/93

I am not sure why MidAsc was ever written unless it was for speed.
It's calling sequence is not really any smaller that the normal MID$
sub.
-- 
ArarghMail804 at [drop the 'http://www.'
from ->] http://www.arargh.com
BCET Basic Compiler Page: http://www.arargh.com/basic/index.html

To reply by email, remove the extra stuff from the reply address.
 




 51 Posts in Topic:
1980 Basic Sought
david.williams@[EMAIL PRO  2008-03-14 09:56:13 
Re: 1980 Basic Sought
winston19842005 <bjjly  2008-03-14 10:23:56 
Re: 1980 Basic Sought
"Judson McClendon&qu  2008-03-14 09:35:58 
Re: 1980 Basic Sought
winston19842005 <bjjly  2008-03-14 10:45:09 
Re: 1980 Basic Sought
"Judson McClendon&qu  2008-03-14 11:06:08 
Re: 1980 Basic Sought
ArarghMail803NOSPAM@[EMAI  2008-03-14 18:09:14 
Re: 1980 Basic Sought
"Tom Lake" <  2008-03-14 21:29:01 
Re: 1980 Basic Sought
ArarghMail803NOSPAM@[EMAI  2008-03-14 22:58:33 
Re: 1980 Basic Sought
"R.Nicholson" &  2008-04-08 11:20:03 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-08 23:27:54 
Re: 1980 Basic Sought
"news@[EMAIL PROTECT  2008-04-10 01:29:14 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-10 04:19:38 
Re: 1980 Basic Sought
"R.Nicholson" &  2008-04-10 10:53:00 
Re: 1980 Basic Sought
"Stephen J. Rush&quo  2008-04-08 03:29:05 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-08 04:44:07 
Re: 1980 Basic Sought
thomas.mertes@[EMAIL PROT  2008-04-07 01:50:52 
Re: 1980 Basic Sought
"Tom Lake" <  2008-04-07 07:55:55 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-07 18:43:27 
Re: 1980 Basic Sought
"Tom Lake" <  2008-04-07 21:22:26 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-07 21:20:53 
Re: 1980 Basic Sought
"Tom Lake" <  2008-04-07 23:08:17 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-08 00:21:08 
Re: 1980 Basic Sought
"Tom Lake" <  2008-04-08 04:35:55 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-08 04:45:15 
Re: 1980 Basic Sought
"Tom Lake" <  2008-04-08 08:29:29 
Re: 1980 Basic Sought
"Judson McClendon&qu  2008-04-08 08:33:38 
Re: 1980 Basic Sought
"Tom Lake" <  2008-04-08 15:29:56 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-08 23:18:16 
Re: 1980 Basic Sought
"Auric__" <n  2008-04-09 20:21:32 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-09 15:36:54 
Re: 1980 Basic Sought
"Auric__" <n  2008-04-09 20:40:42 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-09 16:35:42 
Re: 1980 Basic Sought
"Auric__" <n  2008-04-09 21:58:24 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-09 18:42:45 
Re: 1980 Basic Sought
"Auric__" <n  2008-04-10 15:43:33 
Re: 1980 Basic Sought
"Judson McClendon&qu  2008-04-09 17:20:01 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-09 18:58:15 
Re: 1980 Basic Sought
"Judson McClendon&qu  2008-04-10 09:20:41 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-10 21:54:34 
Re: 1980 Basic Sought
"R.Nicholson" &  2008-04-08 21:51:43 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-09 02:52:08 
Re: 1980 Basic Sought
"Bill Leary" &l  2008-04-09 07:02:03 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-09 07:22:45 
Re: 1980 Basic Sought
"Judson McClendon&qu  2008-04-09 08:35:22 
Re: 1980 Basic Sought
ArarghMail804NOSPAM@[EMAI  2008-04-09 09:21:04 
Re: 1980 Basic Sought
"Judson McClendon&qu  2008-04-09 10:01:21 
Re: 1980 Basic Sought
"Bill Leary" &l  2008-04-10 01:17:20 
Re: 1980 Basic Sought
"Judson McClendon&qu  2008-03-14 09:32:59 
Re: 1980 Basic Sought
Charmed Snark <snark@[  2008-03-14 16:04:19 
Re: 1980 Basic Sought
"Judson McClendon&qu  2008-03-14 13:49:57 
Re: 1980 Basic Sought
Charmed Snark <snark@[  2008-03-15 04:11:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 15:27:57 CDT 2008.