16-bit programming

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
carlottagp
Posts: 16
Joined: Mon Feb 20, 2006 4:45 pm
Location: Shoreham, Vermont

16-bit programming

Post by carlottagp »

Can anyone direct me to a source of help for 16-bit programming in TextPad?
I'm not a professional programmer, but an amateur. The immediate problem is that my (successful) programs are too long, and I need to create and link a library of procedures. (Not macros..).

Thanks for any advice,

Michael
User avatar
Nicholas Jordan
Posts: 124
Joined: Mon Dec 20, 2004 12:33 am
Location: Central Texas ISO Latin-1
Contact:

start here

Post by Nicholas Jordan »

"16-bit programming in TextPad" reflects some prelimnary orientation needs to be done. Your profile states mathematician, there are no shortage of those for the subject of computer science. Lets start with some fundamental definitions:
  • Com:with + pile:ordered collection,... to put with the pile.
  • Machine level instruction: The actual patterns that drive the machine.
  • Editor: A visual tool that is powerful at swapping around text.
  • Compiler: A computer program for writing computer programs.
  • Source Code: What you can see in the editor
  • Target: What exactly you want the program to do on what machine.
  • Linguistic: The use of the editor in a manner defined by the combination of a Linguistic : a Compiler : and a Target
16-bit source code is not as widely available as 32-bit code, but there are few differences in the style of writing for many linguistics. C/C++/Java is widely popular in the field, other linguistics achieve greater acceptance in the academic domain. Some large companies develop their own internal style as the writing of a compiler is a standard undergrad project in a well developed computer science department. There is a vast range of quality of work that is given as sample code on the web, I find that university Ph.D. and Masters level workers who write in straight html 1.1 provide the most reliable source of sample code and observations. google for bjarne stroustrup, note the style of his website.

Let me give you a popular and easy to find sample:

In16 bit C code, a file looks like "FILE" , which expands in the first few passes of the compiler to something called a structure. Over simplified a structure is something between { and } and those who know how the compiler work can have a field day with what exactly can be done on entry into these Brackets.

In 32-bit style, it looks like:

Code: Select all

// open the file....
m_hFile = CreateFile( m_pRequest->m_strFullPath, 
GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,NULL );
A bit more complicated, and all you have done is get a 'handle' with which you can write patterns in an orderded sequence. A popular definition of file in computer science is an "ordered sequence of bytes" ~ in fact the text that is in the open text editor window is an ordered sequence of bytes ... the difference is whether those bytes are written to an area of memory where they can be recovered for use after the machines shuts off.

There are no shortage of authors of beginner books for computer science, but I would not make the mall the first choice ~ use David Eck's Java site on the web to start off with because much of what is being done on smaller devices that run 16-bit code uses Java to fomalize a layer where the engineers for some device can intervene and thwart well known problems in computer science such as the ancient and honored buffer overrun problem. I have migrated to ELSIEVER as my first choice, but they may not have alot of beginner books. Springer-Verlag is top-tier, due to some advanced issues. CRC & O'Reilly are better for beginner works, just start with the dummies books for whichever language you choose. Effective STL by Scott Meyers ( Addison/Wesley ) discusses reality based issues from the perspective of a Ph.D. who has decades of field experience talking in an informal manner that illustrates generalized problems ( in coding and translation/compiling ) that form recognizable patterns that occur again and again from rank beginner @ day One to Twenty Years and Still Coding.

What is your target machine and problem definition to which an application of computer science can achieve desired effectiveness. ( do not use company names - generalize the problem, narrow the code questions )
carlottagp
Posts: 16
Joined: Mon Feb 20, 2006 4:45 pm
Location: Shoreham, Vermont

16-bit programming

Post by carlottagp »

Hello, Nicholas,

Thank you very much for your detailed and helpful response to my request for advice.

Clearly, I should have posted a clearer description of my current difficulty, since your reply went far beyond my needs. I will attempt to do this here;

I’m a retired instrumentation engineer, presently involved in some heavy-duty consulting for my former employer; my field is thermal analysis, principally differential scanning calorimetry. I am getting into some very elementary 16-bit programming for the sake of intellectual relaxation – an occasional relief from high-temperature physics and low-noise analog electronics. (And I find a lot of pleasure in it, to
tell the truth.)

At the moment, I’m working on a program which will generate prime numbers up to 2**28, and the factors of any number in this range. Extrapolating from where I am at this time, I think there will be about 400 lines of source code in the final version. (That is, if I leave the various procedures where they are now.)

I thought it might be a little tidier to separate the procedures into a library, and link the library to the main program. Since the procedures will be called many thousands of times, it obviously makes no sense to use macros.

All I need is the instructions necessary (a) to assemble a number of procedures into a library and (b) the instructions necessary to link the library to the main program. My reference at this time is Irvine’s book on assembly language, which concentrates on 32-bit programming, with 16-bit programming as a “poor relation�, so to speak. I don’t find it helpful at all. So I’m hoping to locate a book with more emphasis on my particular requirements; this was the objective behind my post to the forum.
User avatar
Nicholas Jordan
Posts: 124
Joined: Mon Dec 20, 2004 12:33 am
Location: Central Texas ISO Latin-1
Contact:

instructions necessary (a) to assemble a number of procedure

Post by Nicholas Jordan »

The cannonical reference on primes, fibonacci and the whole of computer science at your level is Donald E. Knuth. I have the three volume boxed set with two of four fascicle already in hand. There are many routines that depend on accomplished work in mathematics that find immediate employment in day-to-day computer science. A great deal of accomplishment in something to occupy your mind can be achieved by writing routines in assembler ( 16-bit or otherwise ) that accomplish greater effectiveness than what someone who is not trained can achieve. A brief look at the book on the web suggests that you have chosen the right book for your efforts, but the issue of 32-bit/16-bit is not likely to have been addressed in a focused, detailed walk through in any book. What you would have to do to be in a reliable work is to investigate compilers generally, with a focus on how to find one that is amenable to sixteen bit targets.

To that end, the compiler that Dr. Irvine uses is written for the business that wants to get something running with no excess of effort. In this work you are delving, you should remember the Golden Rule: "Nuthin ain't nuthin honey, if it ain't free". It is conjecture that you did not know that Janis Joplin was a computer scientist, but it is known that an asp is a large reptile capable of crushing humans. To avoid that, I suggest   http://www.digitalmars.com/   This is as close as you will get to a collected work on linking, building libraries and having the work of 16-bit opcodes in proven libs available for reference.

There are some contemporary issues in BB84 Type Schema that would make no sense to use macros: MACROS are for people who do not have real editors like TextPad. In general, until significant work is achieved on assemblers that issue 16-bit opcodes, I suggest using the idea that compilers generally accept the coding pattern that everything in a directory ( called a node in sorting and searching work ) is available in a build. This is done by declaring a variable extern in C, functions are made available by declaring the function signature in an include file and calling that include file early in the c source. This will immediately mirror the manner in which libs are referenced when building libs comes within scope.

As for the possiblility you may be able to provide a more effective solution of my current difficulty - generating primes - may I post my 179 lines of source ? It would compile on either 16 bit or 32 bit compilers, and may be targeted to either pending further work on the issue.
carlottagp
Posts: 16
Joined: Mon Feb 20, 2006 4:45 pm
Location: Shoreham, Vermont

16-bit programming

Post by carlottagp »

Hello, Nicholas,

Once again, I thank you for your assistance. To answer your last comment, I would certainly like to see your code for prime number generation. However, it is most unlikely that I could contribute anything really useful in this area; what I have at the moment shows primes up to 2**16, and any programming professional who looked at it would turn up his nose. (It's more than 200 lines, and certainly not optimized in any way.)

Thanks again,

Michael
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

I'm not a mathematician, and I haven't tried all of the possibilities yet, but I can state confidently that 2**16 will not be a prime number. :roll:

So maybe you can limit the range to 2**16 - 1 ? 8)
Last edited by Bob Hansen on Wed Mar 05, 2008 10:20 pm, edited 1 time in total.
Hope this was helpful.............good luck,
Bob
User avatar
Nicholas Jordan
Posts: 124
Joined: Mon Dec 20, 2004 12:33 am
Location: Central Texas ISO Latin-1
Contact:

unlikely that (post) could contribute anything really useful

Post by Nicholas Jordan »

Anyone with experience as an instrumentation engineer will be of significant use in my effforts, all the incoming minds just sit around and play video U-Tube where everything goes in one ear and out the other. If nothing else, we can play Code Warrior: Someone posts some code, someone else comments. For starters, let's see your code first ~ we will only confuse you with ours and by looking at your code we can get a firm, fast grasp of where your efforts are at and where you will get stuck. Being stuck for a long time is not profitable, being stuck for a short time is. This is known computer science.

For generating primes, the short-term issue to look at would be how much ephemeral address space a proposed device would have. ( antonym of permanent for the cs's that are watching ) To do meaningful work on primes most algorithm ( al Bundy goes dancing ) :lol: can work in L-2 but for 16-bit programming many devices will resemble EMAC's programming envioronment. I did not mention EMACS until now to avoid having you lost in terminology and code samples written directly in assembler source running ten times what you have already. EMACs has an editor tailored to the device and is a true 8-bit/16-bit learning platform.

Dr. Knuth's assistance would be that premature optomization is the root of all evil. He should know, all known computer science is cataloged in his work. First, write some code you can understand ~ sounds like you have done that already. Then code some limits so that the algorithm either fails in a manner that you can detect or provides some sort of indication in the debugger. This is known as the assert macro. Macros are for use only after one understands in detail how they work, else they are for code shops that just want to get the thing running and expect the compiler author to have done the work.

The place where heavy-duty consulting comes to bear some load is when we try to explain to persons with no engineering experience that the sales department may have what is called degenerate cases of Non Deterministic Finite Automa. These show up occasionally in The Game of Life, and there is no known way to mathematica a test for .... these are called hung boxes in the lingo .... such degenerate cases. In the matter of primes, you can do a fast optomization by eliminating all N greater than square root of N. Charles do La Vallee Poussin did some work recently ( 1899 ) at The Acad. Roy. Belgique. The glacial pace of common sense in contemporary computer science contrasts the fast-paced nature of Mathematics.

Code: Select all

public final  int generatePrimes(int start_, int limit_,boolean ascii_) 
throws UserException
        {
            /**
             * retVal is built-in to my fingertips as the name we will be
             * using for the return value of a function.
             */
            int retVal = 0;// declare this first, so we don't forget it.

            // special casing for called with nonsense values
            // 0 and 1 are no prime numbers
            if(start_ < 3)start_ = 3;// ignore below first non-trivial prime.
            if(limit_ < 5)limit_ = 5;// ignore below second non-trivial prime.
            // simple swap if needed ...
            if(start_ > limit_){int tmp_ = start_;start_ = limit_;limit_ = tmp_;}
            if(start_ == limit_)
            {
                java.lang.System.err.print("user is a twit.");
                java.lang.System.err.print('\n');
                return -1;
            }
            // declare outside of loop, standard optomizaion 
            //called loop invariant removal.
            int number_ = 0;// 
            int divisor = 0;

            try
            {
Note the first thing I did was filter some degenrate twits, getting rid of them is heavy-duty.
The only dumb question is one you should have asked and didn't.
carlottagp
Posts: 16
Joined: Mon Feb 20, 2006 4:45 pm
Location: Shoreham, Vermont

Post by carlottagp »

Bob: I appreciate your comment. I should have written "up to but not including....." !!

Unfortunately, nobody has addressed my original question, referenced in the final paragraph of my Feb. 26 post (making a procedures library, and linking it to the main program.)

Nicholas: Yes, of course my code includes the square-root test you
mentioned. The code quoted in your most recent quote is in a language unfamiliar to me; neither 16-bit assembly, nor Fortran, nor BASIC.
User avatar
Drxenos
Posts: 209
Joined: Mon Jul 07, 2003 8:38 pm

Post by Drxenos »

carlottagp wrote:Bob: I appreciate your comment. I should have written "up to but not including....." !!

Unfortunately, nobody has addressed my original question, referenced in the final paragraph of my Feb. 26 post (making a procedures library, and linking it to the main program.)

Nicholas: Yes, of course my code includes the square-root test you
mentioned. The code quoted in your most recent quote is in a language unfamiliar to me; neither 16-bit assembly, nor Fortran, nor BASIC.
The answer to your questions depending on what you mean by "16-bit programming." Do you mean MS-DOS, Win3, or possibly some other 16-bit platform? I think Nicholas specifically ask you this question (although his response was a bit long winded with a lot superfluous information). Yours cannot be answered until to answer his.
User avatar
Nicholas Jordan
Posts: 124
Joined: Mon Dec 20, 2004 12:33 am
Location: Central Texas ISO Latin-1
Contact:

16-bit compiler is independent of language.

Post by Nicholas Jordan »

The code quoted in your most recent quote is in a language unfamiliar to me; neither 16-bit assembly, nor Fortran, nor BASIC.
The language is from the propietary c/c++ compiler for win. I thought my answer relatively simple and clear and tried very hard to disentangle 16-bit from the language used to write a program. It is as Drxenos directs. I pm'd a link to a trainer board. I advise against ( and ask Drxenos' comment that it should be strongly advise against ) trying to do 16-bit development on any computer other than an isolated test box with no irrecoverable information.

This was the purpose of advising to use a trainer board for 16-bit, several of them use BASIC. Google for BASIC STAMP and see if that is what you are looking for.
Post Reply