Misplaced Pages

Acorn System BASIC

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.

Acorn System BASIC and Atom BASIC are two closely related dialects of the BASIC programming language developed by Acorn Computers for their early microcomputers like the Acorn System 3 and Acorn Atom . Developed in-house, they have a number of significant idiosyncrasies compared to most BASIC dialects of the home computer era.

#215784

63-414: In particular, the language lacked statements for many of the machine's internal functions and provided this using direct access and manipulation of memory locations using indirection operators instead of PEEK and POKE . Both also lacked floating-point support, although this could be added with an optional ROM which introduced further idiosyncrasies. System and Atom BASIC differ primarily in that Atom used

126-530: A stack ). Upon completion of the subroutine, this return address is restored to the PC, and so program execution resumes with the instruction following the call instruction. The third type of machine level branch is the return instruction . This "pops" a return address off the stack and loads it into the PC register, thus returning control to the calling routine. Return instructions may also be conditionally executed. This description pertains to ordinary practice; however,

189-446: A conditional branch , which may or may not cause branching depending on some condition. Also, depending on how it specifies the address of the new instruction sequence (the "target" address), a branch instruction is generally classified as direct , indirect or relative , meaning that the instruction contains the target address, or it specifies where the target address is to be found (e.g., a register or memory location), or it specifies

252-413: A condition in the flag register. The earlier instruction may be arithmetic, or a logic instruction. It is often close to the branch, though not necessarily the instruction immediately before the branch. The stored condition is then used in a branch such as jump if overflow-flag set . This temporary information is often stored in a flag register but may also be located elsewhere. A flag register design

315-403: A continual form in memory, like arrays of numbers, the operators could be applied to the right-hand side of a variable. When used in this way, like A? , the system accessed the memory at the variable's location in memory. Any number following the operator was applied as an offset, so for instance, A?100 would return the value of the byte 100 locations after the location of A in memory. This

378-426: A fractional part, they added the % operator to return the remainder. For instance, PRINT 7/3 will return 2, while PRINT 7%3 will return 1. Variable names can consist only of a single letter, A to Z. All double-letter combinations are reserved as arrays, so E was a single value, while EE was an array. All arrays required a DIM statement, it did not assume a dimension of 10 like Microsoft BASICs . At runtime,

441-525: A header with the filename. Files saved with SAVE THISFILE could be read back in with LOAD THISFILE , whilst *CAT listed the names of the files on the cassette as it read past their headers. Arbitrary data could be opened for reading using FIN or writing with FOUT , both of which returned a numeric file handle . Files were closed with SHUT . Data was read or written in numeric format using GET, PUT , as single bytes with BGET, BPUT , and as strings using SGET, SPUT . The EXT returned

504-471: A number of device drivers . Atom BASIC had only a few changes from the System version, adding support for string manipulation and a small number of graphics commands. The Atom was upgradable, with up to 12 KB of RAM in total and an additional 4 KB of ROM that added floating-point support. This used separate functions and operations that worked on them, indicated by the % symbol. This choice of symbol

567-408: A number, PRINT $ A would read the values starting at that location and print it as a string. For instance: This code may appear very similar to the use of strings in other dialects, although the location of the $ relative to the variable name changes. It is especially similar to those dialects that required a DIM on all strings, like HP Time-Shared BASIC or Atari BASIC . Internally, the operation

630-427: A particular unchanging sequence. Conditional branch instructions make it impossible to know this sequence. So conditional branches can cause "stalls" in which the pipeline has to be restarted on a different part of the program. Several techniques improve speed by reducing stalls from conditional branches. Historically, branch prediction took statistics, and used the result to optimize code. A programmer would compile

693-558: A series of kit-built and Eurocard -based systems starting with the Acorn System 1 in 1979. They developed Acorn System BASIC for these machines, an integer-only dialect that required only 4 KB of memory in total. The language had a number of implementation details that made it "highly non-standard." The Atom , introduced in 1980, was built from parts of the System 3 packaged onto a single board. Systems shipped standard with 2 KB of RAM and 8 KB of ROM, which included BASIC and

SECTION 10

#1732863310216

756-505: A single lower-case letter typed immediately after the line number. For instance: The advantage of this method is that the memory address of the statement is stored in s, meaning that the branch, a GOTO, can move directly to that line without having to search through every line in the program looking for the matching line number. Acorn also allowed any expression to be used to produce the line number for branch targets, like GOSUB 500+(A*10) . Acorn's primitives were similar to other BASICs of

819-525: A string, as was the case for STR$ in other dialects, but in this case, the string was written to memory and the function returned the address where it was stored. As the string required storage long enough to hold it, this was often accomplished using TOP. For instance: This converts the value of the pseudo-variable PI to a string starting at memory location TOP, prints the string using $ TOP, and then abandons that memory. PRINT and INPUT mostly worked as in other dialects. One oddity came about because

882-516: A system reset, potentially clearing out the program from memory. To reset this if the key was pressed by mistake, Atom BASIC added the OLD command, which could also be used to reset an accidental NEW . A more minor change was that LIST used comma-separated to and from line numbers instead of the minus sign, LIST 20,40 prints out lines 20 to 40. The language also had the ability to use line labels instead of numbers for branching . Labels consisted of

945-495: A test version of a program, and run it with test data. The test code counted how the branches were actually taken. The statistics from the test code were then used by the compiler to optimize the branches of released code. The optimization would arrange that the fastest branch direction (taken or not) would always be the most frequently taken control flow path. To permit this, CPUs must be designed with (or at least have) predictable branch timing. Some CPUs have instruction sets (such as

1008-457: A variety of test programs. Good predictors usually count the outcomes of previous executions of a branch. Faster, more expensive computers can then run faster by investing in better branch prediction electronics. In a CPU with hardware branch prediction, branch hints let the compiler's presumably superior branch prediction override the hardware's more simplistic branch prediction. Some logic can be written without branches or with fewer branches. It

1071-428: Is often possible to use bitwise operations , conditional moves or other predication instead of branches. In fact, branch-free code is a must for cryptography due to timing attacks . Another technique is a branch delay slot . In this approach, at least one instruction following a branch is always executed, with some exceptions such like the legacy MIPS architecture likely/unlikely branch instruction. Therefore,

1134-679: Is simple in slower, simple computers. In fast computers a flag register can place a bottleneck on speed, because instructions that could otherwise operate in parallel (in several execution units ) need to set the flag bits in a particular sequence. There are also machines (or particular instructions) where the condition may be checked by the jump instruction itself, such as branch <label> if register X negative . In simple computer designs, comparison branches execute more arithmetic and can use more power than flag register branches. In fast computer designs comparison branches can run faster than flag register branches, because comparison branches can access

1197-490: Is suitable for many loops, when more control is needed, for instance when comparing against a more complex criterion, the IF statement may be used: The downside to this style of loop is that the branch requires the program to be searched through for line 500, which, in a loop, normally happens many times. In large programs, this can introduce significant overhead. Using a DO for this purpose offers higher performance: In this case, like

1260-486: Is the WAIT statement, which paused execution until the next clock tick, every 1 ⁄ 60 of a second. This does not wait for one entire tick, just until the next tick, which may happen immediately. LINK calls a machine language routine, the analog of CALL or SYS in most dialects. Acorn used 32-bit signed integers for all math, with no standard floating-point support. To handle division, which often returns

1323-501: Is very different. In those dialects, A and A$ are two different variables and the $ is, in effect, part of the name. In Acorn, A and $ A they are the same variable, and the $ is applying a unary operation to that variable. This also means one can use arrays for strings, like $ AA(10) , which converts the value in AA(10) to a string. This concept allows individual characters to be accessed using vector notation. For instance, A?5 would return

SECTION 20

#1732863310216

1386-469: The Power ISA ) that were designed with "branch hints" so that a compiler can tell a CPU how each branch is to be taken. The problem with software branch prediction is that it requires a complex software development process. To run any software, hardware branch predictors moved the statistics into the electronics. Branch predictors are parts of a processor that guess the outcome of a conditional branch. Then

1449-427: The assembly language mnemonic for a jump instruction is typically some shortened form of the word jump or the word branch , often along with other informative letters (or an extra parameter) representing the condition. Sometimes other details are included as well, such as the range of the jump (the offset size) or a special addressing mode that should be used to locate the actual effective offset. This table lists

1512-484: The ASCII value of the 5th character, 79 for O in this case, while PRINT $ A?5 would output "O". There is no way to extract a substring in a single operation, one has to loop over the characters and move them one-by-one. Concatenation is possible by assigning one variable to the end of another, for instance, $ A+LEN(A)=$ B copies the string B to the end of A. The language has only two string functions, LEN which looks for

1575-636: The FOR loop, the address of the DO is stored when the loop is entered, allowing the UNTIL to return to the top of the loop immediately without having to scan through the program. Note the special case that the DO can be followed directly by another statement without the semicolon separator being required - the A=A+1 is not part of the DO , it is a separate statement. Among the more minor additions

1638-642: The Wikimedia System Administrators, please include the details below. Request from 172.68.168.150 via cp1114 cp1114, Varnish XID 413527653 Upstream caches: cp1114 int Error: 429, Too Many Requests at Fri, 29 Nov 2024 06:55:10 GMT Branch (computer science) A branch , jump or transfer is an instruction in a computer program that can cause a computer to begin executing a different instruction sequence and thus deviate from its default behavior of executing instructions in order. Branch (or branching , branched ) may also refer to

1701-404: The act of switching execution to a different instruction sequence as a result of executing a branch instruction. Branch instructions are used to implement control flow in program loops and conditionals (i.e., executing a particular sequence of instructions only if certain conditions are satisfied). A branch instruction can be either an unconditional branch , which always results in branching, or

1764-403: The algorithm planned by the programmer. One type of machine level branch is the jump instruction . These may or may not result in the PC being loaded or modified with some new, different value other than what it ordinarily would have been (being incremented past the current instruction to point to the following, next instruction). Jumps typically have unconditional and conditional forms where

1827-399: The byte value at the 11th location in A (all accesses are zero-indexed). Likewise, one could store values in memory using the same operator applied before the variable name: This will convert the decimal value 123456 from ASCII into an integer and store it in the memory locations starting at the base location for A. To aid operation with vectors, Acorn added the pseudo-variable TOP . When

1890-424: The colon and semicolon were already used for other purposes, leaving only the comma to separate fields. To print values with no spaces between them, the values were listed with a space character between them, like PRINT A B C , a format that was also allowed on many other dialects although rarely used. This alone would not cause numbers to be printed in compact format, because they are normally printed with spaces on

1953-446: The colon for OR is why the statement separator had to use the semicolon. Note that these are separate from the logical connections found in IF statements, like IF A=1 AND B=0 THEN... , which are also supported. There were only two math functions, ABS and RND . ABS works as in other BASICs, returning the absolute value of a given input. RND does not, it returns a value between the -ve and +ve maximum integer values. To use this in

Acorn System BASIC - Misplaced Pages Continue

2016-445: The condition(s). All high level languages support algorithms that can re-use code as a loop , a control structure that repeats a sequence of instructions until some condition is satisfied that causes the loop to terminate. Loops also qualify as branch instructions. At the machine level, loops are implemented as ordinary conditional jumps that redirect execution to repeating code. In CPUs with flag registers , an earlier instruction sets

2079-403: The construction of bottom-tested, expression-based loops. FOR loops are highly optimized by using a direct comparison between their index variable and a constant value that is set only once upon entry into the loop. Another optimization is that the address of the FOR is stored, not the line number, so when the matching NEXT is encountered the program can immediately branch back to the FOR. While FOR

2142-416: The conventional form to return a value between 0 and a given positive value, between 0 and 10 for example, one used ABS(RND)%11 . Most BASICs of the era used PEEK and POKE to access machine specific functionality that was not built into the language itself. Acorn did not have PEEK and POKE, and used new operators to provide this functionality in an easier-to-use system. The operators were ? and ! ,

2205-446: The conversion. For instance, A=#4000 sets the value of A to the decimal value 16384, the location of the screen memory. This was often combined with the $ operator to allow strings to contain unprintable characters, like the "cursor up" character. Floating-point support could be added with the additional 4 KB ROM expansion. This used an expanded 40-bit word size, 32 bits of signed mantissa followed by an 8-bit exponent. This meant

2268-552: The cursor keys to move upward into a program listing, make changes on-screen, and then press Return to enter those changes. On the Atom, which had a full-screen display, one could move upward into a listing using the cursor keys , but to edit that text, the Copy key was pressed to copy it to the input area where it could be edited. Another difference on the Atom was the Break key, which performed

2331-428: The destination address relative to the current place in the program. The source of the displacement value may vary, such as an immediate value embedded within the instruction, or the contents of a processor register or memory location, or the contents of some location added to an index value. The term branch can also be used when referring to programs in high-level programming languages . In these branches usually take

2394-512: The difference between the current and target addresses. Branch instructions can alter the contents of the CPU 's Program Counter (or PC) (or Instruction Pointer on Intel microprocessors). The PC maintains the memory address of the next machine instruction to be fetched and executed. Therefore, a branch, if executed, causes the CPU to execute code from a new memory address, changing the program logic according to

2457-469: The era, and supported most of the elementary statements like CLEAR, DIM, END, FOR..TO..STEP..NEXT , GOSUB , GOTO , IF..THEN , INPUT, (optional) LET, LIST, LOAD, PRINT, REM , RETURN , RUN, SAVE, STOP . There are a number of common statements that are missing, notably DATA, READ, RESTORE used to store data in a program, ON..GOSUB, ON..GOTO computed branches , and DEF FN for user-defined functions. To these basics, Acorn added DO..UNTIL for

2520-449: The form of conditional statements of various forms that encapsulate the instruction sequence that will be executed if the conditions are satisfied. Unconditional branch instructions such as GOTO are used to unconditionally jump to a different instruction sequence. If the algorithm requires a conditional branch, the GOTO (or GOSUB subroutine call) is preceded by an IF-THEN statement specifying

2583-441: The former setting or returning the byte at a given location, and the latter setting or returning a 4-byte "word". For instance, common examples of PEEK in most dialects, like PRINT PEEK(4000) , could be accomplished with PRINT ?4000 . Most dialects lacked the equivalent of the !. Moreover, the same syntax could be used to set the value in memory, like a POKE, for instance, ?4000=200 . To aid in accessing data arranged in

Acorn System BASIC - Misplaced Pages Continue

2646-426: The latter may be taken or not taken (the PC is modified or not) depending on some condition. The second type of machine level branch is the call instruction which is used to implement subroutines . Like jump instructions, calls may or may not modify the PC according to condition codes, however, additionally a return address is saved in a secure place in memory (usually in a memory resident data structure called

2709-466: The length of the file, while PTR returned or set the current pointer in the file, the number of bytes read or written so far. If the floating-point ROM was present, it added FGET, FPUT . For instance: Will use the BPUT to write a series of bytes, 88s, until the user presses Escape to stop the program. They can then be read back in (after manually rewinding the tape) using: The dollar sign tells

2772-526: The machine level branch or jump instructions found in several well-known architectures: x86, the PDP-11, VAX, and some others, set the carry-flag to signal borrow and clear the carry-flag to signal no borrow . ARM, 6502 , the PIC, and some others, do the opposite for subtractive operations. This inverted function of the carry flag for certain instructions is marked by ( ), that is, borrow= not carry in some parts of

2835-436: The machine programmer has considerable powers to manipulate the return address on the stack, and so redirect program execution in any number of different ways. Depending on the processor, jump and call instructions may alter the contents of the PC register in different ways. An absolute address may be loaded, or the current contents of the PC may have some value (or displacement) added or subtracted from its current value, making

2898-462: The only check performed on an array was that the index being passed in was a positive value, so one could read off into memory by passing in values larger than the dimension. It did not support multi-dimensional arrays. Basic math operations included +, -, *, /, % . It also supported bitwise logic operators, with &, \, : used for AND, OR and XOR, respectively. These operators perform comparisons, so 1 & 0 returns 0. The use of

2961-473: The processor's logic gambles on the guess by beginning to execute the expected instruction flow. An example of a simple hardware branch prediction scheme is to assume that all backward branches (i.e. to a smaller program counter) are taken (because they are part of a loop), and all forward branches (to a larger program counter) are not taken (because they leave a loop). Better branch predictors are developed and validated statistically by running them in simulation on

3024-426: The registers with more parallelism, using the same CPU mechanisms as a calculation. Some early and simple CPU architectures, still found in microcontrollers, may not implement a conditional jump, but rather only a conditional "skip the next instruction" operation. A conditional jump or call is thus implemented as a conditional skip of an unconditional jump or call instruction. Depending on the computer architecture ,

3087-432: The right to make each one 8 characters wide This could be adjusted by changing the value in the @ pseudo-variable. A newline was printed with a single quote, PRINT "HELLO" ' "WORLD" . COUNT returns the cursor column, similar to POS in most dialects. The default storage device for the Atom was a compact cassette system. Each file was stored as a series of blocks, each of which contained

3150-473: The same indirection system to provide rudimentary string manipulation, which Standard lacked, and added a small number of new statements for computer graphics . Most of these oddities were removed when the underlying system was greatly expanded to produce BBC BASIC on the Atom's successor, the BBC Micro . BBC BASIC ROMs were later offered to Atom users. Acorn Computers formed in 1978 and got its start making

3213-539: The screen, MOVE moved the graphical cursor to the given X,Y location, and DRAW drew a line from the current location to the provided X,Y. The floating-point ROM also included support for colour graphics with the addition of the COLOUR statement. Calling COLOUR with a parameter 0 through 3, sets the subsequent output to that colour. On a black-and-white display, the colours were shown as shades of grey. PEEK and POKE Too Many Requests If you report this error to

SECTION 50

#1732863310216

3276-529: The stored program. One idiosyncrasy was that while it allowed multiple statements on a single line, the separator between statements was the semicolon instead of the commonly used colon, thus requiring the user to convert that character when typing in programs for other computers. Intended for use with computer terminals , Acorn BASIC did not support a full-screen editing mode. For contrast, in Commodore BASIC (and many other microcomputer dialects), one can use

3339-412: The system first started up, it pointed to the first location past the end of the program. Any DIMs were then created at the current value of TOP, and TOP was then updated to the end of the new object. It was possible to create dynamic vectors by directly manipulating TOP. Atom BASIC added string support but did not support string variables nor did it have the concept of a string as an atomic type. Instead,

3402-446: The system needed some way to distinguish the data when reading and writing from memory, which was handled in a fashion similar to the string operator, using the % prefix: As the code was contained in a separate 4 KB ROM, it did not modify existing statements like PRINT. Instead, an entirely new set of statements was introduced, including FDIM, FIF, FINPUT, FPRINT, FUNITL . This means, for instance, that one cannot IF A=B if

3465-436: The system to convert the incoming binary data to string format, so in this case, the output will be a series of X's, not 88's. It might seem that SGET could be used instead of BGET, but this would attempt to continue reading from the file until it saw a return character, which in this example had not been written. The Atom had rudimentary bitmap graphics and Atom BASIC added a number of commands to support it. CLEAR cleared

3528-438: The table, but if not otherwise noted, borrow≡carry. However, carry on additive operations are handled the same way by most architectures. To achieve high performance, modern processors are pipelined . They consist of multiple parts that each partially process an instruction, feed their results to the next stage in the pipeline, and start working on the next instruction in the program. This design expects instructions to execute in

3591-460: The time, there were comments that it should definitely not use Acorn's variety of BASIC, which "virtually no other microcomputer can understand" and that "If the new language were based on the Atom's form of BASIC, it would be a disaster." Ultimately, the BBC system did use those older Acorn-written BASIC variants, but heavily modified. The resulting BBC BASIC was much more similar to Microsoft BASIC and

3654-401: The trailing return character and returned the length, and CH to return the ASCII value of a character. CH has an odd format with no parens, so CH"A" would return 65. It is otherwise similar to the more common ASC seen in other dialects. Another new operator was # , which converted a numeric value into a hexadecimal string. Like $ , this could be used anywhere to perform

3717-443: The values are floating point, one must instead FIF A=B THEN... . An integer value can be converted to float using the FLT , and float to integer using the float operator, %. The ROM also included a much larger variety of math functions, including ABS, ACS, ASN, ATN, COS, DEG, EXP, FLT, HTN, LOG, PI, RAD, SGN, SIN, SQR, STR, TAN, VAL . STR converted a floating-point number into

3780-409: The vector system was used to manipulate string data in memory, as ASCII values. To aid this usage, the $ operator converted in-memory values to their ASCII values. This operator continued reading data from memory until it encountered a return, and when writing data to memory, always added a return at the end. So while PRINT ?A would print the single value of the byte at A's location in memory as

3843-428: Was later offered as an upgrade to the Atom. As the two dialects are very similar, the following will refer to Atom BASIC primarily and point out differences where they exist. Like most BASICs of the era, Atom BASIC used a line-oriented editor with direct (immediate) and indirect modes. Typing in a statement without a line number performed the operation immediately. Adding a line number instead placed those statements in

SECTION 60

#1732863310216

3906-476: Was often used with another Acorn-only concept, the "vector". Confusingly, these were created using the same DIM commands as an array, but applied to single-letter variables. When the DIM was encountered the system would set aside that many locations at the top of memory, and then move the memory pointer up. This left a block of memory that could then be accessed with the indirection operators. For instance: Which will print

3969-451: Was unfortunate, as Microsoft BASIC used the percent sign to indicate integers, not floating point. The Atom was on the market for only a short period before Acorn began development of its successor, the Proton. This was initially to be a two-processor unit. The design was still in its earliest stages when a series of events led to it being selected as the basis of the single-CPU BBC Micro . At

#215784