Home » CEEFAX disks » telesoftware6.adl » 22-04-88/T\OSB23
22-04-88/T\OSB23
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 » telesoftware6.adl |
Filename: | 22-04-88/T\OSB23 |
Read OK: | ✔ |
File size: | 2280 bytes |
Load address: | 0000 |
Exec address: | FFFFFFFF |
File contents
OSBITS - An Exploration of the BBC Micro at Machine Level By Programmer .......................................................... Part 23: Floating Point Arithmetic II In this module we don't have much in the way of text, but we have another program using floating point machine code arithmetic. This time, having achieved addition and subtraction in our experimentation, we go on to multiplication and division. The general rule for multiplication is that you multiply the mantissae and add the exponents while for division you divide the mantissae and subtract the exponents. Thus, if A and B are the mantissae and C and D are exponents (such that, for example, 12.34 could be represented as 1.234e1 where 1.234 is the mantissa and 1 is the exponent - the power of 10, in this case, needed to multiply the number to its actual value) we have the following: AeC * BeD = (A*B)e(C+D) AeC / DeD = (A/B)e(C-D) The program in this module works on this basis but it does throw up a few problems. I'll go through the program section by section and briefly discuss the problems I came across in writing it. As with the last module, this program is divided into subroutines that carry out the main sections of the work. One significant difference is that, this time, I have used CALL with parameters as a means of getting the floating point numbers into the program. This means that the code is only assembled once in each RUN with a REPEAT UNTIL FALSE loop letting you enter new values and seeing the results each time. This is an alternative to using the FNEQUF pseudo-opt in the assembler. You may like to modify the last module to work in this way. Having been transferred, using information in the parameter block at &600 that BASIC sets up for CALL with parameters, the numbers input are stored securely, since they will be needed twice, once for multiplication and once for division. Note that the initial transfer needs some zero page workspace because of the indirect addressing used. The block at &600 looks like this: &600 1 byte - number of parameters &601 2 bytes - parameter address &603 1 byte - parameter type &604 2 bytes - next parameter address .... and so on The parameter type for a floating point variable is 5. Others are 0 for a byte (i.e. an ?X), 4 for an integer, 128 for a $X string in memory (terminated by a CR) and 129 for a string variable (X$). In the last case (see module 7) the parameter address is a pointer to a string information block. The numbers are then transferred into the workspaces for the calculation by a subroutine 'transfer_in'. The multiplication is carried out and then the result is transferred out into 'result_mult'. This process is repeated for the division. At the end the results of the machine code calculations are compared with the result using BBC BASIC. I will admit here and now that my routines are a little innacurate but I will also admit to this being of an experimental nature and I was trying for clarity. As we go down the listing of the assembly program the next thing we meet is a block of workspace. I have increased the workspace for the calculations to seven bytes from five because I need seven for division. I have also triple named 'fpws_1' and 'fpws_2' for their multiplication and division roles. This is a technique you can use if you want to be clear about the function of a piece of memory although its use changes during the program. There is no penalty for multi-naming, apart from making the assembly source code a bit longer. Your final program code, which does not use the labels, is not affected. So let's look at the multiplication first. To avoid problems I have trapped zeros at the start of the multiplying routines. Obviously a zero entered as either number will give a zero result when they are multiplied together. There is a subroutine at 'make_zero' which makes all five bytes of 'fpws_1' zero. Note that if you branch or jump to a sobroutine, rather than JSRing to it, you will automatically RTS at the end of it, in this case that takes us out of the 'fp_mult' subroutine completely. If neither number is zero we move on. The sign bit is transferred to another byte and the top bit of the mantissa corrected exactly as in the last module. The multiplying denormalisation routine rotates each mantissa right by two bytes. With a four byte mantissa this effectively gives us two two byte numbers which, when multiplied together, produce a four byte number. This four byte number then fills the mantissa work space again. You might think, as I originally did, that when rotating the mantissae you should alter the exponents to compensate. This produces incorrect results and, after much thinking and drawing of diagrams I came to the following conclusion. We are do not have to change the exponents because the mantissae are, in fact, just less that 1 in size. Now if you multiply 0.9 by 0.9 you get 0.81 and multiplying two mantissae, each with its top bit set, is just like this. We get a similar situation with division. 'mult_denormalise' also calculates the initial new exponent. Remember that BBC BASIC adds &80 to the exponents in its floating point format. If on adding the exponents we change the 2's complement sign of the result then the result ha overflowed and ismout of range. This might happen if, say, we added 120 to 20. 140 is actually a negative number in 2's complement and so we have wrapped around the byte to give an incorrect result. We can trap this by chacking the overflow flag. This flag will detect an anomolous overflow and so we can use it to branch to an error routine. With multiplication, a result that has overflowed too much negatively means that the number is in fact too small for us to represent it. This is not treated as an error, but instead means that we must set the result to zero. For a value that is too big I have used Error 20, but given it slightly different messages to BASIC as you can see in the listing. I multiplied the two numbers using a modified version of the multi-byte mutliplication routine from module 13. The main difference is that the floating point mantissa is stored back to front compared to the integers, with the least significant byte in the lowest memory location. Note that, as the partial product workspace does not use the exponent, it is only four bytes long not five. After multiplying we renormalise the mantissa by rotating it left until the top bit is set. By converting to two two byte numbers we cannot have an overflow here so we only have to check for a number that is too small. A zero result is trapped here because it would otherwise send the routine into an endless loop. Finally the sign bit is replaced. The sign business is a great deal easier with multiplcation and division that it was with addition and subtraction. If you EOR the two sign bits together you get the result; simple as that. Where division is concerned much of the procedure is the same. Here a zero as the second number is a fatal error since we cannot divide by zero. A zero for first number just leads to a zero result. Denormalisation for division, in my implimentation, involves rotating the divisor right by two bytes. This effectively means that we have a four byte number divided by a two byte one, although the two byte one has two other bytes beyone the 'binary point' and the division routine therefore works over 48 bits. In calculating the initial exponent of the result I found that to compensate for the rotation, and because both our numbers were just under 1 in size again, I had to increase the size of the exponent by 32 (&20) which is done after the second exponent has been subtracted from the first. [I wish I understood these 'fudge' factors more clearly, then I could explain them more clearly.] Just as the exponents could overflow during multiplication, so they can during division, and that is trapped at the end of the 'div_denormalise' routine. The division subroutine is a straightforward modification of the multi-byte integer division routine in module 15. In this case we calculate over 48 bits instead of 32, and the workspace is back to front because of the way the floating point mantissae are stored. Renormalisation and fixing the sign bit operate exactly as with multiplication, using the same subroutines. These floating point routines are by no means simple. To make them more accurate would make them more obscure, but the principles behind them are straightforward enough. Maybe you'd like to try making that Mandelbrot program from module 21 work using floating point? While you're thinking about that I will move on to sideways ROMs, a subject very specific to the BBC Micro, in the next module.
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 0d 0d 0d 50 61 72 74 20 32 33 3a 20 |.......Part 23: | 00000090 46 6c 6f 61 74 69 6e 67 20 50 6f 69 6e 74 20 41 |Floating Point A| 000000a0 72 69 74 68 6d 65 74 69 63 20 49 49 0d 0d 0d 49 |rithmetic II...I| 000000b0 6e 20 74 68 69 73 20 6d 6f 64 75 6c 65 20 77 65 |n this module we| 000000c0 20 64 6f 6e 27 74 20 68 61 76 65 20 6d 75 63 68 | don't have much| 000000d0 20 69 6e 20 74 68 65 20 77 61 79 20 6f 66 20 74 | in the way of t| 000000e0 65 78 74 2c 20 62 75 74 20 77 65 0d 68 61 76 65 |ext, but we.have| 000000f0 20 61 6e 6f 74 68 65 72 20 70 72 6f 67 72 61 6d | another program| 00000100 20 75 73 69 6e 67 20 66 6c 6f 61 74 69 6e 67 20 | using floating | 00000110 70 6f 69 6e 74 20 6d 61 63 68 69 6e 65 20 63 6f |point machine co| 00000120 64 65 0d 61 72 69 74 68 6d 65 74 69 63 2e 20 20 |de.arithmetic. | 00000130 54 68 69 73 20 74 69 6d 65 2c 20 68 61 76 69 6e |This time, havin| 00000140 67 20 61 63 68 69 65 76 65 64 20 61 64 64 69 74 |g achieved addit| 00000150 69 6f 6e 20 61 6e 64 0d 73 75 62 74 72 61 63 74 |ion and.subtract| 00000160 69 6f 6e 20 69 6e 20 6f 75 72 20 65 78 70 65 72 |ion in our exper| 00000170 69 6d 65 6e 74 61 74 69 6f 6e 2c 20 77 65 20 67 |imentation, we g| 00000180 6f 20 6f 6e 20 74 6f 0d 6d 75 6c 74 69 70 6c 69 |o on to.multipli| 00000190 63 61 74 69 6f 6e 20 61 6e 64 20 64 69 76 69 73 |cation and divis| 000001a0 69 6f 6e 2e 0d 0d 54 68 65 20 67 65 6e 65 72 61 |ion...The genera| 000001b0 6c 20 72 75 6c 65 20 66 6f 72 20 6d 75 6c 74 69 |l rule for multi| 000001c0 70 6c 69 63 61 74 69 6f 6e 20 69 73 20 74 68 61 |plication is tha| 000001d0 74 20 79 6f 75 20 6d 75 6c 74 69 70 6c 79 20 74 |t you multiply t| 000001e0 68 65 0d 6d 61 6e 74 69 73 73 61 65 20 61 6e 64 |he.mantissae and| 000001f0 20 61 64 64 20 74 68 65 20 65 78 70 6f 6e 65 6e | add the exponen| 00000200 74 73 20 77 68 69 6c 65 20 66 6f 72 20 64 69 76 |ts while for div| 00000210 69 73 69 6f 6e 20 79 6f 75 0d 64 69 76 69 64 65 |ision you.divide| 00000220 20 74 68 65 20 6d 61 6e 74 69 73 73 61 65 20 61 | the mantissae a| 00000230 6e 64 20 73 75 62 74 72 61 63 74 20 74 68 65 20 |nd subtract the | 00000240 65 78 70 6f 6e 65 6e 74 73 2e 0d 0d 54 68 75 73 |exponents...Thus| 00000250 2c 20 69 66 20 41 20 61 6e 64 20 42 20 61 72 65 |, if A and B are| 00000260 20 74 68 65 20 6d 61 6e 74 69 73 73 61 65 20 61 | the mantissae a| 00000270 6e 64 20 43 20 61 6e 64 20 44 20 61 72 65 20 65 |nd C and D are e| 00000280 78 70 6f 6e 65 6e 74 73 0d 28 73 75 63 68 20 74 |xponents.(such t| 00000290 68 61 74 2c 20 66 6f 72 20 65 78 61 6d 70 6c 65 |hat, for example| 000002a0 2c 20 31 32 2e 33 34 20 63 6f 75 6c 64 20 62 65 |, 12.34 could be| 000002b0 20 72 65 70 72 65 73 65 6e 74 65 64 20 61 73 0d | represented as.| 000002c0 31 2e 32 33 34 65 31 20 77 68 65 72 65 20 31 2e |1.234e1 where 1.| 000002d0 32 33 34 20 69 73 20 74 68 65 20 6d 61 6e 74 69 |234 is the manti| 000002e0 73 73 61 20 61 6e 64 20 31 20 69 73 20 74 68 65 |ssa and 1 is the| 000002f0 20 65 78 70 6f 6e 65 6e 74 20 2d 0d 74 68 65 20 | exponent -.the | 00000300 70 6f 77 65 72 20 6f 66 20 31 30 2c 20 69 6e 20 |power of 10, in | 00000310 74 68 69 73 20 63 61 73 65 2c 20 6e 65 65 64 65 |this case, neede| 00000320 64 20 74 6f 20 6d 75 6c 74 69 70 6c 79 20 74 68 |d to multiply th| 00000330 65 20 6e 75 6d 62 65 72 0d 74 6f 20 69 74 73 20 |e number.to its | 00000340 61 63 74 75 61 6c 20 76 61 6c 75 65 29 20 77 65 |actual value) we| 00000350 20 68 61 76 65 20 74 68 65 20 66 6f 6c 6c 6f 77 | have the follow| 00000360 69 6e 67 3a 0d 0d 20 20 20 20 20 20 20 20 20 20 |ing:.. | 00000370 20 20 20 20 41 65 43 20 2a 20 42 65 44 20 3d 20 | AeC * BeD = | 00000380 28 41 2a 42 29 65 28 43 2b 44 29 0d 20 20 20 20 |(A*B)e(C+D). | 00000390 20 20 20 20 20 20 20 20 20 20 41 65 43 20 2f 20 | AeC / | 000003a0 44 65 44 20 3d 20 28 41 2f 42 29 65 28 43 2d 44 |DeD = (A/B)e(C-D| 000003b0 29 0d 0d 54 68 65 20 70 72 6f 67 72 61 6d 20 69 |)..The program i| 000003c0 6e 20 74 68 69 73 20 6d 6f 64 75 6c 65 20 77 6f |n this module wo| 000003d0 72 6b 73 20 6f 6e 20 74 68 69 73 20 62 61 73 69 |rks on this basi| 000003e0 73 20 62 75 74 20 69 74 20 64 6f 65 73 0d 74 68 |s but it does.th| 000003f0 72 6f 77 20 75 70 20 61 20 66 65 77 20 70 72 6f |row up a few pro| 00000400 62 6c 65 6d 73 2e 20 20 49 27 6c 6c 20 67 6f 20 |blems. I'll go | 00000410 74 68 72 6f 75 67 68 20 74 68 65 20 70 72 6f 67 |through the prog| 00000420 72 61 6d 0d 73 65 63 74 69 6f 6e 20 62 79 20 73 |ram.section by s| 00000430 65 63 74 69 6f 6e 20 61 6e 64 20 62 72 69 65 66 |ection and brief| 00000440 6c 79 20 64 69 73 63 75 73 73 20 74 68 65 20 70 |ly discuss the p| 00000450 72 6f 62 6c 65 6d 73 20 49 20 63 61 6d 65 0d 61 |roblems I came.a| 00000460 63 72 6f 73 73 20 69 6e 20 77 72 69 74 69 6e 67 |cross in writing| 00000470 20 69 74 2e 0d 0d 41 73 20 77 69 74 68 20 74 68 | it...As with th| 00000480 65 20 6c 61 73 74 20 6d 6f 64 75 6c 65 2c 20 74 |e last module, t| 00000490 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 |his program is d| 000004a0 69 76 69 64 65 64 20 69 6e 74 6f 0d 73 75 62 72 |ivided into.subr| 000004b0 6f 75 74 69 6e 65 73 20 74 68 61 74 20 63 61 72 |outines that car| 000004c0 72 79 20 6f 75 74 20 74 68 65 20 6d 61 69 6e 20 |ry out the main | 000004d0 73 65 63 74 69 6f 6e 73 20 6f 66 20 74 68 65 20 |sections of the | 000004e0 77 6f 72 6b 2e 20 0d 4f 6e 65 20 73 69 67 6e 69 |work. .One signi| 000004f0 66 69 63 61 6e 74 20 64 69 66 66 65 72 65 6e 63 |ficant differenc| 00000500 65 20 69 73 20 74 68 61 74 2c 20 74 68 69 73 20 |e is that, this | 00000510 74 69 6d 65 2c 20 49 20 68 61 76 65 20 75 73 65 |time, I have use| 00000520 64 0d 43 41 4c 4c 20 77 69 74 68 20 70 61 72 61 |d.CALL with para| 00000530 6d 65 74 65 72 73 20 61 73 20 61 20 6d 65 61 6e |meters as a mean| 00000540 73 20 6f 66 20 67 65 74 74 69 6e 67 20 74 68 65 |s of getting the| 00000550 20 66 6c 6f 61 74 69 6e 67 0d 70 6f 69 6e 74 20 | floating.point | 00000560 6e 75 6d 62 65 72 73 20 69 6e 74 6f 20 74 68 65 |numbers into the| 00000570 20 70 72 6f 67 72 61 6d 2e 20 20 54 68 69 73 20 | program. This | 00000580 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 20 63 |means that the c| 00000590 6f 64 65 20 69 73 0d 6f 6e 6c 79 20 61 73 73 65 |ode is.only asse| 000005a0 6d 62 6c 65 64 20 6f 6e 63 65 20 69 6e 20 65 61 |mbled once in ea| 000005b0 63 68 20 52 55 4e 20 77 69 74 68 20 61 20 52 45 |ch RUN with a RE| 000005c0 50 45 41 54 20 55 4e 54 49 4c 20 46 41 4c 53 45 |PEAT UNTIL FALSE| 000005d0 0d 6c 6f 6f 70 20 6c 65 74 74 69 6e 67 20 79 6f |.loop letting yo| 000005e0 75 20 65 6e 74 65 72 20 6e 65 77 20 76 61 6c 75 |u enter new valu| 000005f0 65 73 20 61 6e 64 20 73 65 65 69 6e 67 20 74 68 |es and seeing th| 00000600 65 20 72 65 73 75 6c 74 73 0d 65 61 63 68 20 74 |e results.each t| 00000610 69 6d 65 2e 20 20 54 68 69 73 20 69 73 20 61 6e |ime. This is an| 00000620 20 61 6c 74 65 72 6e 61 74 69 76 65 20 74 6f 20 | alternative to | 00000630 75 73 69 6e 67 20 74 68 65 20 46 4e 45 51 55 46 |using the FNEQUF| 00000640 0d 70 73 65 75 64 6f 2d 6f 70 74 20 69 6e 20 74 |.pseudo-opt in t| 00000650 68 65 20 61 73 73 65 6d 62 6c 65 72 2e 20 20 59 |he assembler. Y| 00000660 6f 75 20 6d 61 79 20 6c 69 6b 65 20 74 6f 20 6d |ou may like to m| 00000670 6f 64 69 66 79 20 74 68 65 0d 6c 61 73 74 20 6d |odify the.last m| 00000680 6f 64 75 6c 65 20 74 6f 20 77 6f 72 6b 20 69 6e |odule to work in| 00000690 20 74 68 69 73 20 77 61 79 2e 0d 0d 48 61 76 69 | this way...Havi| 000006a0 6e 67 20 62 65 65 6e 20 74 72 61 6e 73 66 65 72 |ng been transfer| 000006b0 72 65 64 2c 20 75 73 69 6e 67 20 69 6e 66 6f 72 |red, using infor| 000006c0 6d 61 74 69 6f 6e 20 69 6e 20 74 68 65 20 70 61 |mation in the pa| 000006d0 72 61 6d 65 74 65 72 0d 62 6c 6f 63 6b 20 61 74 |rameter.block at| 000006e0 20 26 36 30 30 20 74 68 61 74 20 42 41 53 49 43 | &600 that BASIC| 000006f0 20 73 65 74 73 20 75 70 20 66 6f 72 20 43 41 4c | sets up for CAL| 00000700 4c 20 77 69 74 68 20 70 61 72 61 6d 65 74 65 72 |L with parameter| 00000710 73 2c 0d 74 68 65 20 6e 75 6d 62 65 72 73 20 69 |s,.the numbers i| 00000720 6e 70 75 74 20 61 72 65 20 73 74 6f 72 65 64 20 |nput are stored | 00000730 73 65 63 75 72 65 6c 79 2c 20 73 69 6e 63 65 20 |securely, since | 00000740 74 68 65 79 20 77 69 6c 6c 20 62 65 0d 6e 65 65 |they will be.nee| 00000750 64 65 64 20 74 77 69 63 65 2c 20 6f 6e 63 65 20 |ded twice, once | 00000760 66 6f 72 20 6d 75 6c 74 69 70 6c 69 63 61 74 69 |for multiplicati| 00000770 6f 6e 20 61 6e 64 20 6f 6e 63 65 20 66 6f 72 20 |on and once for | 00000780 64 69 76 69 73 69 6f 6e 2e 20 0d 4e 6f 74 65 20 |division. .Note | 00000790 74 68 61 74 20 74 68 65 20 69 6e 69 74 69 61 6c |that the initial| 000007a0 20 74 72 61 6e 73 66 65 72 20 6e 65 65 64 73 20 | transfer needs | 000007b0 73 6f 6d 65 20 7a 65 72 6f 20 70 61 67 65 0d 77 |some zero page.w| 000007c0 6f 72 6b 73 70 61 63 65 20 62 65 63 61 75 73 65 |orkspace because| 000007d0 20 6f 66 20 74 68 65 20 69 6e 64 69 72 65 63 74 | of the indirect| 000007e0 20 61 64 64 72 65 73 73 69 6e 67 20 75 73 65 64 | addressing used| 000007f0 2e 20 20 54 68 65 0d 62 6c 6f 63 6b 20 61 74 20 |. The.block at | 00000800 26 36 30 30 20 6c 6f 6f 6b 73 20 6c 69 6b 65 20 |&600 looks like | 00000810 74 68 69 73 3a 0d 0d 20 20 20 20 26 36 30 30 20 |this:.. &600 | 00000820 20 20 20 31 20 62 79 74 65 20 2d 20 6e 75 6d 62 | 1 byte - numb| 00000830 65 72 20 6f 66 20 70 61 72 61 6d 65 74 65 72 73 |er of parameters| 00000840 0d 20 20 20 20 26 36 30 31 20 20 20 20 32 20 62 |. &601 2 b| 00000850 79 74 65 73 20 2d 20 70 61 72 61 6d 65 74 65 72 |ytes - parameter| 00000860 20 61 64 64 72 65 73 73 0d 20 20 20 20 26 36 30 | address. &60| 00000870 33 20 20 20 20 31 20 62 79 74 65 20 2d 20 70 61 |3 1 byte - pa| 00000880 72 61 6d 65 74 65 72 20 74 79 70 65 0d 20 20 20 |rameter type. | 00000890 20 26 36 30 34 20 20 20 20 32 20 62 79 74 65 73 | &604 2 bytes| 000008a0 20 2d 20 6e 65 78 74 20 70 61 72 61 6d 65 74 65 | - next paramete| 000008b0 72 20 61 64 64 72 65 73 73 20 2e 2e 2e 2e 20 61 |r address .... a| 000008c0 6e 64 20 73 6f 20 6f 6e 0d 0d 54 68 65 20 70 61 |nd so on..The pa| 000008d0 72 61 6d 65 74 65 72 20 74 79 70 65 20 66 6f 72 |rameter type for| 000008e0 20 61 20 66 6c 6f 61 74 69 6e 67 20 70 6f 69 6e | a floating poin| 000008f0 74 20 76 61 72 69 61 62 6c 65 20 69 73 20 35 2e |t variable is 5.| 00000900 20 0d 4f 74 68 65 72 73 20 61 72 65 20 30 20 66 | .Others are 0 f| 00000910 6f 72 20 61 20 62 79 74 65 20 28 69 2e 65 2e 20 |or a byte (i.e. | 00000920 61 6e 20 3f 58 29 2c 20 34 20 66 6f 72 20 61 6e |an ?X), 4 for an| 00000930 20 69 6e 74 65 67 65 72 2c 20 31 32 38 0d 66 6f | integer, 128.fo| 00000940 72 20 61 20 24 58 20 73 74 72 69 6e 67 20 69 6e |r a $X string in| 00000950 20 6d 65 6d 6f 72 79 20 28 74 65 72 6d 69 6e 61 | memory (termina| 00000960 74 65 64 20 62 79 20 61 20 43 52 29 20 61 6e 64 |ted by a CR) and| 00000970 20 31 32 39 20 66 6f 72 20 61 0d 73 74 72 69 6e | 129 for a.strin| 00000980 67 20 76 61 72 69 61 62 6c 65 20 28 58 24 29 2e |g variable (X$).| 00000990 20 20 49 6e 20 74 68 65 20 6c 61 73 74 20 63 61 | In the last ca| 000009a0 73 65 20 28 73 65 65 20 6d 6f 64 75 6c 65 20 37 |se (see module 7| 000009b0 29 20 74 68 65 0d 70 61 72 61 6d 65 74 65 72 20 |) the.parameter | 000009c0 61 64 64 72 65 73 73 20 69 73 20 61 20 70 6f 69 |address is a poi| 000009d0 6e 74 65 72 20 74 6f 20 61 20 73 74 72 69 6e 67 |nter to a string| 000009e0 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 0d 62 6c 6f | information.blo| 000009f0 63 6b 2e 0d 0d 54 68 65 20 6e 75 6d 62 65 72 73 |ck...The numbers| 00000a00 20 61 72 65 20 74 68 65 6e 20 74 72 61 6e 73 66 | are then transf| 00000a10 65 72 72 65 64 20 69 6e 74 6f 20 74 68 65 20 77 |erred into the w| 00000a20 6f 72 6b 73 70 61 63 65 73 20 66 6f 72 20 74 68 |orkspaces for th| 00000a30 65 0d 63 61 6c 63 75 6c 61 74 69 6f 6e 20 62 79 |e.calculation by| 00000a40 20 61 20 73 75 62 72 6f 75 74 69 6e 65 20 27 74 | a subroutine 't| 00000a50 72 61 6e 73 66 65 72 5f 69 6e 27 2e 20 20 54 68 |ransfer_in'. Th| 00000a60 65 0d 6d 75 6c 74 69 70 6c 69 63 61 74 69 6f 6e |e.multiplication| 00000a70 20 69 73 20 63 61 72 72 69 65 64 20 6f 75 74 20 | is carried out | 00000a80 61 6e 64 20 74 68 65 6e 20 74 68 65 20 72 65 73 |and then the res| 00000a90 75 6c 74 20 69 73 0d 74 72 61 6e 73 66 65 72 72 |ult is.transferr| 00000aa0 65 64 20 6f 75 74 20 69 6e 74 6f 20 27 72 65 73 |ed out into 'res| 00000ab0 75 6c 74 5f 6d 75 6c 74 27 2e 20 20 54 68 69 73 |ult_mult'. This| 00000ac0 20 70 72 6f 63 65 73 73 20 69 73 0d 72 65 70 65 | process is.repe| 00000ad0 61 74 65 64 20 66 6f 72 20 74 68 65 20 64 69 76 |ated for the div| 00000ae0 69 73 69 6f 6e 2e 20 20 41 74 20 74 68 65 20 65 |ision. At the e| 00000af0 6e 64 20 74 68 65 20 72 65 73 75 6c 74 73 20 6f |nd the results o| 00000b00 66 20 74 68 65 0d 6d 61 63 68 69 6e 65 20 63 6f |f the.machine co| 00000b10 64 65 20 63 61 6c 63 75 6c 61 74 69 6f 6e 73 20 |de calculations | 00000b20 61 72 65 20 63 6f 6d 70 61 72 65 64 20 77 69 74 |are compared wit| 00000b30 68 20 74 68 65 20 72 65 73 75 6c 74 20 75 73 69 |h the result usi| 00000b40 6e 67 0d 42 42 43 20 42 41 53 49 43 2e 20 20 49 |ng.BBC BASIC. I| 00000b50 20 77 69 6c 6c 20 61 64 6d 69 74 20 68 65 72 65 | will admit here| 00000b60 20 61 6e 64 20 6e 6f 77 20 74 68 61 74 20 6d 79 | and now that my| 00000b70 20 72 6f 75 74 69 6e 65 73 20 61 72 65 20 61 0d | routines are a.| 00000b80 6c 69 74 74 6c 65 20 69 6e 6e 61 63 75 72 61 74 |little innacurat| 00000b90 65 20 62 75 74 20 49 20 77 69 6c 6c 20 61 6c 73 |e but I will als| 00000ba0 6f 20 61 64 6d 69 74 20 74 6f 20 74 68 69 73 20 |o admit to this | 00000bb0 62 65 69 6e 67 20 6f 66 20 61 6e 0d 65 78 70 65 |being of an.expe| 00000bc0 72 69 6d 65 6e 74 61 6c 20 6e 61 74 75 72 65 20 |rimental nature | 00000bd0 61 6e 64 20 49 20 77 61 73 20 74 72 79 69 6e 67 |and I was trying| 00000be0 20 66 6f 72 20 63 6c 61 72 69 74 79 2e 0d 0d 41 | for clarity...A| 00000bf0 73 20 77 65 20 67 6f 20 64 6f 77 6e 20 74 68 65 |s we go down the| 00000c00 20 6c 69 73 74 69 6e 67 20 6f 66 20 74 68 65 20 | listing of the | 00000c10 61 73 73 65 6d 62 6c 79 20 70 72 6f 67 72 61 6d |assembly program| 00000c20 20 74 68 65 20 6e 65 78 74 0d 74 68 69 6e 67 20 | the next.thing | 00000c30 77 65 20 6d 65 65 74 20 69 73 20 61 20 62 6c 6f |we meet is a blo| 00000c40 63 6b 20 6f 66 20 77 6f 72 6b 73 70 61 63 65 2e |ck of workspace.| 00000c50 20 20 49 20 68 61 76 65 20 69 6e 63 72 65 61 73 | I have increas| 00000c60 65 64 20 74 68 65 0d 77 6f 72 6b 73 70 61 63 65 |ed the.workspace| 00000c70 20 66 6f 72 20 74 68 65 20 63 61 6c 63 75 6c 61 | for the calcula| 00000c80 74 69 6f 6e 73 20 74 6f 20 73 65 76 65 6e 20 62 |tions to seven b| 00000c90 79 74 65 73 20 66 72 6f 6d 20 66 69 76 65 0d 62 |ytes from five.b| 00000ca0 65 63 61 75 73 65 20 49 20 6e 65 65 64 20 73 65 |ecause I need se| 00000cb0 76 65 6e 20 66 6f 72 20 64 69 76 69 73 69 6f 6e |ven for division| 00000cc0 2e 20 20 49 20 68 61 76 65 20 61 6c 73 6f 20 74 |. I have also t| 00000cd0 72 69 70 6c 65 20 6e 61 6d 65 64 0d 27 66 70 77 |riple named.'fpw| 00000ce0 73 5f 31 27 20 61 6e 64 20 27 66 70 77 73 5f 32 |s_1' and 'fpws_2| 00000cf0 27 20 66 6f 72 20 74 68 65 69 72 20 6d 75 6c 74 |' for their mult| 00000d00 69 70 6c 69 63 61 74 69 6f 6e 20 61 6e 64 20 64 |iplication and d| 00000d10 69 76 69 73 69 6f 6e 0d 72 6f 6c 65 73 2e 20 20 |ivision.roles. | 00000d20 54 68 69 73 20 69 73 20 61 20 74 65 63 68 6e 69 |This is a techni| 00000d30 71 75 65 20 79 6f 75 20 63 61 6e 20 75 73 65 20 |que you can use | 00000d40 69 66 20 79 6f 75 20 77 61 6e 74 20 74 6f 20 62 |if you want to b| 00000d50 65 0d 63 6c 65 61 72 20 61 62 6f 75 74 20 74 68 |e.clear about th| 00000d60 65 20 66 75 6e 63 74 69 6f 6e 20 6f 66 20 61 20 |e function of a | 00000d70 70 69 65 63 65 20 6f 66 20 6d 65 6d 6f 72 79 20 |piece of memory | 00000d80 61 6c 74 68 6f 75 67 68 20 69 74 73 0d 75 73 65 |although its.use| 00000d90 20 63 68 61 6e 67 65 73 20 64 75 72 69 6e 67 20 | changes during | 00000da0 74 68 65 20 70 72 6f 67 72 61 6d 2e 20 20 54 68 |the program. Th| 00000db0 65 72 65 20 69 73 20 6e 6f 20 70 65 6e 61 6c 74 |ere is no penalt| 00000dc0 79 20 66 6f 72 0d 6d 75 6c 74 69 2d 6e 61 6d 69 |y for.multi-nami| 00000dd0 6e 67 2c 20 61 70 61 72 74 20 66 72 6f 6d 20 6d |ng, apart from m| 00000de0 61 6b 69 6e 67 20 74 68 65 20 61 73 73 65 6d 62 |aking the assemb| 00000df0 6c 79 20 73 6f 75 72 63 65 20 63 6f 64 65 20 61 |ly source code a| 00000e00 0d 62 69 74 20 6c 6f 6e 67 65 72 2e 20 20 59 6f |.bit longer. Yo| 00000e10 75 72 20 66 69 6e 61 6c 20 70 72 6f 67 72 61 6d |ur final program| 00000e20 20 63 6f 64 65 2c 20 77 68 69 63 68 20 64 6f 65 | code, which doe| 00000e30 73 20 6e 6f 74 20 75 73 65 20 74 68 65 0d 6c 61 |s not use the.la| 00000e40 62 65 6c 73 2c 20 69 73 20 6e 6f 74 20 61 66 66 |bels, is not aff| 00000e50 65 63 74 65 64 2e 0d 0d 53 6f 20 6c 65 74 27 73 |ected...So let's| 00000e60 20 6c 6f 6f 6b 20 61 74 20 74 68 65 20 6d 75 6c | look at the mul| 00000e70 74 69 70 6c 69 63 61 74 69 6f 6e 20 66 69 72 73 |tiplication firs| 00000e80 74 2e 0d 0d 54 6f 20 61 76 6f 69 64 20 70 72 6f |t...To avoid pro| 00000e90 62 6c 65 6d 73 20 49 20 68 61 76 65 20 74 72 61 |blems I have tra| 00000ea0 70 70 65 64 20 7a 65 72 6f 73 20 61 74 20 74 68 |pped zeros at th| 00000eb0 65 20 73 74 61 72 74 20 6f 66 20 74 68 65 0d 6d |e start of the.m| 00000ec0 75 6c 74 69 70 6c 79 69 6e 67 20 72 6f 75 74 69 |ultiplying routi| 00000ed0 6e 65 73 2e 20 20 4f 62 76 69 6f 75 73 6c 79 20 |nes. Obviously | 00000ee0 61 20 7a 65 72 6f 20 65 6e 74 65 72 65 64 20 61 |a zero entered a| 00000ef0 73 20 65 69 74 68 65 72 0d 6e 75 6d 62 65 72 20 |s either.number | 00000f00 77 69 6c 6c 20 67 69 76 65 20 61 20 7a 65 72 6f |will give a zero| 00000f10 20 72 65 73 75 6c 74 20 77 68 65 6e 20 74 68 65 | result when the| 00000f20 79 20 61 72 65 20 6d 75 6c 74 69 70 6c 69 65 64 |y are multiplied| 00000f30 0d 74 6f 67 65 74 68 65 72 2e 20 20 54 68 65 72 |.together. Ther| 00000f40 65 20 69 73 20 61 20 73 75 62 72 6f 75 74 69 6e |e is a subroutin| 00000f50 65 20 61 74 20 27 6d 61 6b 65 5f 7a 65 72 6f 27 |e at 'make_zero'| 00000f60 20 77 68 69 63 68 20 6d 61 6b 65 73 0d 61 6c 6c | which makes.all| 00000f70 20 66 69 76 65 20 62 79 74 65 73 20 6f 66 20 27 | five bytes of '| 00000f80 66 70 77 73 5f 31 27 20 7a 65 72 6f 2e 20 20 4e |fpws_1' zero. N| 00000f90 6f 74 65 20 74 68 61 74 20 69 66 20 79 6f 75 20 |ote that if you | 00000fa0 62 72 61 6e 63 68 20 6f 72 0d 6a 75 6d 70 20 74 |branch or.jump t| 00000fb0 6f 20 61 20 73 6f 62 72 6f 75 74 69 6e 65 2c 20 |o a sobroutine, | 00000fc0 72 61 74 68 65 72 20 74 68 61 6e 20 4a 53 52 69 |rather than JSRi| 00000fd0 6e 67 20 74 6f 20 69 74 2c 20 79 6f 75 20 77 69 |ng to it, you wi| 00000fe0 6c 6c 0d 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 |ll.automatically| 00000ff0 20 52 54 53 20 61 74 20 74 68 65 20 65 6e 64 20 | RTS at the end | 00001000 6f 66 20 69 74 2c 20 69 6e 20 74 68 69 73 20 63 |of it, in this c| 00001010 61 73 65 20 74 68 61 74 20 74 61 6b 65 73 0d 75 |ase that takes.u| 00001020 73 20 6f 75 74 20 6f 66 20 74 68 65 20 27 66 70 |s out of the 'fp| 00001030 5f 6d 75 6c 74 27 20 73 75 62 72 6f 75 74 69 6e |_mult' subroutin| 00001040 65 20 63 6f 6d 70 6c 65 74 65 6c 79 2e 0d 0d 49 |e completely...I| 00001050 66 20 6e 65 69 74 68 65 72 20 6e 75 6d 62 65 72 |f neither number| 00001060 20 69 73 20 7a 65 72 6f 20 77 65 20 6d 6f 76 65 | is zero we move| 00001070 20 6f 6e 2e 20 20 54 68 65 20 73 69 67 6e 20 62 | on. The sign b| 00001080 69 74 20 69 73 0d 74 72 61 6e 73 66 65 72 72 65 |it is.transferre| 00001090 64 20 74 6f 20 61 6e 6f 74 68 65 72 20 62 79 74 |d to another byt| 000010a0 65 20 61 6e 64 20 74 68 65 20 74 6f 70 20 62 69 |e and the top bi| 000010b0 74 20 6f 66 20 74 68 65 20 6d 61 6e 74 69 73 73 |t of the mantiss| 000010c0 61 0d 63 6f 72 72 65 63 74 65 64 20 65 78 61 63 |a.corrected exac| 000010d0 74 6c 79 20 61 73 20 69 6e 20 74 68 65 20 6c 61 |tly as in the la| 000010e0 73 74 20 6d 6f 64 75 6c 65 2e 0d 0d 54 68 65 20 |st module...The | 000010f0 6d 75 6c 74 69 70 6c 79 69 6e 67 20 64 65 6e 6f |multiplying deno| 00001100 72 6d 61 6c 69 73 61 74 69 6f 6e 20 72 6f 75 74 |rmalisation rout| 00001110 69 6e 65 20 72 6f 74 61 74 65 73 20 65 61 63 68 |ine rotates each| 00001120 0d 6d 61 6e 74 69 73 73 61 20 72 69 67 68 74 20 |.mantissa right | 00001130 62 79 20 74 77 6f 20 62 79 74 65 73 2e 20 20 57 |by two bytes. W| 00001140 69 74 68 20 61 20 66 6f 75 72 20 62 79 74 65 20 |ith a four byte | 00001150 6d 61 6e 74 69 73 73 61 20 74 68 69 73 0d 65 66 |mantissa this.ef| 00001160 66 65 63 74 69 76 65 6c 79 20 67 69 76 65 73 20 |fectively gives | 00001170 75 73 20 74 77 6f 20 74 77 6f 20 62 79 74 65 20 |us two two byte | 00001180 6e 75 6d 62 65 72 73 20 77 68 69 63 68 2c 20 77 |numbers which, w| 00001190 68 65 6e 0d 6d 75 6c 74 69 70 6c 69 65 64 20 74 |hen.multiplied t| 000011a0 6f 67 65 74 68 65 72 2c 20 70 72 6f 64 75 63 65 |ogether, produce| 000011b0 20 61 20 66 6f 75 72 20 62 79 74 65 20 6e 75 6d | a four byte num| 000011c0 62 65 72 2e 20 20 54 68 69 73 20 66 6f 75 72 0d |ber. This four.| 000011d0 62 79 74 65 20 6e 75 6d 62 65 72 20 74 68 65 6e |byte number then| 000011e0 20 66 69 6c 6c 73 20 74 68 65 20 6d 61 6e 74 69 | fills the manti| 000011f0 73 73 61 20 77 6f 72 6b 20 73 70 61 63 65 20 61 |ssa work space a| 00001200 67 61 69 6e 2e 0d 0d 59 6f 75 20 6d 69 67 68 74 |gain...You might| 00001210 20 74 68 69 6e 6b 2c 20 61 73 20 49 20 6f 72 69 | think, as I ori| 00001220 67 69 6e 61 6c 6c 79 20 64 69 64 2c 20 74 68 61 |ginally did, tha| 00001230 74 20 77 68 65 6e 20 72 6f 74 61 74 69 6e 67 20 |t when rotating | 00001240 74 68 65 0d 6d 61 6e 74 69 73 73 61 65 20 79 6f |the.mantissae yo| 00001250 75 20 73 68 6f 75 6c 64 20 61 6c 74 65 72 20 74 |u should alter t| 00001260 68 65 20 65 78 70 6f 6e 65 6e 74 73 20 74 6f 20 |he exponents to | 00001270 63 6f 6d 70 65 6e 73 61 74 65 2e 20 0d 54 68 69 |compensate. .Thi| 00001280 73 20 70 72 6f 64 75 63 65 73 20 69 6e 63 6f 72 |s produces incor| 00001290 72 65 63 74 20 72 65 73 75 6c 74 73 20 61 6e 64 |rect results and| 000012a0 2c 20 61 66 74 65 72 20 6d 75 63 68 20 74 68 69 |, after much thi| 000012b0 6e 6b 69 6e 67 20 61 6e 64 0d 64 72 61 77 69 6e |nking and.drawin| 000012c0 67 20 6f 66 20 64 69 61 67 72 61 6d 73 20 49 20 |g of diagrams I | 000012d0 63 61 6d 65 20 74 6f 20 74 68 65 20 66 6f 6c 6c |came to the foll| 000012e0 6f 77 69 6e 67 20 63 6f 6e 63 6c 75 73 69 6f 6e |owing conclusion| 000012f0 2e 20 20 57 65 0d 61 72 65 20 64 6f 20 6e 6f 74 |. We.are do not| 00001300 20 68 61 76 65 20 74 6f 20 63 68 61 6e 67 65 20 | have to change | 00001310 74 68 65 20 65 78 70 6f 6e 65 6e 74 73 20 62 65 |the exponents be| 00001320 63 61 75 73 65 20 74 68 65 0d 6d 61 6e 74 69 73 |cause the.mantis| 00001330 73 61 65 20 61 72 65 2c 20 69 6e 20 66 61 63 74 |sae are, in fact| 00001340 2c 20 6a 75 73 74 20 6c 65 73 73 20 74 68 61 74 |, just less that| 00001350 20 31 20 69 6e 20 73 69 7a 65 2e 20 20 4e 6f 77 | 1 in size. Now| 00001360 20 69 66 0d 79 6f 75 20 6d 75 6c 74 69 70 6c 79 | if.you multiply| 00001370 20 30 2e 39 20 62 79 20 30 2e 39 20 79 6f 75 20 | 0.9 by 0.9 you | 00001380 67 65 74 20 30 2e 38 31 20 61 6e 64 20 6d 75 6c |get 0.81 and mul| 00001390 74 69 70 6c 79 69 6e 67 20 74 77 6f 0d 6d 61 6e |tiplying two.man| 000013a0 74 69 73 73 61 65 2c 20 65 61 63 68 20 77 69 74 |tissae, each wit| 000013b0 68 20 69 74 73 20 74 6f 70 20 62 69 74 20 73 65 |h its top bit se| 000013c0 74 2c 20 69 73 20 6a 75 73 74 20 6c 69 6b 65 20 |t, is just like | 000013d0 74 68 69 73 2e 20 20 57 65 0d 67 65 74 20 61 20 |this. We.get a | 000013e0 73 69 6d 69 6c 61 72 20 73 69 74 75 61 74 69 6f |similar situatio| 000013f0 6e 20 77 69 74 68 20 64 69 76 69 73 69 6f 6e 2e |n with division.| 00001400 0d 0d 27 6d 75 6c 74 5f 64 65 6e 6f 72 6d 61 6c |..'mult_denormal| 00001410 69 73 65 27 20 61 6c 73 6f 20 63 61 6c 63 75 6c |ise' also calcul| 00001420 61 74 65 73 20 74 68 65 20 69 6e 69 74 69 61 6c |ates the initial| 00001430 20 6e 65 77 20 65 78 70 6f 6e 65 6e 74 2e 20 0d | new exponent. .| 00001440 52 65 6d 65 6d 62 65 72 20 74 68 61 74 20 42 42 |Remember that BB| 00001450 43 20 42 41 53 49 43 20 61 64 64 73 20 26 38 30 |C BASIC adds &80| 00001460 20 74 6f 20 74 68 65 20 65 78 70 6f 6e 65 6e 74 | to the exponent| 00001470 73 20 69 6e 20 69 74 73 0d 66 6c 6f 61 74 69 6e |s in its.floatin| 00001480 67 20 70 6f 69 6e 74 20 66 6f 72 6d 61 74 2e 20 |g point format. | 00001490 20 49 66 20 6f 6e 20 61 64 64 69 6e 67 20 74 68 | If on adding th| 000014a0 65 20 65 78 70 6f 6e 65 6e 74 73 20 77 65 20 63 |e exponents we c| 000014b0 68 61 6e 67 65 0d 74 68 65 20 32 27 73 20 63 6f |hange.the 2's co| 000014c0 6d 70 6c 65 6d 65 6e 74 20 73 69 67 6e 20 6f 66 |mplement sign of| 000014d0 20 74 68 65 20 72 65 73 75 6c 74 20 74 68 65 6e | the result then| 000014e0 20 74 68 65 20 72 65 73 75 6c 74 20 68 61 0d 6f | the result ha.o| 000014f0 76 65 72 66 6c 6f 77 65 64 20 61 6e 64 20 69 73 |verflowed and is| 00001500 6d 6f 75 74 20 6f 66 20 72 61 6e 67 65 2e 20 20 |mout of range. | 00001510 54 68 69 73 20 6d 69 67 68 74 20 68 61 70 70 65 |This might happe| 00001520 6e 20 69 66 2c 20 73 61 79 2c 0d 77 65 20 61 64 |n if, say,.we ad| 00001530 64 65 64 20 31 32 30 20 74 6f 20 32 30 2e 20 20 |ded 120 to 20. | 00001540 31 34 30 20 69 73 20 61 63 74 75 61 6c 6c 79 20 |140 is actually | 00001550 61 20 6e 65 67 61 74 69 76 65 20 6e 75 6d 62 65 |a negative numbe| 00001560 72 20 69 6e 0d 32 27 73 20 63 6f 6d 70 6c 65 6d |r in.2's complem| 00001570 65 6e 74 20 61 6e 64 20 73 6f 20 77 65 20 68 61 |ent and so we ha| 00001580 76 65 20 77 72 61 70 70 65 64 20 61 72 6f 75 6e |ve wrapped aroun| 00001590 64 20 74 68 65 20 62 79 74 65 20 74 6f 0d 67 69 |d the byte to.gi| 000015a0 76 65 20 61 6e 20 69 6e 63 6f 72 72 65 63 74 20 |ve an incorrect | 000015b0 72 65 73 75 6c 74 2e 20 20 57 65 20 63 61 6e 20 |result. We can | 000015c0 74 72 61 70 20 74 68 69 73 20 62 79 20 63 68 61 |trap this by cha| 000015d0 63 6b 69 6e 67 20 74 68 65 0d 6f 76 65 72 66 6c |cking the.overfl| 000015e0 6f 77 20 66 6c 61 67 2e 20 20 54 68 69 73 20 66 |ow flag. This f| 000015f0 6c 61 67 20 77 69 6c 6c 20 64 65 74 65 63 74 20 |lag will detect | 00001600 61 6e 20 61 6e 6f 6d 6f 6c 6f 75 73 20 6f 76 65 |an anomolous ove| 00001610 72 66 6c 6f 77 0d 61 6e 64 20 73 6f 20 77 65 20 |rflow.and so we | 00001620 63 61 6e 20 75 73 65 20 69 74 20 74 6f 20 62 72 |can use it to br| 00001630 61 6e 63 68 20 74 6f 20 61 6e 20 65 72 72 6f 72 |anch to an error| 00001640 20 72 6f 75 74 69 6e 65 2e 20 20 57 69 74 68 0d | routine. With.| 00001650 6d 75 6c 74 69 70 6c 69 63 61 74 69 6f 6e 2c 20 |multiplication, | 00001660 61 20 72 65 73 75 6c 74 20 74 68 61 74 20 68 61 |a result that ha| 00001670 73 20 6f 76 65 72 66 6c 6f 77 65 64 20 74 6f 6f |s overflowed too| 00001680 20 6d 75 63 68 0d 6e 65 67 61 74 69 76 65 6c 79 | much.negatively| 00001690 20 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 20 | means that the | 000016a0 6e 75 6d 62 65 72 20 69 73 20 69 6e 20 66 61 63 |number is in fac| 000016b0 74 20 74 6f 6f 20 73 6d 61 6c 6c 20 66 6f 72 20 |t too small for | 000016c0 75 73 0d 74 6f 20 72 65 70 72 65 73 65 6e 74 20 |us.to represent | 000016d0 69 74 2e 20 20 54 68 69 73 20 69 73 20 6e 6f 74 |it. This is not| 000016e0 20 74 72 65 61 74 65 64 20 61 73 20 61 6e 20 65 | treated as an e| 000016f0 72 72 6f 72 2c 20 62 75 74 0d 69 6e 73 74 65 61 |rror, but.instea| 00001700 64 20 6d 65 61 6e 73 20 74 68 61 74 20 77 65 20 |d means that we | 00001710 6d 75 73 74 20 73 65 74 20 74 68 65 20 72 65 73 |must set the res| 00001720 75 6c 74 20 74 6f 20 7a 65 72 6f 2e 20 20 46 6f |ult to zero. Fo| 00001730 72 20 61 0d 76 61 6c 75 65 20 74 68 61 74 20 69 |r a.value that i| 00001740 73 20 74 6f 6f 20 62 69 67 20 49 20 68 61 76 65 |s too big I have| 00001750 20 75 73 65 64 20 45 72 72 6f 72 20 32 30 2c 20 | used Error 20, | 00001760 62 75 74 20 67 69 76 65 6e 20 69 74 0d 73 6c 69 |but given it.sli| 00001770 67 68 74 6c 79 20 64 69 66 66 65 72 65 6e 74 20 |ghtly different | 00001780 6d 65 73 73 61 67 65 73 20 74 6f 20 42 41 53 49 |messages to BASI| 00001790 43 20 61 73 20 79 6f 75 20 63 61 6e 20 73 65 65 |C as you can see| 000017a0 20 69 6e 20 74 68 65 0d 6c 69 73 74 69 6e 67 2e | in the.listing.| 000017b0 0d 0d 49 20 6d 75 6c 74 69 70 6c 69 65 64 20 74 |..I multiplied t| 000017c0 68 65 20 74 77 6f 20 6e 75 6d 62 65 72 73 20 75 |he two numbers u| 000017d0 73 69 6e 67 20 61 20 6d 6f 64 69 66 69 65 64 20 |sing a modified | 000017e0 76 65 72 73 69 6f 6e 20 6f 66 20 74 68 65 0d 6d |version of the.m| 000017f0 75 6c 74 69 2d 62 79 74 65 20 6d 75 74 6c 69 70 |ulti-byte mutlip| 00001800 6c 69 63 61 74 69 6f 6e 20 72 6f 75 74 69 6e 65 |lication routine| 00001810 20 66 72 6f 6d 20 6d 6f 64 75 6c 65 20 31 33 2e | from module 13.| 00001820 20 20 54 68 65 20 6d 61 69 6e 0d 64 69 66 66 65 | The main.diffe| 00001830 72 65 6e 63 65 20 69 73 20 74 68 61 74 20 74 68 |rence is that th| 00001840 65 20 66 6c 6f 61 74 69 6e 67 20 70 6f 69 6e 74 |e floating point| 00001850 20 6d 61 6e 74 69 73 73 61 20 69 73 20 73 74 6f | mantissa is sto| 00001860 72 65 64 0d 62 61 63 6b 20 74 6f 20 66 72 6f 6e |red.back to fron| 00001870 74 20 63 6f 6d 70 61 72 65 64 20 74 6f 20 74 68 |t compared to th| 00001880 65 20 69 6e 74 65 67 65 72 73 2c 20 77 69 74 68 |e integers, with| 00001890 20 74 68 65 20 6c 65 61 73 74 0d 73 69 67 6e 69 | the least.signi| 000018a0 66 69 63 61 6e 74 20 62 79 74 65 20 69 6e 20 74 |ficant byte in t| 000018b0 68 65 20 6c 6f 77 65 73 74 20 6d 65 6d 6f 72 79 |he lowest memory| 000018c0 20 6c 6f 63 61 74 69 6f 6e 2e 20 20 4e 6f 74 65 | location. Note| 000018d0 20 74 68 61 74 2c 0d 61 73 20 74 68 65 20 70 61 | that,.as the pa| 000018e0 72 74 69 61 6c 20 70 72 6f 64 75 63 74 20 77 6f |rtial product wo| 000018f0 72 6b 73 70 61 63 65 20 64 6f 65 73 20 6e 6f 74 |rkspace does not| 00001900 20 75 73 65 20 74 68 65 20 65 78 70 6f 6e 65 6e | use the exponen| 00001910 74 2c 0d 69 74 20 69 73 20 6f 6e 6c 79 20 66 6f |t,.it is only fo| 00001920 75 72 20 62 79 74 65 73 20 6c 6f 6e 67 20 6e 6f |ur bytes long no| 00001930 74 20 66 69 76 65 2e 0d 0d 41 66 74 65 72 20 6d |t five...After m| 00001940 75 6c 74 69 70 6c 79 69 6e 67 20 77 65 20 72 65 |ultiplying we re| 00001950 6e 6f 72 6d 61 6c 69 73 65 20 74 68 65 20 6d 61 |normalise the ma| 00001960 6e 74 69 73 73 61 20 62 79 20 72 6f 74 61 74 69 |ntissa by rotati| 00001970 6e 67 20 69 74 0d 6c 65 66 74 20 75 6e 74 69 6c |ng it.left until| 00001980 20 74 68 65 20 74 6f 70 20 62 69 74 20 69 73 20 | the top bit is | 00001990 73 65 74 2e 20 20 42 79 20 63 6f 6e 76 65 72 74 |set. By convert| 000019a0 69 6e 67 20 74 6f 20 74 77 6f 20 74 77 6f 0d 62 |ing to two two.b| 000019b0 79 74 65 20 6e 75 6d 62 65 72 73 20 77 65 20 63 |yte numbers we c| 000019c0 61 6e 6e 6f 74 20 68 61 76 65 20 61 6e 20 6f 76 |annot have an ov| 000019d0 65 72 66 6c 6f 77 20 68 65 72 65 20 73 6f 20 77 |erflow here so w| 000019e0 65 20 6f 6e 6c 79 20 68 61 76 65 0d 74 6f 20 63 |e only have.to c| 000019f0 68 65 63 6b 20 66 6f 72 20 61 20 6e 75 6d 62 65 |heck for a numbe| 00001a00 72 20 74 68 61 74 20 69 73 20 74 6f 6f 20 73 6d |r that is too sm| 00001a10 61 6c 6c 2e 20 20 41 20 7a 65 72 6f 20 72 65 73 |all. A zero res| 00001a20 75 6c 74 20 69 73 0d 74 72 61 70 70 65 64 20 68 |ult is.trapped h| 00001a30 65 72 65 20 62 65 63 61 75 73 65 20 69 74 20 77 |ere because it w| 00001a40 6f 75 6c 64 20 6f 74 68 65 72 77 69 73 65 20 73 |ould otherwise s| 00001a50 65 6e 64 20 74 68 65 20 72 6f 75 74 69 6e 65 0d |end the routine.| 00001a60 69 6e 74 6f 20 61 6e 20 65 6e 64 6c 65 73 73 20 |into an endless | 00001a70 6c 6f 6f 70 2e 0d 0d 46 69 6e 61 6c 6c 79 20 74 |loop...Finally t| 00001a80 68 65 20 73 69 67 6e 20 62 69 74 20 69 73 20 72 |he sign bit is r| 00001a90 65 70 6c 61 63 65 64 2e 20 20 54 68 65 20 73 69 |eplaced. The si| 00001aa0 67 6e 20 62 75 73 69 6e 65 73 73 20 69 73 20 61 |gn business is a| 00001ab0 0d 67 72 65 61 74 20 64 65 61 6c 20 65 61 73 69 |.great deal easi| 00001ac0 65 72 20 77 69 74 68 20 6d 75 6c 74 69 70 6c 63 |er with multiplc| 00001ad0 61 74 69 6f 6e 20 61 6e 64 20 64 69 76 69 73 69 |ation and divisi| 00001ae0 6f 6e 20 74 68 61 74 20 69 74 0d 77 61 73 20 77 |on that it.was w| 00001af0 69 74 68 20 61 64 64 69 74 69 6f 6e 20 61 6e 64 |ith addition and| 00001b00 20 73 75 62 74 72 61 63 74 69 6f 6e 2e 20 20 49 | subtraction. I| 00001b10 66 20 79 6f 75 20 45 4f 52 20 74 68 65 20 74 77 |f you EOR the tw| 00001b20 6f 20 73 69 67 6e 0d 62 69 74 73 20 74 6f 67 65 |o sign.bits toge| 00001b30 74 68 65 72 20 79 6f 75 20 67 65 74 20 74 68 65 |ther you get the| 00001b40 20 72 65 73 75 6c 74 3b 20 73 69 6d 70 6c 65 20 | result; simple | 00001b50 61 73 20 74 68 61 74 2e 0d 0d 57 68 65 72 65 20 |as that...Where | 00001b60 64 69 76 69 73 69 6f 6e 20 69 73 20 63 6f 6e 63 |division is conc| 00001b70 65 72 6e 65 64 20 6d 75 63 68 20 6f 66 20 74 68 |erned much of th| 00001b80 65 20 70 72 6f 63 65 64 75 72 65 20 69 73 20 74 |e procedure is t| 00001b90 68 65 0d 73 61 6d 65 2e 20 20 48 65 72 65 20 61 |he.same. Here a| 00001ba0 20 7a 65 72 6f 20 61 73 20 74 68 65 20 73 65 63 | zero as the sec| 00001bb0 6f 6e 64 20 6e 75 6d 62 65 72 20 69 73 20 61 20 |ond number is a | 00001bc0 66 61 74 61 6c 20 65 72 72 6f 72 0d 73 69 6e 63 |fatal error.sinc| 00001bd0 65 20 77 65 20 63 61 6e 6e 6f 74 20 64 69 76 69 |e we cannot divi| 00001be0 64 65 20 62 79 20 7a 65 72 6f 2e 20 20 41 20 7a |de by zero. A z| 00001bf0 65 72 6f 20 66 6f 72 20 66 69 72 73 74 20 6e 75 |ero for first nu| 00001c00 6d 62 65 72 0d 6a 75 73 74 20 6c 65 61 64 73 20 |mber.just leads | 00001c10 74 6f 20 61 20 7a 65 72 6f 20 72 65 73 75 6c 74 |to a zero result| 00001c20 2e 0d 0d 44 65 6e 6f 72 6d 61 6c 69 73 61 74 69 |...Denormalisati| 00001c30 6f 6e 20 66 6f 72 20 64 69 76 69 73 69 6f 6e 2c |on for division,| 00001c40 20 69 6e 20 6d 79 20 69 6d 70 6c 69 6d 65 6e 74 | in my impliment| 00001c50 61 74 69 6f 6e 2c 20 69 6e 76 6f 6c 76 65 73 0d |ation, involves.| 00001c60 72 6f 74 61 74 69 6e 67 20 74 68 65 20 64 69 76 |rotating the div| 00001c70 69 73 6f 72 20 72 69 67 68 74 20 62 79 20 74 77 |isor right by tw| 00001c80 6f 20 62 79 74 65 73 2e 20 20 54 68 69 73 20 65 |o bytes. This e| 00001c90 66 66 65 63 74 69 76 65 6c 79 0d 6d 65 61 6e 73 |ffectively.means| 00001ca0 20 74 68 61 74 20 77 65 20 68 61 76 65 20 61 20 | that we have a | 00001cb0 66 6f 75 72 20 62 79 74 65 20 6e 75 6d 62 65 72 |four byte number| 00001cc0 20 64 69 76 69 64 65 64 20 62 79 20 61 20 74 77 | divided by a tw| 00001cd0 6f 20 62 79 74 65 0d 6f 6e 65 2c 20 61 6c 74 68 |o byte.one, alth| 00001ce0 6f 75 67 68 20 74 68 65 20 74 77 6f 20 62 79 74 |ough the two byt| 00001cf0 65 20 6f 6e 65 20 68 61 73 20 74 77 6f 20 6f 74 |e one has two ot| 00001d00 68 65 72 20 62 79 74 65 73 20 62 65 79 6f 6e 65 |her bytes beyone| 00001d10 0d 74 68 65 20 27 62 69 6e 61 72 79 20 70 6f 69 |.the 'binary poi| 00001d20 6e 74 27 20 61 6e 64 20 74 68 65 20 64 69 76 69 |nt' and the divi| 00001d30 73 69 6f 6e 20 72 6f 75 74 69 6e 65 20 74 68 65 |sion routine the| 00001d40 72 65 66 6f 72 65 20 77 6f 72 6b 73 0d 6f 76 65 |refore works.ove| 00001d50 72 20 34 38 20 62 69 74 73 2e 0d 0d 49 6e 20 63 |r 48 bits...In c| 00001d60 61 6c 63 75 6c 61 74 69 6e 67 20 74 68 65 20 69 |alculating the i| 00001d70 6e 69 74 69 61 6c 20 65 78 70 6f 6e 65 6e 74 20 |nitial exponent | 00001d80 6f 66 20 74 68 65 20 72 65 73 75 6c 74 20 49 20 |of the result I | 00001d90 66 6f 75 6e 64 0d 74 68 61 74 20 74 6f 20 63 6f |found.that to co| 00001da0 6d 70 65 6e 73 61 74 65 20 66 6f 72 20 74 68 65 |mpensate for the| 00001db0 20 72 6f 74 61 74 69 6f 6e 2c 20 61 6e 64 20 62 | rotation, and b| 00001dc0 65 63 61 75 73 65 20 62 6f 74 68 20 6f 75 72 0d |ecause both our.| 00001dd0 6e 75 6d 62 65 72 73 20 77 65 72 65 20 6a 75 73 |numbers were jus| 00001de0 74 20 75 6e 64 65 72 20 31 20 69 6e 20 73 69 7a |t under 1 in siz| 00001df0 65 20 61 67 61 69 6e 2c 20 49 20 68 61 64 20 74 |e again, I had t| 00001e00 6f 20 69 6e 63 72 65 61 73 65 0d 74 68 65 20 73 |o increase.the s| 00001e10 69 7a 65 20 6f 66 20 74 68 65 20 65 78 70 6f 6e |ize of the expon| 00001e20 65 6e 74 20 62 79 20 33 32 20 28 26 32 30 29 20 |ent by 32 (&20) | 00001e30 77 68 69 63 68 20 69 73 20 64 6f 6e 65 20 61 66 |which is done af| 00001e40 74 65 72 20 74 68 65 0d 73 65 63 6f 6e 64 20 65 |ter the.second e| 00001e50 78 70 6f 6e 65 6e 74 20 68 61 73 20 62 65 65 6e |xponent has been| 00001e60 20 73 75 62 74 72 61 63 74 65 64 20 66 72 6f 6d | subtracted from| 00001e70 20 74 68 65 20 66 69 72 73 74 2e 20 20 5b 49 20 | the first. [I | 00001e80 77 69 73 68 0d 49 20 75 6e 64 65 72 73 74 6f 6f |wish.I understoo| 00001e90 64 20 74 68 65 73 65 20 27 66 75 64 67 65 27 20 |d these 'fudge' | 00001ea0 66 61 63 74 6f 72 73 20 6d 6f 72 65 20 63 6c 65 |factors more cle| 00001eb0 61 72 6c 79 2c 20 74 68 65 6e 20 49 0d 63 6f 75 |arly, then I.cou| 00001ec0 6c 64 20 65 78 70 6c 61 69 6e 20 74 68 65 6d 20 |ld explain them | 00001ed0 6d 6f 72 65 20 63 6c 65 61 72 6c 79 2e 5d 0d 0d |more clearly.]..| 00001ee0 4a 75 73 74 20 61 73 20 74 68 65 20 65 78 70 6f |Just as the expo| 00001ef0 6e 65 6e 74 73 20 63 6f 75 6c 64 20 6f 76 65 72 |nents could over| 00001f00 66 6c 6f 77 20 64 75 72 69 6e 67 20 6d 75 6c 74 |flow during mult| 00001f10 69 70 6c 69 63 61 74 69 6f 6e 2c 0d 73 6f 20 74 |iplication,.so t| 00001f20 68 65 79 20 63 61 6e 20 64 75 72 69 6e 67 20 64 |hey can during d| 00001f30 69 76 69 73 69 6f 6e 2c 20 61 6e 64 20 74 68 61 |ivision, and tha| 00001f40 74 20 69 73 20 74 72 61 70 70 65 64 20 61 74 20 |t is trapped at | 00001f50 74 68 65 20 65 6e 64 0d 6f 66 20 74 68 65 20 27 |the end.of the '| 00001f60 64 69 76 5f 64 65 6e 6f 72 6d 61 6c 69 73 65 27 |div_denormalise'| 00001f70 20 72 6f 75 74 69 6e 65 2e 0d 0d 54 68 65 20 64 | routine...The d| 00001f80 69 76 69 73 69 6f 6e 20 73 75 62 72 6f 75 74 69 |ivision subrouti| 00001f90 6e 65 20 69 73 20 61 20 73 74 72 61 69 67 68 74 |ne is a straight| 00001fa0 66 6f 72 77 61 72 64 20 6d 6f 64 69 66 69 63 61 |forward modifica| 00001fb0 74 69 6f 6e 20 6f 66 0d 74 68 65 20 6d 75 6c 74 |tion of.the mult| 00001fc0 69 2d 62 79 74 65 20 69 6e 74 65 67 65 72 20 64 |i-byte integer d| 00001fd0 69 76 69 73 69 6f 6e 20 72 6f 75 74 69 6e 65 20 |ivision routine | 00001fe0 69 6e 20 6d 6f 64 75 6c 65 20 31 35 2e 20 20 49 |in module 15. I| 00001ff0 6e 0d 74 68 69 73 20 63 61 73 65 20 77 65 20 63 |n.this case we c| 00002000 61 6c 63 75 6c 61 74 65 20 6f 76 65 72 20 34 38 |alculate over 48| 00002010 20 62 69 74 73 20 69 6e 73 74 65 61 64 20 6f 66 | bits instead of| 00002020 20 33 32 2c 20 61 6e 64 20 74 68 65 0d 77 6f 72 | 32, and the.wor| 00002030 6b 73 70 61 63 65 20 69 73 20 62 61 63 6b 20 74 |kspace is back t| 00002040 6f 20 66 72 6f 6e 74 20 62 65 63 61 75 73 65 20 |o front because | 00002050 6f 66 20 74 68 65 20 77 61 79 20 74 68 65 20 66 |of the way the f| 00002060 6c 6f 61 74 69 6e 67 0d 70 6f 69 6e 74 20 6d 61 |loating.point ma| 00002070 6e 74 69 73 73 61 65 20 61 72 65 20 73 74 6f 72 |ntissae are stor| 00002080 65 64 2e 0d 0d 52 65 6e 6f 72 6d 61 6c 69 73 61 |ed...Renormalisa| 00002090 74 69 6f 6e 20 61 6e 64 20 66 69 78 69 6e 67 20 |tion and fixing | 000020a0 74 68 65 20 73 69 67 6e 20 62 69 74 20 6f 70 65 |the sign bit ope| 000020b0 72 61 74 65 20 65 78 61 63 74 6c 79 20 61 73 0d |rate exactly as.| 000020c0 77 69 74 68 20 6d 75 6c 74 69 70 6c 69 63 61 74 |with multiplicat| 000020d0 69 6f 6e 2c 20 75 73 69 6e 67 20 74 68 65 20 73 |ion, using the s| 000020e0 61 6d 65 20 73 75 62 72 6f 75 74 69 6e 65 73 2e |ame subroutines.| 000020f0 0d 0d 54 68 65 73 65 20 66 6c 6f 61 74 69 6e 67 |..These floating| 00002100 20 70 6f 69 6e 74 20 72 6f 75 74 69 6e 65 73 20 | point routines | 00002110 61 72 65 20 62 79 20 6e 6f 20 6d 65 61 6e 73 20 |are by no means | 00002120 73 69 6d 70 6c 65 2e 20 20 54 6f 0d 6d 61 6b 65 |simple. To.make| 00002130 20 74 68 65 6d 20 6d 6f 72 65 20 61 63 63 75 72 | them more accur| 00002140 61 74 65 20 77 6f 75 6c 64 20 6d 61 6b 65 20 74 |ate would make t| 00002150 68 65 6d 20 6d 6f 72 65 20 6f 62 73 63 75 72 65 |hem more obscure| 00002160 2c 20 62 75 74 0d 74 68 65 20 70 72 69 6e 63 69 |, but.the princi| 00002170 70 6c 65 73 20 62 65 68 69 6e 64 20 74 68 65 6d |ples behind them| 00002180 20 61 72 65 20 73 74 72 61 69 67 68 74 66 6f 72 | are straightfor| 00002190 77 61 72 64 20 65 6e 6f 75 67 68 2e 20 0d 4d 61 |ward enough. .Ma| 000021a0 79 62 65 20 79 6f 75 27 64 20 6c 69 6b 65 20 74 |ybe you'd like t| 000021b0 6f 20 74 72 79 20 6d 61 6b 69 6e 67 20 74 68 61 |o try making tha| 000021c0 74 20 4d 61 6e 64 65 6c 62 72 6f 74 20 70 72 6f |t Mandelbrot pro| 000021d0 67 72 61 6d 20 66 72 6f 6d 0d 6d 6f 64 75 6c 65 |gram from.module| 000021e0 20 32 31 20 77 6f 72 6b 20 75 73 69 6e 67 20 66 | 21 work using f| 000021f0 6c 6f 61 74 69 6e 67 20 70 6f 69 6e 74 3f 0d 0d |loating point?..| 00002200 57 68 69 6c 65 20 79 6f 75 27 72 65 20 74 68 69 |While you're thi| 00002210 6e 6b 69 6e 67 20 61 62 6f 75 74 20 74 68 61 74 |nking about that| 00002220 20 49 20 77 69 6c 6c 20 6d 6f 76 65 20 6f 6e 20 | I will move on | 00002230 74 6f 20 73 69 64 65 77 61 79 73 0d 52 4f 4d 73 |to sideways.ROMs| 00002240 2c 20 61 20 73 75 62 6a 65 63 74 20 76 65 72 79 |, a subject very| 00002250 20 73 70 65 63 69 66 69 63 20 74 6f 20 74 68 65 | specific to the| 00002260 20 42 42 43 20 4d 69 63 72 6f 2c 20 69 6e 20 74 | BBC Micro, in t| 00002270 68 65 20 6e 65 78 74 0d 6d 6f 64 75 6c 65 2e 0d |he next.module..| 00002280