Contents / Reference section / BASIC keywords / Previous letter / Next letter / Index


A

ABS absolute value

Purpose

This function turns negative numbers into equivalent positive numbers but leaves positive numbers alone. For example the absolute value of -9.75 is 9.75 while the absolute value of 4.56 is 4.56.

The ABS function is often used when calculating the difference between two values if you do not know which is the larger of the two. Thus (K - L) will be positive if K is greater than L, and will be negative if L is greater than K.

For example if K=9 and L=12 then (K - L) would be equal to -3. However the value of ABS(K-L) will always be positive. In the example given ABS(K-L) would equal 3.

Examples

205 error=ABS(DIFFERENCE)

100 DIFF=ABS(X2-Xl)

PRINT ABS(temp%-50)

Description

A function giving the absolute value of its argument.

Known problems

There is a known 'bug' in release 1.0. If ABS is used with the unary minus operator (PRINT - ABS(1)) a 'Type mismatch' error message will be reported.

Syntax

<num-var>=ABS (<numeric>)

Associated keywords

SGN

ACS arc-cosine

Purpose

To calculate an angle whose cosine is known. The calculated angle is in radians but may be converted to degrees by using the function DEG. See DEG for more information.

Examples

10 X=ACS(Y)

1205 angle=DEG (ACS(0.5678))

330 OUT=ACS(.234)

PRINT ACS (0.5)

Description

A function giving the arc-cosine of its argument. The result is in radian measure.

Syntax

<num-var>=ACS (<numeric>)

Associated keywords

ASN, ATN, SIN, COS, TAN, RAD, DEG

ADVAL analogue to digital converter value

Purpose

An analogue signal is one which can have almost any value - including fractional parts. It is contrasted with a digital signal which is expressed in exact numbers. The height of the water in a harbour is an analogue quantity whereas the number of boats it contains is a digital quantity.

Watches always used to have analogue dials - "The time is about four fifteen". Electronic things usually much prefer to work with whole numbers; for example

16h: 15m: 23s

There are four "Analogue to Digital" converters in the Model B BBC Microcomputer. Each analogue to digital converter in the computer accepts a voltage and gives out a whole number indicating how large the voltage is. This voltage might be controlled by, for example, the position of a "games paddle" or "joy-stick" control which is connected to the computer. Alternatively the computer might be connected to a speed sensor on a piece of machinery or it might measure the temperature of a room.

The input voltage range is 0 volt to 1.8 volt. When the input is 0V the converter produces the number zero. With 1.8 V input the converter produces the number 65520. Why 65520? The circuit in the computer which does the conversion was designed to give out numbers in the range 0 to 4095. However it may well be that future converters can give out numbers over a large range - enabling the computer to measurr things more accurately. In order to ensure that the BBC Microcomputer can cope with this situation we have specified a large range.

Thus instead of numbers in the range 0 to 4095 it produces a number in the range 0 to 65520. Therefore instead of numeric results going up in the sequence 0,1,2,3, etc. they will go

0,16,32,48,64 etc. If you prefer the range 0 to 4095 then just divide the value by 16.

There are four analogue inputs channels provided in the Model B microcomputer and the number in brackets after the keyword ADVAL refers to the channel whose value you wish to find. The channels are numbered 1,2,3,4.

ADVAL(0) performs a special function in that it can be used to test to see which of the "Fire" buttons is pressed on the games paddles. The value returned also indicates which ADC channel was the last one to be updated. The following can be used to extract these two pieces of information from the value returned by ADVAL(0).

X=ADVAL(0) AND 3

will give a number with the following meaning

X=0 no button pressed

X=1 left side fire button pressed

X=2 right side fire button pressed

X=3 both fire buttons pressed.

X=ADVAL(0) DIV 256

will give the number of the last analogue to digital channel to complete conversion. If the value returned is zero then no channel has yet completed conversion.

ADVAL with a negative number in the brackets - e.g. X=ADVAL(-3) can be used to see how full any of the internal buffers are. When characters are typed in on the keyboard they are put into a buffer from which they are extracted with statements like INPUT and GET. Other buffers are used internally for other purposes. The exact meaning of the number returned depends on the buffer being tested.

X=ADVAL(-1) returns the number of characters in the keyboard buffer
X=ADVAL(-2) returns the number of characters in the RS423 input buffer
X=ADVAL(-3) returns the number of free spaces in the RS423 output buffer
X=ADVAL(-4) returns the number of free spaces in the printer output buffer
X=ADVAL(-5) returns the number of free spaces in the SOUND channel 0 buffer
X=ADVAL(-6) returns the number of free spaces in the SOUND channel 1 buffer
X=ADVAL(-7) returns the number of free spaces in the SOUND channel 2 buffer
X=ADVAL(-8) returns the number of free spaces in the SOUND channel 3 buffer
X=ADVAL(-9) returns the number of free spaces in the SPEECH buffer

This feature can be used, for example, to ensure that a program never gets stuck waiting for a SOUND channel to empty.

e.g. IF ADVAL(-7)<> 0 THEN SOUND 2,.....etc

Examples

980 X=ADVAL(3)

125 TEMP=ADVAL(X)

intensity=ADVAL (1)

Syntax

<num-var>=ADVAL(<numeric>)

Description

A function which returns the last known value of the analogue to digital channel given in its argument. There are 4 channels each of 12 bit resolution, but the returned value is scaled to 16 bits.

The analogue to digital converter cycles repeatedly through the selected channels and keeps a table of the results so that the function ADVAL returns very quickly. New samples are taken about every 10 milli-seconds. Thus with 4 channels selected results will be updated every 40 ms. See page 428 "Machine Operating System" for information on changing the number of channels selected.

AND

Purpose

AND can be used either as a logical operator or as a "bit by bit" operator. A common jargon word for "bit by bit" is "bitwise" and it wi11 be used in the description which follows.

As a logical operator AND is used to ensure that two conditions are met before something is done. For example

IF X=9 AND Y=0 THEN PRINT "HELLO"

Logical AND is most often used as part of the IF...AND...THEN...construction.

Bitwise AND compares the first bit of one number with the first bit of another number. If both bits are set to a one (rather than a zero) then the first bit in the answer is also set to a one. This process is then repeated for bit 1 in each of the two numbers being compared and so on for all 32 bits in the numbers. For example the result of 14 AND 7 is 6, since in binary

14 is 0000 0000 0000 0000 0000 0000 0000 1110
7 is 0000 0000 0000 0000 0000 0000 0000 0111
6 is 0000 0000 0000 0000 0000 0000 0000 0110

Examples

300 IF length>9 AND wt>9 THEN PRINT "YES"

100 IF X=2 AND cost>5 AND J=12 THEN PRINT "NO!!

The above example will only print NO!! if all three conditions are met.

Description

The operation of integer bitwise AND between two items. Note that the logical and bitwise operations are in fact equivalent. This follows since the value of TRUE is -1 which is represented on this machine by the binary number

1111 1111 1111 1111 1111 1111 1111 1111

Similarly the binary value of FALSE is

0000 0000 0000 0000 0000 0000 0000 0000

Thus PRINT 6=6

would print "-1" since "6=6" is TRUE.

Syntax

<num-var>=<numeric> AND <numeric>

<testable condition>=<testable condition> AND <testable condition>

Associated keywords

EOR, OR, FALSE, TRUE, NOT

ASC American Standard Code (ASCII)

Purpose

There are two commonly used methods of talking about characters (things like A, B, 5, ?, and so on). Most obviously they are single characters! So we can say D$="H" -meaning put the letter H into the box in the computer labelled D$. The computer understands this but it doesn't acutally put an H into the box. Instead it stores a number which represents the letter H (in fact the number is 72). Every character has a unique corresponding number called its ASCII code. (ASCII stands for American Standard Code for Information Interchange. The abbreviation ASCII rhymes with "Laski").

Sometimes it is convenient to find out what number corresponds to a particular character - that is its ASCII code. You can look it up at the back of this book or you can say to the computer

PRINT ASC("H")

The function ASC gives the ASCII value of the first letter in the string. Thus

PRINT ASC("Good")

gives 71, the ASCII value of "G".

The reverse process of generating a 1-character string from a given ASCII value is performed by the function CHR$.

Examples

25 X=ASC ("Today")

would put the ASCII value of "T" which is 84 into the variable X.

650 value5=ASC(A$)

Description

A function returning the ASCII character value of the first character of the argument string. If the string is null (empty) then -1 will be returned.

Syntax

<num-var>=ASC(<string>)

Associated keywords

CHR$, STR$, VAL

ASN arc-sine

Purpose

To calculate an angle whose sine is known. The calculated angle is in radians but may be converted to degrees by using the function DEG. 1 radian is equal to about 57 degrees. Mathematicians often prefer to work in radians.

Examples

340 J=ASN(0.3456)

30 angle=DEG(ASN(.7654))

PRINT ASN(.5)

Description

A function giving the arc-sine of its argument. The result is in radian measure.

Syntax

<num-var>=ASN(<numeric>)

Associated keywords

ACS, ATN, SIN, COS, TAN, RAD, DEG

ATN arc-tangent

Purpose

To calculate an angle whose tangent is known. The calculated angle is in radians but may be converted to degrees by using the function DEG

Examples

1250X=ATN(Y)

240 value=DEG(ATN(2.31))

Description

A function giving the arc-tangent of its argument. The result is in radian measure.

Syntax

<num-var>=ATN(<numeric>)

Associated keywords

ACS, ASN, SIN, COS, TAN, RAD, DEG

AUTO automatic

Purpose

When typing a BASIC program into the computer it is common to make the first line of the program line number 10, the second line 20 etc. To save having to type in the line number each time, the command AUTO can be used to make the computer "offer" each line number automatically. Used on its own the command AUTO will offer first line 10 and then line 20, 30, 40 etc. The command AUTO 455 would instead start the process at line number 455, followed by lines 465, 475, 485 etc.

Another option allows the user to select the step size. Thus the command AUTO 465,2 would cause the computer to offer lines 465, 467, 469, 471 etc. The largest step size is 255.

To escape from AUTO mode the user must press the key marked ESCAPE. AUTO mode will be abandoned if the computer tries to generate a line number greater than 32767.

Examples

AUTO

AUTO 220

AUTO 105,5

Syntax

AUTO[<num-const>[,<num-const>]]

Description

AUTO is a command allowing the user to enter lines without first typing in the number of the line. Because AUTO is a command it cannot form part of a multiple statement line. AUTO mode can be left by pressing ESCAPE or by generating a line number exceeding 32767.

AUTO may have up to two arguments. The first optional argument gives the starting line number and the second optional argument gives the increment between line numbers.

Exit: BBC Microcomputer User Guide; Kasoft Typesetting; Archer


The BBC Microcomputer User Guide was written by John Coll and edited by David Allen for the British Broadcasting Corporation.

Optical character recognition and original formatting effort by Mark Usher.

HTML version maintained by: Kade "Archer" Hansson; e-mail: archer@dialix.com.au

Last updated: Monday 12th February 2001