Home » CEEFAX disks » telesoftware5.adl » 22-01-88/T\OSB11
22-01-88/T\OSB11
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » CEEFAX disks » telesoftware5.adl |
Filename: | 22-01-88/T\OSB11 |
Read OK: | ✔ |
File size: | 1E5C bytes |
Load address: | 0000 |
Exec address: | FFFFFFFF |
File contents
OSBITS - An Exploration of the BBC Micro at Machine Level By Programmer ........................................................... Part 11: Inputting Numbers In these next five modules of my exploration of the BBC Micro I am going to cover two areas. They are converting ASCII numbers into numbers in memory (input), and vice versa (output), and the arithmetical processes of multiplication and division. Since inputting and multiplication are connected they will come first. In the programming examples so far I have used OSRDCH to provide us with a single byte. In module 6 we printed out the value of that byte in three formats, decimal, hexadecimal and binary. But we were expecting a single byte, and as OSRDCH was being used that was all we got. The input routine in this module is designed to accept large numbers. You can define just how large yourself, but for the time being we will stick to numbers that can be held in 32 bits. In the real world there are always users whose main aim in life is to crash your programs, and quite right too. You have to try to anticipate everything a malicious user (or a software auditor) would do even if it seems totally illogical. Nowhere is this a greater problem than with input routines. First we must decide what our input routine is going to do. This is known as its Functional Specification, and even if you fine tune it along the way it helps enormously to know what you are trying to achieve. In its briefest form then the functional spec of this module is as follows: Put a string typed in by the user into a defined area of memory, rejecting any characters that do not form numbers and allowing the user to delete the last character he input. The module should be written in such a way as to be easily incorporated in an ASCII to binary conversion routine in the next module. There is an OS routine for input which we could use. It is OSWORD 0 and on entry we can specify a piece of memory to use to hold the string input, the input buffer, and we can also set an upper and lower limit to the characters accepted and the length of the string. On exit from the routine we can find out the length of the string entered and we can check for ESCAPE being pressed. However, OSWORD 0 has some disadvantages. When you define limits to the characters entered the routine behaves a little eccentrically. Invalid characters are still printed to the screen and attempts to delete characters will have unpredictable results if invalid characters are present. I thought it would be an interesting exercise to write a similar routine myself which would not exhibit such strange behaviour and which would allow clearer defining of character limits. So, before going on in the next module to using this routine as a basis for inputting numbers and converting them to binary in memory, let's look at this module, B/osb11. The flow of the program goes like this: Input a character using OSRDCH (If an error has occurred then exit) Check for a carriage return which terminates input (If a CR then exit) Check for a delete (If a delete then remove last character) Check any other characters against valid list Output any valid character to screen and add to string in memory We will use the Y register to keep track of the position of our last character in the buffer. The main section of the code lies between lines 210 and 390. Here a character is captured using OSRDCH and it is checked to see if it is a carriage return (13) or a delete (127), each of which get special treatment. The number of characters in the buffer is checked against the buffer length. If it passes these tests then the character is checked by a subroutine at 'check_character' which we will come onto in a moment. If the accumulator contains a null (zero) after this subroutine then the character was not valid. Otherwise the character, which has now passed all the tests, is sent to the screen and added to the string in memory at 'input_buffer'. The Y register, which is counting our way along this buffer, is increased. It will always hold the number of characters in the input buffer. Line 410 is where the code takes us after a carriage return. This terminates the input and we store a CR at the end of the string and also store the length in a piece of memory labelled 'string_length'. This latter is to allow us to use BASIC to check that the routine is working correctly after we have assembled the program. We exit having cleared the Carry flag so this can be used to indicate a valid result. Line 520 is where we go on detecting an error, usually ESCAPE, during input. Note that part of the string may be in memory and that the Carry flag will be set. Again we can use this to indicate an invalid result. At line 610 is a routine we enter if the buffer was already full when a new character was keyed in. The micro beeps (by using VDU7, i.e. OSWRCH with 7 in the accumulator) to warn of a full buffer. The character just entered is discarded and the next character is awaited by returning to the start of the main loop. The only ways out of this situation would be ESCAPE, a Carriage Return or deleting the last character. Line 700 is the start of the delete routine. As long as Y is greater than 0 it is safe to delete the character. If you try deleting past the start without trapping this error the cursor will move to the end of the previous line. We only actually delete if there is something to delete (which seems sensible) and we do this simply by calling OSWRCH with 127 in the accumulator. The Y register must be reduced by one because there is one less character in the buffer and we return to the start of the loop. Note that in all these cases the Y register will only be increased by one if there is a valid character going into the buffer. The 'check_loop' subroutine is at line 870. We enter this with the character in the accumulator and we will use the X register as an index along a string which contains all the valid characters. This string is at 'valid_list'. So, using the stack as a temporary store for A while we check that we have not reached the end of the list, (where there is a zero), we look along the list, a character at a time, using an indexed addressed version of CMP. When we reach a character in the list that matches the one in A then the zero flag is set and we can branch on zero (BEQ) to the address 'valid'. If we reach a zero in the list first this means the character is not valid and we branch to 'invalid'. Note that after 'invalid' we have to rebalance the stack with a PLA because we didn't reach the one at line 920. Zero is put in the accumulator and the subroutine returns. For a valid character the subroutine returns immediately. The list of valid characters, at line 1070, is terminated by a zero byte. In this example it contains all the characters used in decimal integer arithmetic but you could include a decimal point for example, or &ABCDEF for hexadecimal arithmetic. The buffer is actually one larger than the buffer size is specified, this is to leave room for the final carriage return character. This is the first time we've used the FNEQUM function to set aside some memory. I've put &FF/255 in the buffer to start with but it could contain anything initially. After the assembler is some BASIC which repeatedly calls the routine and prints out the contents of the buffer, so you should see that whatever you input is put into the buffer. In the next module we will use this routine as the basis of an ASCII to binary conversion which will introduce a use of simple multiplication; and in the module after that I will give you a general integer multiplication routine.
00000000 4f 53 42 49 54 53 20 2d 20 41 6e 20 45 78 70 6c |OSBITS - An Expl| 00000010 6f 72 61 74 69 6f 6e 20 6f 66 20 74 68 65 20 42 |oration of the B| 00000020 42 43 20 4d 69 63 72 6f 20 61 74 20 4d 61 63 68 |BC Micro at Mach| 00000030 69 6e 65 20 4c 65 76 65 6c 0d 0d 42 79 20 50 72 |ine Level..By Pr| 00000040 6f 67 72 61 6d 6d 65 72 0d 0d 2e 2e 2e 2e 2e 2e |ogrammer........| 00000050 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e |................| * 00000080 2e 2e 2e 2e 2e 0d 0d 0d 50 61 72 74 20 31 31 3a |........Part 11:| 00000090 20 49 6e 70 75 74 74 69 6e 67 20 4e 75 6d 62 65 | Inputting Numbe| 000000a0 72 73 0d 0d 49 6e 20 74 68 65 73 65 20 6e 65 78 |rs..In these nex| 000000b0 74 20 66 69 76 65 20 6d 6f 64 75 6c 65 73 20 6f |t five modules o| 000000c0 66 20 6d 79 20 65 78 70 6c 6f 72 61 74 69 6f 6e |f my exploration| 000000d0 20 6f 66 20 74 68 65 20 42 42 43 0d 4d 69 63 72 | of the BBC.Micr| 000000e0 6f 20 49 20 61 6d 20 67 6f 69 6e 67 20 74 6f 20 |o I am going to | 000000f0 63 6f 76 65 72 20 74 77 6f 20 61 72 65 61 73 2e |cover two areas.| 00000100 20 20 54 68 65 79 20 61 72 65 20 63 6f 6e 76 65 | They are conve| 00000110 72 74 69 6e 67 0d 41 53 43 49 49 20 6e 75 6d 62 |rting.ASCII numb| 00000120 65 72 73 20 69 6e 74 6f 20 6e 75 6d 62 65 72 73 |ers into numbers| 00000130 20 69 6e 20 6d 65 6d 6f 72 79 20 28 69 6e 70 75 | in memory (inpu| 00000140 74 29 2c 20 61 6e 64 20 76 69 63 65 20 76 65 72 |t), and vice ver| 00000150 73 61 0d 28 6f 75 74 70 75 74 29 2c 20 61 6e 64 |sa.(output), and| 00000160 20 74 68 65 20 61 72 69 74 68 6d 65 74 69 63 61 | the arithmetica| 00000170 6c 20 70 72 6f 63 65 73 73 65 73 20 6f 66 20 6d |l processes of m| 00000180 75 6c 74 69 70 6c 69 63 61 74 69 6f 6e 0d 61 6e |ultiplication.an| 00000190 64 20 64 69 76 69 73 69 6f 6e 2e 20 20 53 69 6e |d division. Sin| 000001a0 63 65 20 69 6e 70 75 74 74 69 6e 67 20 61 6e 64 |ce inputting and| 000001b0 20 6d 75 6c 74 69 70 6c 69 63 61 74 69 6f 6e 20 | multiplication | 000001c0 61 72 65 0d 63 6f 6e 6e 65 63 74 65 64 20 74 68 |are.connected th| 000001d0 65 79 20 77 69 6c 6c 20 63 6f 6d 65 20 66 69 72 |ey will come fir| 000001e0 73 74 2e 0d 0d 49 6e 20 74 68 65 20 70 72 6f 67 |st...In the prog| 000001f0 72 61 6d 6d 69 6e 67 20 65 78 61 6d 70 6c 65 73 |ramming examples| 00000200 20 73 6f 20 66 61 72 20 49 20 68 61 76 65 20 75 | so far I have u| 00000210 73 65 64 20 4f 53 52 44 43 48 20 74 6f 0d 70 72 |sed OSRDCH to.pr| 00000220 6f 76 69 64 65 20 75 73 20 77 69 74 68 20 61 20 |ovide us with a | 00000230 73 69 6e 67 6c 65 20 62 79 74 65 2e 20 20 49 6e |single byte. In| 00000240 20 6d 6f 64 75 6c 65 20 36 20 77 65 20 70 72 69 | module 6 we pri| 00000250 6e 74 65 64 20 6f 75 74 0d 74 68 65 20 76 61 6c |nted out.the val| 00000260 75 65 20 6f 66 20 74 68 61 74 20 62 79 74 65 20 |ue of that byte | 00000270 69 6e 20 74 68 72 65 65 20 66 6f 72 6d 61 74 73 |in three formats| 00000280 2c 20 64 65 63 69 6d 61 6c 2c 0d 68 65 78 61 64 |, decimal,.hexad| 00000290 65 63 69 6d 61 6c 20 61 6e 64 20 62 69 6e 61 72 |ecimal and binar| 000002a0 79 2e 20 20 42 75 74 20 77 65 20 77 65 72 65 20 |y. But we were | 000002b0 65 78 70 65 63 74 69 6e 67 20 61 20 73 69 6e 67 |expecting a sing| 000002c0 6c 65 0d 62 79 74 65 2c 20 61 6e 64 20 61 73 20 |le.byte, and as | 000002d0 4f 53 52 44 43 48 20 77 61 73 20 62 65 69 6e 67 |OSRDCH was being| 000002e0 20 75 73 65 64 20 74 68 61 74 20 77 61 73 20 61 | used that was a| 000002f0 6c 6c 20 77 65 20 67 6f 74 2e 0d 0d 54 68 65 20 |ll we got...The | 00000300 69 6e 70 75 74 20 72 6f 75 74 69 6e 65 20 69 6e |input routine in| 00000310 20 74 68 69 73 20 6d 6f 64 75 6c 65 20 69 73 20 | this module is | 00000320 64 65 73 69 67 6e 65 64 20 74 6f 20 61 63 63 65 |designed to acce| 00000330 70 74 20 6c 61 72 67 65 0d 6e 75 6d 62 65 72 73 |pt large.numbers| 00000340 2e 20 20 59 6f 75 20 63 61 6e 20 64 65 66 69 6e |. You can defin| 00000350 65 20 6a 75 73 74 20 68 6f 77 20 6c 61 72 67 65 |e just how large| 00000360 20 79 6f 75 72 73 65 6c 66 2c 20 62 75 74 20 66 | yourself, but f| 00000370 6f 72 0d 74 68 65 20 74 69 6d 65 20 62 65 69 6e |or.the time bein| 00000380 67 20 77 65 20 77 69 6c 6c 20 73 74 69 63 6b 20 |g we will stick | 00000390 74 6f 20 6e 75 6d 62 65 72 73 20 74 68 61 74 20 |to numbers that | 000003a0 63 61 6e 20 62 65 20 68 65 6c 64 20 69 6e 0d 33 |can be held in.3| 000003b0 32 20 62 69 74 73 2e 0d 0d 49 6e 20 74 68 65 20 |2 bits...In the | 000003c0 72 65 61 6c 20 77 6f 72 6c 64 20 74 68 65 72 65 |real world there| 000003d0 20 61 72 65 20 61 6c 77 61 79 73 20 75 73 65 72 | are always user| 000003e0 73 20 77 68 6f 73 65 20 6d 61 69 6e 20 61 69 6d |s whose main aim| 000003f0 20 69 6e 0d 6c 69 66 65 20 69 73 20 74 6f 20 63 | in.life is to c| 00000400 72 61 73 68 20 79 6f 75 72 20 70 72 6f 67 72 61 |rash your progra| 00000410 6d 73 2c 20 61 6e 64 20 71 75 69 74 65 20 72 69 |ms, and quite ri| 00000420 67 68 74 20 74 6f 6f 2e 20 20 59 6f 75 0d 68 61 |ght too. You.ha| 00000430 76 65 20 74 6f 20 74 72 79 20 74 6f 20 61 6e 74 |ve to try to ant| 00000440 69 63 69 70 61 74 65 20 65 76 65 72 79 74 68 69 |icipate everythi| 00000450 6e 67 20 61 20 6d 61 6c 69 63 69 6f 75 73 20 75 |ng a malicious u| 00000460 73 65 72 20 28 6f 72 20 61 0d 73 6f 66 74 77 61 |ser (or a.softwa| 00000470 72 65 20 61 75 64 69 74 6f 72 29 20 77 6f 75 6c |re auditor) woul| 00000480 64 20 64 6f 20 65 76 65 6e 20 69 66 20 69 74 20 |d do even if it | 00000490 73 65 65 6d 73 20 74 6f 74 61 6c 6c 79 0d 69 6c |seems totally.il| 000004a0 6c 6f 67 69 63 61 6c 2e 20 20 4e 6f 77 68 65 72 |logical. Nowher| 000004b0 65 20 69 73 20 74 68 69 73 20 61 20 67 72 65 61 |e is this a grea| 000004c0 74 65 72 20 70 72 6f 62 6c 65 6d 20 74 68 61 6e |ter problem than| 000004d0 20 77 69 74 68 0d 69 6e 70 75 74 20 72 6f 75 74 | with.input rout| 000004e0 69 6e 65 73 2e 0d 0d 46 69 72 73 74 20 77 65 20 |ines...First we | 000004f0 6d 75 73 74 20 64 65 63 69 64 65 20 77 68 61 74 |must decide what| 00000500 20 6f 75 72 20 69 6e 70 75 74 20 72 6f 75 74 69 | our input routi| 00000510 6e 65 20 69 73 20 67 6f 69 6e 67 20 74 6f 20 64 |ne is going to d| 00000520 6f 2e 20 0d 54 68 69 73 20 69 73 20 6b 6e 6f 77 |o. .This is know| 00000530 6e 20 61 73 20 69 74 73 20 46 75 6e 63 74 69 6f |n as its Functio| 00000540 6e 61 6c 20 53 70 65 63 69 66 69 63 61 74 69 6f |nal Specificatio| 00000550 6e 2c 20 61 6e 64 20 65 76 65 6e 20 69 66 0d 79 |n, and even if.y| 00000560 6f 75 20 66 69 6e 65 20 74 75 6e 65 20 69 74 20 |ou fine tune it | 00000570 61 6c 6f 6e 67 20 74 68 65 20 77 61 79 20 69 74 |along the way it| 00000580 20 68 65 6c 70 73 20 65 6e 6f 72 6d 6f 75 73 6c | helps enormousl| 00000590 79 20 74 6f 20 6b 6e 6f 77 0d 77 68 61 74 20 79 |y to know.what y| 000005a0 6f 75 20 61 72 65 20 74 72 79 69 6e 67 20 74 6f |ou are trying to| 000005b0 20 61 63 68 69 65 76 65 2e 20 20 49 6e 20 69 74 | achieve. In it| 000005c0 73 20 62 72 69 65 66 65 73 74 20 66 6f 72 6d 20 |s briefest form | 000005d0 74 68 65 6e 0d 74 68 65 20 66 75 6e 63 74 69 6f |then.the functio| 000005e0 6e 61 6c 20 73 70 65 63 20 6f 66 20 74 68 69 73 |nal spec of this| 000005f0 20 6d 6f 64 75 6c 65 20 69 73 20 61 73 20 66 6f | module is as fo| 00000600 6c 6c 6f 77 73 3a 0d 0d 50 75 74 20 61 20 73 74 |llows:..Put a st| 00000610 72 69 6e 67 20 74 79 70 65 64 20 69 6e 20 62 79 |ring typed in by| 00000620 20 74 68 65 20 75 73 65 72 20 69 6e 74 6f 20 61 | the user into a| 00000630 20 64 65 66 69 6e 65 64 20 61 72 65 61 20 6f 66 | defined area of| 00000640 0d 6d 65 6d 6f 72 79 2c 20 72 65 6a 65 63 74 69 |.memory, rejecti| 00000650 6e 67 20 61 6e 79 20 63 68 61 72 61 63 74 65 72 |ng any character| 00000660 73 20 74 68 61 74 20 64 6f 20 6e 6f 74 20 66 6f |s that do not fo| 00000670 72 6d 20 6e 75 6d 62 65 72 73 0d 61 6e 64 20 61 |rm numbers.and a| 00000680 6c 6c 6f 77 69 6e 67 20 74 68 65 20 75 73 65 72 |llowing the user| 00000690 20 74 6f 20 64 65 6c 65 74 65 20 74 68 65 20 6c | to delete the l| 000006a0 61 73 74 20 63 68 61 72 61 63 74 65 72 20 68 65 |ast character he| 000006b0 20 69 6e 70 75 74 2e 0d 54 68 65 20 6d 6f 64 75 | input..The modu| 000006c0 6c 65 20 73 68 6f 75 6c 64 20 62 65 20 77 72 69 |le should be wri| 000006d0 74 74 65 6e 20 69 6e 20 73 75 63 68 20 61 20 77 |tten in such a w| 000006e0 61 79 20 61 73 20 74 6f 20 62 65 20 65 61 73 69 |ay as to be easi| 000006f0 6c 79 0d 69 6e 63 6f 72 70 6f 72 61 74 65 64 20 |ly.incorporated | 00000700 69 6e 20 61 6e 20 41 53 43 49 49 20 74 6f 20 62 |in an ASCII to b| 00000710 69 6e 61 72 79 20 63 6f 6e 76 65 72 73 69 6f 6e |inary conversion| 00000720 20 72 6f 75 74 69 6e 65 20 69 6e 20 74 68 65 0d | routine in the.| 00000730 6e 65 78 74 20 6d 6f 64 75 6c 65 2e 0d 0d 54 68 |next module...Th| 00000740 65 72 65 20 69 73 20 61 6e 20 4f 53 20 72 6f 75 |ere is an OS rou| 00000750 74 69 6e 65 20 66 6f 72 20 69 6e 70 75 74 20 77 |tine for input w| 00000760 68 69 63 68 20 77 65 20 63 6f 75 6c 64 20 75 73 |hich we could us| 00000770 65 2e 20 20 49 74 20 69 73 0d 4f 53 57 4f 52 44 |e. It is.OSWORD| 00000780 20 30 20 61 6e 64 20 6f 6e 20 65 6e 74 72 79 20 | 0 and on entry | 00000790 77 65 20 63 61 6e 20 73 70 65 63 69 66 79 20 61 |we can specify a| 000007a0 20 70 69 65 63 65 20 6f 66 20 6d 65 6d 6f 72 79 | piece of memory| 000007b0 20 74 6f 0d 75 73 65 20 74 6f 20 68 6f 6c 64 20 | to.use to hold | 000007c0 74 68 65 20 73 74 72 69 6e 67 20 69 6e 70 75 74 |the string input| 000007d0 2c 20 74 68 65 20 69 6e 70 75 74 20 62 75 66 66 |, the input buff| 000007e0 65 72 2c 20 61 6e 64 20 77 65 20 63 61 6e 0d 61 |er, and we can.a| 000007f0 6c 73 6f 20 73 65 74 20 61 6e 20 75 70 70 65 72 |lso set an upper| 00000800 20 61 6e 64 20 6c 6f 77 65 72 20 6c 69 6d 69 74 | and lower limit| 00000810 20 74 6f 20 74 68 65 20 63 68 61 72 61 63 74 65 | to the characte| 00000820 72 73 20 61 63 63 65 70 74 65 64 0d 61 6e 64 20 |rs accepted.and | 00000830 74 68 65 20 6c 65 6e 67 74 68 20 6f 66 20 74 68 |the length of th| 00000840 65 20 73 74 72 69 6e 67 2e 20 20 4f 6e 20 65 78 |e string. On ex| 00000850 69 74 20 66 72 6f 6d 20 74 68 65 20 72 6f 75 74 |it from the rout| 00000860 69 6e 65 20 77 65 0d 63 61 6e 20 66 69 6e 64 20 |ine we.can find | 00000870 6f 75 74 20 74 68 65 20 6c 65 6e 67 74 68 20 6f |out the length o| 00000880 66 20 74 68 65 20 73 74 72 69 6e 67 20 65 6e 74 |f the string ent| 00000890 65 72 65 64 20 61 6e 64 20 77 65 20 63 61 6e 0d |ered and we can.| 000008a0 63 68 65 63 6b 20 66 6f 72 20 45 53 43 41 50 45 |check for ESCAPE| 000008b0 20 62 65 69 6e 67 20 70 72 65 73 73 65 64 2e 0d | being pressed..| 000008c0 0d 48 6f 77 65 76 65 72 2c 20 4f 53 57 4f 52 44 |.However, OSWORD| 000008d0 20 30 20 68 61 73 20 73 6f 6d 65 20 64 69 73 61 | 0 has some disa| 000008e0 64 76 61 6e 74 61 67 65 73 2e 20 20 57 68 65 6e |dvantages. When| 000008f0 20 79 6f 75 20 64 65 66 69 6e 65 0d 6c 69 6d 69 | you define.limi| 00000900 74 73 20 74 6f 20 74 68 65 20 63 68 61 72 61 63 |ts to the charac| 00000910 74 65 72 73 20 65 6e 74 65 72 65 64 20 74 68 65 |ters entered the| 00000920 20 72 6f 75 74 69 6e 65 20 62 65 68 61 76 65 73 | routine behaves| 00000930 20 61 0d 6c 69 74 74 6c 65 20 65 63 63 65 6e 74 | a.little eccent| 00000940 72 69 63 61 6c 6c 79 2e 20 20 49 6e 76 61 6c 69 |rically. Invali| 00000950 64 20 63 68 61 72 61 63 74 65 72 73 20 61 72 65 |d characters are| 00000960 20 73 74 69 6c 6c 20 70 72 69 6e 74 65 64 0d 74 | still printed.t| 00000970 6f 20 74 68 65 20 73 63 72 65 65 6e 20 61 6e 64 |o the screen and| 00000980 20 61 74 74 65 6d 70 74 73 20 74 6f 20 64 65 6c | attempts to del| 00000990 65 74 65 20 63 68 61 72 61 63 74 65 72 73 20 77 |ete characters w| 000009a0 69 6c 6c 20 68 61 76 65 0d 75 6e 70 72 65 64 69 |ill have.unpredi| 000009b0 63 74 61 62 6c 65 20 72 65 73 75 6c 74 73 20 69 |ctable results i| 000009c0 66 20 69 6e 76 61 6c 69 64 20 63 68 61 72 61 63 |f invalid charac| 000009d0 74 65 72 73 20 61 72 65 20 70 72 65 73 65 6e 74 |ters are present| 000009e0 2e 20 20 49 0d 74 68 6f 75 67 68 74 20 69 74 20 |. I.thought it | 000009f0 77 6f 75 6c 64 20 62 65 20 61 6e 20 69 6e 74 65 |would be an inte| 00000a00 72 65 73 74 69 6e 67 20 65 78 65 72 63 69 73 65 |resting exercise| 00000a10 20 74 6f 20 77 72 69 74 65 20 61 0d 73 69 6d 69 | to write a.simi| 00000a20 6c 61 72 20 72 6f 75 74 69 6e 65 20 6d 79 73 65 |lar routine myse| 00000a30 6c 66 20 77 68 69 63 68 20 77 6f 75 6c 64 20 6e |lf which would n| 00000a40 6f 74 20 65 78 68 69 62 69 74 20 73 75 63 68 20 |ot exhibit such | 00000a50 73 74 72 61 6e 67 65 0d 62 65 68 61 76 69 6f 75 |strange.behaviou| 00000a60 72 20 61 6e 64 20 77 68 69 63 68 20 77 6f 75 6c |r and which woul| 00000a70 64 20 61 6c 6c 6f 77 20 63 6c 65 61 72 65 72 20 |d allow clearer | 00000a80 64 65 66 69 6e 69 6e 67 20 6f 66 0d 63 68 61 72 |defining of.char| 00000a90 61 63 74 65 72 20 6c 69 6d 69 74 73 2e 0d 0d 53 |acter limits...S| 00000aa0 6f 2c 20 62 65 66 6f 72 65 20 67 6f 69 6e 67 20 |o, before going | 00000ab0 6f 6e 20 69 6e 20 74 68 65 20 6e 65 78 74 20 6d |on in the next m| 00000ac0 6f 64 75 6c 65 20 74 6f 20 75 73 69 6e 67 20 74 |odule to using t| 00000ad0 68 69 73 20 72 6f 75 74 69 6e 65 0d 61 73 20 61 |his routine.as a| 00000ae0 20 62 61 73 69 73 20 66 6f 72 20 69 6e 70 75 74 | basis for input| 00000af0 74 69 6e 67 20 6e 75 6d 62 65 72 73 20 61 6e 64 |ting numbers and| 00000b00 20 63 6f 6e 76 65 72 74 69 6e 67 20 74 68 65 6d | converting them| 00000b10 20 74 6f 0d 62 69 6e 61 72 79 20 69 6e 20 6d 65 | to.binary in me| 00000b20 6d 6f 72 79 2c 20 6c 65 74 27 73 20 6c 6f 6f 6b |mory, let's look| 00000b30 20 61 74 20 74 68 69 73 20 6d 6f 64 75 6c 65 2c | at this module,| 00000b40 20 42 2f 6f 73 62 31 31 2e 0d 0d 54 68 65 20 66 | B/osb11...The f| 00000b50 6c 6f 77 20 6f 66 20 74 68 65 20 70 72 6f 67 72 |low of the progr| 00000b60 61 6d 20 67 6f 65 73 20 6c 69 6b 65 20 74 68 69 |am goes like thi| 00000b70 73 3a 0d 0d 20 20 20 20 49 6e 70 75 74 20 61 20 |s:.. Input a | 00000b80 63 68 61 72 61 63 74 65 72 20 75 73 69 6e 67 20 |character using | 00000b90 4f 53 52 44 43 48 0d 20 20 20 20 28 49 66 20 61 |OSRDCH. (If a| 00000ba0 6e 20 65 72 72 6f 72 20 68 61 73 20 6f 63 63 75 |n error has occu| 00000bb0 72 72 65 64 20 74 68 65 6e 20 65 78 69 74 29 0d |rred then exit).| 00000bc0 20 20 20 20 43 68 65 63 6b 20 66 6f 72 20 61 20 | Check for a | 00000bd0 63 61 72 72 69 61 67 65 20 72 65 74 75 72 6e 20 |carriage return | 00000be0 77 68 69 63 68 20 74 65 72 6d 69 6e 61 74 65 73 |which terminates| 00000bf0 20 69 6e 70 75 74 0d 20 20 20 20 28 49 66 20 61 | input. (If a| 00000c00 20 43 52 20 74 68 65 6e 20 65 78 69 74 29 0d 20 | CR then exit). | 00000c10 20 20 20 43 68 65 63 6b 20 66 6f 72 20 61 20 64 | Check for a d| 00000c20 65 6c 65 74 65 0d 20 20 20 20 28 49 66 20 61 20 |elete. (If a | 00000c30 64 65 6c 65 74 65 20 74 68 65 6e 20 72 65 6d 6f |delete then remo| 00000c40 76 65 20 6c 61 73 74 20 63 68 61 72 61 63 74 65 |ve last characte| 00000c50 72 29 0d 20 20 20 20 43 68 65 63 6b 20 61 6e 79 |r). Check any| 00000c60 20 6f 74 68 65 72 20 63 68 61 72 61 63 74 65 72 | other character| 00000c70 73 20 61 67 61 69 6e 73 74 20 76 61 6c 69 64 20 |s against valid | 00000c80 6c 69 73 74 0d 20 20 20 20 4f 75 74 70 75 74 20 |list. Output | 00000c90 61 6e 79 20 76 61 6c 69 64 20 63 68 61 72 61 63 |any valid charac| 00000ca0 74 65 72 20 74 6f 20 73 63 72 65 65 6e 20 61 6e |ter to screen an| 00000cb0 64 20 61 64 64 20 74 6f 20 73 74 72 69 6e 67 0d |d add to string.| 00000cc0 20 20 20 20 20 20 20 20 69 6e 20 6d 65 6d 6f 72 | in memor| 00000cd0 79 0d 0d 57 65 20 77 69 6c 6c 20 75 73 65 20 74 |y..We will use t| 00000ce0 68 65 20 59 20 72 65 67 69 73 74 65 72 20 74 6f |he Y register to| 00000cf0 20 6b 65 65 70 20 74 72 61 63 6b 20 6f 66 20 74 | keep track of t| 00000d00 68 65 20 70 6f 73 69 74 69 6f 6e 20 6f 66 0d 6f |he position of.o| 00000d10 75 72 20 6c 61 73 74 20 63 68 61 72 61 63 74 65 |ur last characte| 00000d20 72 20 69 6e 20 74 68 65 20 62 75 66 66 65 72 2e |r in the buffer.| 00000d30 0d 0d 54 68 65 20 6d 61 69 6e 20 73 65 63 74 69 |..The main secti| 00000d40 6f 6e 20 6f 66 20 74 68 65 20 63 6f 64 65 20 6c |on of the code l| 00000d50 69 65 73 20 62 65 74 77 65 65 6e 20 6c 69 6e 65 |ies between line| 00000d60 73 20 32 31 30 20 61 6e 64 20 33 39 30 2e 20 0d |s 210 and 390. .| 00000d70 48 65 72 65 20 61 20 63 68 61 72 61 63 74 65 72 |Here a character| 00000d80 20 69 73 20 63 61 70 74 75 72 65 64 20 75 73 69 | is captured usi| 00000d90 6e 67 20 4f 53 52 44 43 48 20 61 6e 64 20 69 74 |ng OSRDCH and it| 00000da0 20 69 73 20 63 68 65 63 6b 65 64 0d 74 6f 20 73 | is checked.to s| 00000db0 65 65 20 69 66 20 69 74 20 69 73 20 61 20 63 61 |ee if it is a ca| 00000dc0 72 72 69 61 67 65 20 72 65 74 75 72 6e 20 28 31 |rriage return (1| 00000dd0 33 29 20 6f 72 20 61 20 64 65 6c 65 74 65 20 28 |3) or a delete (| 00000de0 31 32 37 29 2c 0d 65 61 63 68 20 6f 66 20 77 68 |127),.each of wh| 00000df0 69 63 68 20 67 65 74 20 73 70 65 63 69 61 6c 20 |ich get special | 00000e00 74 72 65 61 74 6d 65 6e 74 2e 20 20 54 68 65 20 |treatment. The | 00000e10 6e 75 6d 62 65 72 20 6f 66 0d 63 68 61 72 61 63 |number of.charac| 00000e20 74 65 72 73 20 69 6e 20 74 68 65 20 62 75 66 66 |ters in the buff| 00000e30 65 72 20 69 73 20 63 68 65 63 6b 65 64 20 61 67 |er is checked ag| 00000e40 61 69 6e 73 74 20 74 68 65 20 62 75 66 66 65 72 |ainst the buffer| 00000e50 0d 6c 65 6e 67 74 68 2e 20 20 49 66 20 69 74 20 |.length. If it | 00000e60 70 61 73 73 65 73 20 74 68 65 73 65 20 74 65 73 |passes these tes| 00000e70 74 73 20 74 68 65 6e 20 74 68 65 20 63 68 61 72 |ts then the char| 00000e80 61 63 74 65 72 20 69 73 0d 63 68 65 63 6b 65 64 |acter is.checked| 00000e90 20 62 79 20 61 20 73 75 62 72 6f 75 74 69 6e 65 | by a subroutine| 00000ea0 20 61 74 20 27 63 68 65 63 6b 5f 63 68 61 72 61 | at 'check_chara| 00000eb0 63 74 65 72 27 20 77 68 69 63 68 20 77 65 20 77 |cter' which we w| 00000ec0 69 6c 6c 0d 63 6f 6d 65 20 6f 6e 74 6f 20 69 6e |ill.come onto in| 00000ed0 20 61 20 6d 6f 6d 65 6e 74 2e 20 20 49 66 20 74 | a moment. If t| 00000ee0 68 65 20 61 63 63 75 6d 75 6c 61 74 6f 72 20 63 |he accumulator c| 00000ef0 6f 6e 74 61 69 6e 73 20 61 20 6e 75 6c 6c 0d 28 |ontains a null.(| 00000f00 7a 65 72 6f 29 20 61 66 74 65 72 20 74 68 69 73 |zero) after this| 00000f10 20 73 75 62 72 6f 75 74 69 6e 65 20 74 68 65 6e | subroutine then| 00000f20 20 74 68 65 20 63 68 61 72 61 63 74 65 72 20 77 | the character w| 00000f30 61 73 20 6e 6f 74 0d 76 61 6c 69 64 2e 20 20 4f |as not.valid. O| 00000f40 74 68 65 72 77 69 73 65 20 74 68 65 20 63 68 61 |therwise the cha| 00000f50 72 61 63 74 65 72 2c 20 77 68 69 63 68 20 68 61 |racter, which ha| 00000f60 73 20 6e 6f 77 20 70 61 73 73 65 64 20 61 6c 6c |s now passed all| 00000f70 0d 74 68 65 20 74 65 73 74 73 2c 20 69 73 20 73 |.the tests, is s| 00000f80 65 6e 74 20 74 6f 20 74 68 65 20 73 63 72 65 65 |ent to the scree| 00000f90 6e 20 61 6e 64 20 61 64 64 65 64 20 74 6f 20 74 |n and added to t| 00000fa0 68 65 20 73 74 72 69 6e 67 20 69 6e 0d 6d 65 6d |he string in.mem| 00000fb0 6f 72 79 20 61 74 20 27 69 6e 70 75 74 5f 62 75 |ory at 'input_bu| 00000fc0 66 66 65 72 27 2e 20 20 54 68 65 20 59 20 72 65 |ffer'. The Y re| 00000fd0 67 69 73 74 65 72 2c 20 77 68 69 63 68 20 69 73 |gister, which is| 00000fe0 20 63 6f 75 6e 74 69 6e 67 0d 6f 75 72 20 77 61 | counting.our wa| 00000ff0 79 20 61 6c 6f 6e 67 20 74 68 69 73 20 62 75 66 |y along this buf| 00001000 66 65 72 2c 20 69 73 20 69 6e 63 72 65 61 73 65 |fer, is increase| 00001010 64 2e 20 20 49 74 20 77 69 6c 6c 20 61 6c 77 61 |d. It will alwa| 00001020 79 73 0d 68 6f 6c 64 20 74 68 65 20 6e 75 6d 62 |ys.hold the numb| 00001030 65 72 20 6f 66 20 63 68 61 72 61 63 74 65 72 73 |er of characters| 00001040 20 69 6e 20 74 68 65 20 69 6e 70 75 74 20 62 75 | in the input bu| 00001050 66 66 65 72 2e 0d 0d 4c 69 6e 65 20 34 31 30 20 |ffer...Line 410 | 00001060 69 73 20 77 68 65 72 65 20 74 68 65 20 63 6f 64 |is where the cod| 00001070 65 20 74 61 6b 65 73 20 75 73 20 61 66 74 65 72 |e takes us after| 00001080 20 61 20 63 61 72 72 69 61 67 65 20 72 65 74 75 | a carriage retu| 00001090 72 6e 2e 20 0d 54 68 69 73 20 74 65 72 6d 69 6e |rn. .This termin| 000010a0 61 74 65 73 20 74 68 65 20 69 6e 70 75 74 20 61 |ates the input a| 000010b0 6e 64 20 77 65 20 73 74 6f 72 65 20 61 20 43 52 |nd we store a CR| 000010c0 20 61 74 20 74 68 65 20 65 6e 64 20 6f 66 0d 74 | at the end of.t| 000010d0 68 65 20 73 74 72 69 6e 67 20 61 6e 64 20 61 6c |he string and al| 000010e0 73 6f 20 73 74 6f 72 65 20 74 68 65 20 6c 65 6e |so store the len| 000010f0 67 74 68 20 69 6e 20 61 20 70 69 65 63 65 20 6f |gth in a piece o| 00001100 66 20 6d 65 6d 6f 72 79 0d 6c 61 62 65 6c 6c 65 |f memory.labelle| 00001110 64 20 27 73 74 72 69 6e 67 5f 6c 65 6e 67 74 68 |d 'string_length| 00001120 27 2e 20 20 54 68 69 73 20 6c 61 74 74 65 72 20 |'. This latter | 00001130 69 73 20 74 6f 20 61 6c 6c 6f 77 20 75 73 20 74 |is to allow us t| 00001140 6f 20 75 73 65 0d 42 41 53 49 43 20 74 6f 20 63 |o use.BASIC to c| 00001150 68 65 63 6b 20 74 68 61 74 20 74 68 65 20 72 6f |heck that the ro| 00001160 75 74 69 6e 65 20 69 73 20 77 6f 72 6b 69 6e 67 |utine is working| 00001170 20 63 6f 72 72 65 63 74 6c 79 20 61 66 74 65 72 | correctly after| 00001180 0d 77 65 20 68 61 76 65 20 61 73 73 65 6d 62 6c |.we have assembl| 00001190 65 64 20 74 68 65 20 70 72 6f 67 72 61 6d 2e 20 |ed the program. | 000011a0 20 57 65 20 65 78 69 74 20 68 61 76 69 6e 67 20 | We exit having | 000011b0 63 6c 65 61 72 65 64 20 74 68 65 0d 43 61 72 72 |cleared the.Carr| 000011c0 79 20 66 6c 61 67 20 73 6f 20 74 68 69 73 20 63 |y flag so this c| 000011d0 61 6e 20 62 65 20 75 73 65 64 20 74 6f 20 69 6e |an be used to in| 000011e0 64 69 63 61 74 65 20 61 20 76 61 6c 69 64 20 72 |dicate a valid r| 000011f0 65 73 75 6c 74 2e 0d 0d 4c 69 6e 65 20 35 32 30 |esult...Line 520| 00001200 20 69 73 20 77 68 65 72 65 20 77 65 20 67 6f 20 | is where we go | 00001210 6f 6e 20 64 65 74 65 63 74 69 6e 67 20 61 6e 20 |on detecting an | 00001220 65 72 72 6f 72 2c 20 75 73 75 61 6c 6c 79 0d 45 |error, usually.E| 00001230 53 43 41 50 45 2c 20 64 75 72 69 6e 67 20 69 6e |SCAPE, during in| 00001240 70 75 74 2e 20 20 4e 6f 74 65 20 74 68 61 74 20 |put. Note that | 00001250 70 61 72 74 20 6f 66 20 74 68 65 20 73 74 72 69 |part of the stri| 00001260 6e 67 20 6d 61 79 20 62 65 0d 69 6e 20 6d 65 6d |ng may be.in mem| 00001270 6f 72 79 20 61 6e 64 20 74 68 61 74 20 74 68 65 |ory and that the| 00001280 20 43 61 72 72 79 20 66 6c 61 67 20 77 69 6c 6c | Carry flag will| 00001290 20 62 65 20 73 65 74 2e 20 20 41 67 61 69 6e 20 | be set. Again | 000012a0 77 65 20 63 61 6e 0d 75 73 65 20 74 68 69 73 20 |we can.use this | 000012b0 74 6f 20 69 6e 64 69 63 61 74 65 20 61 6e 20 69 |to indicate an i| 000012c0 6e 76 61 6c 69 64 20 72 65 73 75 6c 74 2e 0d 0d |nvalid result...| 000012d0 41 74 20 6c 69 6e 65 20 36 31 30 20 69 73 20 61 |At line 610 is a| 000012e0 20 72 6f 75 74 69 6e 65 20 77 65 20 65 6e 74 65 | routine we ente| 000012f0 72 20 69 66 20 74 68 65 20 62 75 66 66 65 72 20 |r if the buffer | 00001300 77 61 73 20 61 6c 72 65 61 64 79 0d 66 75 6c 6c |was already.full| 00001310 20 77 68 65 6e 20 61 20 6e 65 77 20 63 68 61 72 | when a new char| 00001320 61 63 74 65 72 20 77 61 73 20 6b 65 79 65 64 20 |acter was keyed | 00001330 69 6e 2e 20 20 54 68 65 20 6d 69 63 72 6f 20 62 |in. The micro b| 00001340 65 65 70 73 20 28 62 79 0d 75 73 69 6e 67 20 56 |eeps (by.using V| 00001350 44 55 37 2c 20 69 2e 65 2e 20 4f 53 57 52 43 48 |DU7, i.e. OSWRCH| 00001360 20 77 69 74 68 20 37 20 69 6e 20 74 68 65 20 61 | with 7 in the a| 00001370 63 63 75 6d 75 6c 61 74 6f 72 29 20 74 6f 20 77 |ccumulator) to w| 00001380 61 72 6e 0d 6f 66 20 61 20 66 75 6c 6c 20 62 75 |arn.of a full bu| 00001390 66 66 65 72 2e 20 20 54 68 65 20 63 68 61 72 61 |ffer. The chara| 000013a0 63 74 65 72 20 6a 75 73 74 20 65 6e 74 65 72 65 |cter just entere| 000013b0 64 20 69 73 20 64 69 73 63 61 72 64 65 64 0d 61 |d is discarded.a| 000013c0 6e 64 20 74 68 65 20 6e 65 78 74 20 63 68 61 72 |nd the next char| 000013d0 61 63 74 65 72 20 69 73 20 61 77 61 69 74 65 64 |acter is awaited| 000013e0 20 62 79 20 72 65 74 75 72 6e 69 6e 67 20 74 6f | by returning to| 000013f0 20 74 68 65 20 73 74 61 72 74 0d 6f 66 20 74 68 | the start.of th| 00001400 65 20 6d 61 69 6e 20 6c 6f 6f 70 2e 20 20 54 68 |e main loop. Th| 00001410 65 20 6f 6e 6c 79 20 77 61 79 73 20 6f 75 74 20 |e only ways out | 00001420 6f 66 20 74 68 69 73 20 73 69 74 75 61 74 69 6f |of this situatio| 00001430 6e 20 77 6f 75 6c 64 0d 62 65 20 45 53 43 41 50 |n would.be ESCAP| 00001440 45 2c 20 61 20 43 61 72 72 69 61 67 65 20 52 65 |E, a Carriage Re| 00001450 74 75 72 6e 20 6f 72 20 64 65 6c 65 74 69 6e 67 |turn or deleting| 00001460 20 74 68 65 20 6c 61 73 74 20 63 68 61 72 61 63 | the last charac| 00001470 74 65 72 2e 0d 0d 4c 69 6e 65 20 37 30 30 20 69 |ter...Line 700 i| 00001480 73 20 74 68 65 20 73 74 61 72 74 20 6f 66 20 74 |s the start of t| 00001490 68 65 20 64 65 6c 65 74 65 20 72 6f 75 74 69 6e |he delete routin| 000014a0 65 2e 20 20 41 73 20 6c 6f 6e 67 20 61 73 20 59 |e. As long as Y| 000014b0 0d 69 73 20 67 72 65 61 74 65 72 20 74 68 61 6e |.is greater than| 000014c0 20 30 20 69 74 20 69 73 20 73 61 66 65 20 74 6f | 0 it is safe to| 000014d0 20 64 65 6c 65 74 65 20 74 68 65 20 63 68 61 72 | delete the char| 000014e0 61 63 74 65 72 2e 20 20 49 66 0d 79 6f 75 20 74 |acter. If.you t| 000014f0 72 79 20 64 65 6c 65 74 69 6e 67 20 70 61 73 74 |ry deleting past| 00001500 20 74 68 65 20 73 74 61 72 74 20 77 69 74 68 6f | the start witho| 00001510 75 74 20 74 72 61 70 70 69 6e 67 20 74 68 69 73 |ut trapping this| 00001520 20 65 72 72 6f 72 0d 74 68 65 20 63 75 72 73 6f | error.the curso| 00001530 72 20 77 69 6c 6c 20 6d 6f 76 65 20 74 6f 20 74 |r will move to t| 00001540 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20 70 72 |he end of the pr| 00001550 65 76 69 6f 75 73 20 6c 69 6e 65 2e 20 20 57 65 |evious line. We| 00001560 0d 6f 6e 6c 79 20 61 63 74 75 61 6c 6c 79 20 64 |.only actually d| 00001570 65 6c 65 74 65 20 69 66 20 74 68 65 72 65 20 69 |elete if there i| 00001580 73 20 73 6f 6d 65 74 68 69 6e 67 20 74 6f 20 64 |s something to d| 00001590 65 6c 65 74 65 20 28 77 68 69 63 68 0d 73 65 65 |elete (which.see| 000015a0 6d 73 20 73 65 6e 73 69 62 6c 65 29 20 61 6e 64 |ms sensible) and| 000015b0 20 77 65 20 64 6f 20 74 68 69 73 20 73 69 6d 70 | we do this simp| 000015c0 6c 79 20 62 79 20 63 61 6c 6c 69 6e 67 20 4f 53 |ly by calling OS| 000015d0 57 52 43 48 20 77 69 74 68 0d 31 32 37 20 69 6e |WRCH with.127 in| 000015e0 20 74 68 65 20 61 63 63 75 6d 75 6c 61 74 6f 72 | the accumulator| 000015f0 2e 20 20 54 68 65 20 59 20 72 65 67 69 73 74 65 |. The Y registe| 00001600 72 20 6d 75 73 74 20 62 65 20 72 65 64 75 63 65 |r must be reduce| 00001610 64 20 62 79 0d 6f 6e 65 20 62 65 63 61 75 73 65 |d by.one because| 00001620 20 74 68 65 72 65 20 69 73 20 6f 6e 65 20 6c 65 | there is one le| 00001630 73 73 20 63 68 61 72 61 63 74 65 72 20 69 6e 20 |ss character in | 00001640 74 68 65 20 62 75 66 66 65 72 20 61 6e 64 20 77 |the buffer and w| 00001650 65 0d 72 65 74 75 72 6e 20 74 6f 20 74 68 65 20 |e.return to the | 00001660 73 74 61 72 74 20 6f 66 20 74 68 65 20 6c 6f 6f |start of the loo| 00001670 70 2e 0d 0d 4e 6f 74 65 20 74 68 61 74 20 69 6e |p...Note that in| 00001680 20 61 6c 6c 20 74 68 65 73 65 20 63 61 73 65 73 | all these cases| 00001690 20 74 68 65 20 59 20 72 65 67 69 73 74 65 72 20 | the Y register | 000016a0 77 69 6c 6c 20 6f 6e 6c 79 20 62 65 0d 69 6e 63 |will only be.inc| 000016b0 72 65 61 73 65 64 20 62 79 20 6f 6e 65 20 69 66 |reased by one if| 000016c0 20 74 68 65 72 65 20 69 73 20 61 20 76 61 6c 69 | there is a vali| 000016d0 64 20 63 68 61 72 61 63 74 65 72 20 67 6f 69 6e |d character goin| 000016e0 67 20 69 6e 74 6f 0d 74 68 65 20 62 75 66 66 65 |g into.the buffe| 000016f0 72 2e 0d 0d 54 68 65 20 27 63 68 65 63 6b 5f 6c |r...The 'check_l| 00001700 6f 6f 70 27 20 73 75 62 72 6f 75 74 69 6e 65 20 |oop' subroutine | 00001710 69 73 20 61 74 20 6c 69 6e 65 20 38 37 30 2e 20 |is at line 870. | 00001720 20 57 65 20 65 6e 74 65 72 20 74 68 69 73 0d 77 | We enter this.w| 00001730 69 74 68 20 74 68 65 20 63 68 61 72 61 63 74 65 |ith the characte| 00001740 72 20 69 6e 20 74 68 65 20 61 63 63 75 6d 75 6c |r in the accumul| 00001750 61 74 6f 72 20 61 6e 64 20 77 65 20 77 69 6c 6c |ator and we will| 00001760 20 75 73 65 20 74 68 65 20 58 0d 72 65 67 69 73 | use the X.regis| 00001770 74 65 72 20 61 73 20 61 6e 20 69 6e 64 65 78 20 |ter as an index | 00001780 61 6c 6f 6e 67 20 61 20 73 74 72 69 6e 67 20 77 |along a string w| 00001790 68 69 63 68 20 63 6f 6e 74 61 69 6e 73 20 61 6c |hich contains al| 000017a0 6c 20 74 68 65 0d 76 61 6c 69 64 20 63 68 61 72 |l the.valid char| 000017b0 61 63 74 65 72 73 2e 20 20 54 68 69 73 20 73 74 |acters. This st| 000017c0 72 69 6e 67 20 69 73 20 61 74 20 27 76 61 6c 69 |ring is at 'vali| 000017d0 64 5f 6c 69 73 74 27 2e 20 20 53 6f 2c 0d 75 73 |d_list'. So,.us| 000017e0 69 6e 67 20 74 68 65 20 73 74 61 63 6b 20 61 73 |ing the stack as| 000017f0 20 61 20 74 65 6d 70 6f 72 61 72 79 20 73 74 6f | a temporary sto| 00001800 72 65 20 66 6f 72 20 41 20 77 68 69 6c 65 20 77 |re for A while w| 00001810 65 20 63 68 65 63 6b 0d 74 68 61 74 20 77 65 20 |e check.that we | 00001820 68 61 76 65 20 6e 6f 74 20 72 65 61 63 68 65 64 |have not reached| 00001830 20 74 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20 | the end of the | 00001840 6c 69 73 74 2c 20 28 77 68 65 72 65 20 74 68 65 |list, (where the| 00001850 72 65 0d 69 73 20 61 20 7a 65 72 6f 29 2c 20 77 |re.is a zero), w| 00001860 65 20 6c 6f 6f 6b 20 61 6c 6f 6e 67 20 74 68 65 |e look along the| 00001870 20 6c 69 73 74 2c 20 61 20 63 68 61 72 61 63 74 | list, a charact| 00001880 65 72 20 61 74 20 61 20 74 69 6d 65 2c 0d 75 73 |er at a time,.us| 00001890 69 6e 67 20 61 6e 20 69 6e 64 65 78 65 64 20 61 |ing an indexed a| 000018a0 64 64 72 65 73 73 65 64 20 76 65 72 73 69 6f 6e |ddressed version| 000018b0 20 6f 66 20 43 4d 50 2e 20 20 57 68 65 6e 20 77 | of CMP. When w| 000018c0 65 20 72 65 61 63 68 20 61 0d 63 68 61 72 61 63 |e reach a.charac| 000018d0 74 65 72 20 69 6e 20 74 68 65 20 6c 69 73 74 20 |ter in the list | 000018e0 74 68 61 74 20 6d 61 74 63 68 65 73 20 74 68 65 |that matches the| 000018f0 20 6f 6e 65 20 69 6e 20 41 20 74 68 65 6e 20 74 | one in A then t| 00001900 68 65 0d 7a 65 72 6f 20 66 6c 61 67 20 69 73 20 |he.zero flag is | 00001910 73 65 74 20 61 6e 64 20 77 65 20 63 61 6e 20 62 |set and we can b| 00001920 72 61 6e 63 68 20 6f 6e 20 7a 65 72 6f 20 28 42 |ranch on zero (B| 00001930 45 51 29 20 74 6f 20 74 68 65 0d 61 64 64 72 65 |EQ) to the.addre| 00001940 73 73 20 27 76 61 6c 69 64 27 2e 20 20 49 66 20 |ss 'valid'. If | 00001950 77 65 20 72 65 61 63 68 20 61 20 7a 65 72 6f 20 |we reach a zero | 00001960 69 6e 20 74 68 65 20 6c 69 73 74 20 66 69 72 73 |in the list firs| 00001970 74 20 74 68 69 73 0d 6d 65 61 6e 73 20 74 68 65 |t this.means the| 00001980 20 63 68 61 72 61 63 74 65 72 20 69 73 20 6e 6f | character is no| 00001990 74 20 76 61 6c 69 64 20 61 6e 64 20 77 65 20 62 |t valid and we b| 000019a0 72 61 6e 63 68 20 74 6f 20 27 69 6e 76 61 6c 69 |ranch to 'invali| 000019b0 64 27 2e 0d 0d 4e 6f 74 65 20 74 68 61 74 20 61 |d'...Note that a| 000019c0 66 74 65 72 20 27 69 6e 76 61 6c 69 64 27 20 77 |fter 'invalid' w| 000019d0 65 20 68 61 76 65 20 74 6f 20 72 65 62 61 6c 61 |e have to rebala| 000019e0 6e 63 65 20 74 68 65 20 73 74 61 63 6b 0d 77 69 |nce the stack.wi| 000019f0 74 68 20 61 20 50 4c 41 20 62 65 63 61 75 73 65 |th a PLA because| 00001a00 20 77 65 20 64 69 64 6e 27 74 20 72 65 61 63 68 | we didn't reach| 00001a10 20 74 68 65 20 6f 6e 65 20 61 74 20 6c 69 6e 65 | the one at line| 00001a20 20 39 32 30 2e 20 0d 5a 65 72 6f 20 69 73 20 70 | 920. .Zero is p| 00001a30 75 74 20 69 6e 20 74 68 65 20 61 63 63 75 6d 75 |ut in the accumu| 00001a40 6c 61 74 6f 72 20 61 6e 64 20 74 68 65 20 73 75 |lator and the su| 00001a50 62 72 6f 75 74 69 6e 65 20 72 65 74 75 72 6e 73 |broutine returns| 00001a60 2e 20 0d 46 6f 72 20 61 20 76 61 6c 69 64 20 63 |. .For a valid c| 00001a70 68 61 72 61 63 74 65 72 20 74 68 65 20 73 75 62 |haracter the sub| 00001a80 72 6f 75 74 69 6e 65 20 72 65 74 75 72 6e 73 20 |routine returns | 00001a90 69 6d 6d 65 64 69 61 74 65 6c 79 2e 0d 0d 54 68 |immediately...Th| 00001aa0 65 20 6c 69 73 74 20 6f 66 20 76 61 6c 69 64 20 |e list of valid | 00001ab0 63 68 61 72 61 63 74 65 72 73 2c 20 61 74 20 6c |characters, at l| 00001ac0 69 6e 65 20 31 30 37 30 2c 20 69 73 20 74 65 72 |ine 1070, is ter| 00001ad0 6d 69 6e 61 74 65 64 20 62 79 0d 61 20 7a 65 72 |minated by.a zer| 00001ae0 6f 20 62 79 74 65 2e 20 20 49 6e 20 74 68 69 73 |o byte. In this| 00001af0 20 65 78 61 6d 70 6c 65 20 69 74 20 63 6f 6e 74 | example it cont| 00001b00 61 69 6e 73 20 61 6c 6c 20 74 68 65 20 63 68 61 |ains all the cha| 00001b10 72 61 63 74 65 72 73 0d 75 73 65 64 20 69 6e 20 |racters.used in | 00001b20 64 65 63 69 6d 61 6c 20 69 6e 74 65 67 65 72 20 |decimal integer | 00001b30 61 72 69 74 68 6d 65 74 69 63 20 62 75 74 20 79 |arithmetic but y| 00001b40 6f 75 20 63 6f 75 6c 64 20 69 6e 63 6c 75 64 65 |ou could include| 00001b50 20 61 0d 64 65 63 69 6d 61 6c 20 70 6f 69 6e 74 | a.decimal point| 00001b60 20 66 6f 72 20 65 78 61 6d 70 6c 65 2c 20 6f 72 | for example, or| 00001b70 20 26 41 42 43 44 45 46 20 66 6f 72 20 68 65 78 | &ABCDEF for hex| 00001b80 61 64 65 63 69 6d 61 6c 0d 61 72 69 74 68 6d 65 |adecimal.arithme| 00001b90 74 69 63 2e 0d 0d 54 68 65 20 62 75 66 66 65 72 |tic...The buffer| 00001ba0 20 69 73 20 61 63 74 75 61 6c 6c 79 20 6f 6e 65 | is actually one| 00001bb0 20 6c 61 72 67 65 72 20 74 68 61 6e 20 74 68 65 | larger than the| 00001bc0 20 62 75 66 66 65 72 20 73 69 7a 65 20 69 73 0d | buffer size is.| 00001bd0 73 70 65 63 69 66 69 65 64 2c 20 74 68 69 73 20 |specified, this | 00001be0 69 73 20 74 6f 20 6c 65 61 76 65 20 72 6f 6f 6d |is to leave room| 00001bf0 20 66 6f 72 20 74 68 65 20 66 69 6e 61 6c 20 63 | for the final c| 00001c00 61 72 72 69 61 67 65 0d 72 65 74 75 72 6e 20 63 |arriage.return c| 00001c10 68 61 72 61 63 74 65 72 2e 20 20 54 68 69 73 20 |haracter. This | 00001c20 69 73 20 74 68 65 20 66 69 72 73 74 20 74 69 6d |is the first tim| 00001c30 65 20 77 65 27 76 65 20 75 73 65 64 20 74 68 65 |e we've used the| 00001c40 0d 46 4e 45 51 55 4d 20 66 75 6e 63 74 69 6f 6e |.FNEQUM function| 00001c50 20 74 6f 20 73 65 74 20 61 73 69 64 65 20 73 6f | to set aside so| 00001c60 6d 65 20 6d 65 6d 6f 72 79 2e 20 20 49 27 76 65 |me memory. I've| 00001c70 20 70 75 74 20 26 46 46 2f 32 35 35 0d 69 6e 20 | put &FF/255.in | 00001c80 74 68 65 20 62 75 66 66 65 72 20 74 6f 20 73 74 |the buffer to st| 00001c90 61 72 74 20 77 69 74 68 20 62 75 74 20 69 74 20 |art with but it | 00001ca0 63 6f 75 6c 64 20 63 6f 6e 74 61 69 6e 20 61 6e |could contain an| 00001cb0 79 74 68 69 6e 67 0d 69 6e 69 74 69 61 6c 6c 79 |ything.initially| 00001cc0 2e 0d 0d 41 66 74 65 72 20 74 68 65 20 61 73 73 |...After the ass| 00001cd0 65 6d 62 6c 65 72 20 69 73 20 73 6f 6d 65 20 42 |embler is some B| 00001ce0 41 53 49 43 20 77 68 69 63 68 20 72 65 70 65 61 |ASIC which repea| 00001cf0 74 65 64 6c 79 20 63 61 6c 6c 73 20 74 68 65 0d |tedly calls the.| 00001d00 72 6f 75 74 69 6e 65 20 61 6e 64 20 70 72 69 6e |routine and prin| 00001d10 74 73 20 6f 75 74 20 74 68 65 20 63 6f 6e 74 65 |ts out the conte| 00001d20 6e 74 73 20 6f 66 20 74 68 65 20 62 75 66 66 65 |nts of the buffe| 00001d30 72 2c 20 73 6f 20 79 6f 75 0d 73 68 6f 75 6c 64 |r, so you.should| 00001d40 20 73 65 65 20 74 68 61 74 20 77 68 61 74 65 76 | see that whatev| 00001d50 65 72 20 79 6f 75 20 69 6e 70 75 74 20 69 73 20 |er you input is | 00001d60 70 75 74 20 69 6e 74 6f 20 74 68 65 20 62 75 66 |put into the buf| 00001d70 66 65 72 2e 0d 0d 49 6e 20 74 68 65 20 6e 65 78 |fer...In the nex| 00001d80 74 20 6d 6f 64 75 6c 65 20 77 65 20 77 69 6c 6c |t module we will| 00001d90 20 75 73 65 20 74 68 69 73 20 72 6f 75 74 69 6e | use this routin| 00001da0 65 20 61 73 20 74 68 65 20 62 61 73 69 73 20 6f |e as the basis o| 00001db0 66 0d 61 6e 20 41 53 43 49 49 20 74 6f 20 62 69 |f.an ASCII to bi| 00001dc0 6e 61 72 79 20 63 6f 6e 76 65 72 73 69 6f 6e 20 |nary conversion | 00001dd0 77 68 69 63 68 20 77 69 6c 6c 20 69 6e 74 72 6f |which will intro| 00001de0 64 75 63 65 20 61 20 75 73 65 20 6f 66 0d 73 69 |duce a use of.si| 00001df0 6d 70 6c 65 20 6d 75 6c 74 69 70 6c 69 63 61 74 |mple multiplicat| 00001e00 69 6f 6e 3b 20 61 6e 64 20 69 6e 20 74 68 65 20 |ion; and in the | 00001e10 6d 6f 64 75 6c 65 20 61 66 74 65 72 20 74 68 61 |module after tha| 00001e20 74 20 49 20 77 69 6c 6c 0d 67 69 76 65 20 79 6f |t I will.give yo| 00001e30 75 20 61 20 67 65 6e 65 72 61 6c 20 69 6e 74 65 |u a general inte| 00001e40 67 65 72 20 6d 75 6c 74 69 70 6c 69 63 61 74 69 |ger multiplicati| 00001e50 6f 6e 20 72 6f 75 74 69 6e 65 2e 0d |on routine..| 00001e5c