Jump to content

MBASIC

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Wtshymanski (talk | contribs) at 22:55, 21 November 2004. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

MBASIC is the Microsoft BASIC implementation of the BASIC programming language for the CP/M operating system. MBASIC was part of Microsoft's BASIC-80 family which ran on the 8-bit Intel 8080 processors, and is a descendant of the original paper tape BASIC interpreters that were among Microsoft's first products. MBASIC was one of the two versions of BASIC bundled with the Osborne 1 computer.

Unlike versions of Microsoft BASIC-80 that were customized by manufacturers to use the particular hardware features of the computer, MBASIC relied only on the CP/M operating system calls for all its I/O. MBASIC in the uncustomized form had no functions for graphics, color, joysticks, mice, serial communications, networking, sound, or even a real-time clock function. MBASIC did not fully support the features of the host CP/M operating system, lacking any support for user areas. Since CP/M systems were typically single-user and stand alone, there was no provision for file or record locking or any form of multitasking. Apart from these limitations MBASIC was considered at the time to be a powerful and useful implementation of BASIC.

MBASIC was an interpreter. Program source text was stored in memory in tokenized form, with BASIC keywords replaced by one-byte tokens which saved memory space and speeded execution. Programs could be listed on the screen for editing, or saved to disk in either a compressed binary format or as plain ASCII text. Every source line was identified with a number, which could be used at the target of a GOTO transfer. Only on-screen line editing commands were provided - no full-screen cursor-addressing editing was available owing to the limitations of support in the host operating system.

Program text, variables, disk buffers and the CP/M operating system itself all had to share the 64 kilobyte address space of the 8080 processor. Typically when first starting MBASIC there would be less than 32 kB memory available for programs and data, even on a machine equipped with a full 64 kilobytes of RAM. To allow larger and more complex programs to be run, later versions of MBASIC supported functions that allowed portions of program text to be read in and executed under program control (the "CHAIN" and "MERGE" statements). No support for "shell" command excution was provided, though this functionality could be duplicated by a determined programmer.

Data could be read and stored to disk as either sequential files (delimited by the CP/M convention of CR/LF at the end of each line) or else as fixed-record-length random access files, which, given a sufficiently determined programmer, could be used to perform database-type record manipulation. The binary format for floating-point numbers was proprietary to the implementation, which meant that data could only be interchanged with other programs using ASCII text representation or else extensive programming to convert the binary format.

MBASIC supported the following data types:

* 8-bit character data, in strings of length 0 to 255 characters,
* 16-bit integers, 
* 32-bit floating point (single precision),equivalent to six decimal digits, with a two-digit exponent,
* 64-bit floating point (double precision), equivalent to sixteen decimal digits,with a two-digit exponent.


String operators included substring selection, concatenation, assignment, and testing for equality.

Arrays of the above types were allowed with up to 7 dimensions, but no functions were provided that operated on arrays.

Unlike some other BASIC implementations of the time, MBASIC did not provide support for matrix operations, complex numbers, or a BCD data type for financial calculations.

All floating point operations were carried out in software since typically CP/M systems did not have hardware for floating point. The built-in mathematics functions only operated in single precision (sine, cosine, tangent, natural log, exponential). A software [pseudo-random number generator] was provided, but this relied on the user to key in a random number seed to obtain random numbers useful for games and some simulations.

A particular advantage of MBASIC was the full-text error messages provided for sytax and run-time errors. MBASIC also had a "trace" function that displayed line numbers as they were executed.

Program flow control in MBASIC was controlled by IF...THEN... ELSE... conditional tests, WHILE...WEND loops, and GOTO and GOSUB instructions. No CASE statement was available, although an ON...GOTO... provided multi-way branches. Subroutines had no parameters and all variables were global.

No discussion of BASICs on the 8-bit computers of the late '70s and early '80s would be complete without mentioning the importance of the PEEK and POKE functions for directly reading and writing to memory. Since these systems typically had no memory protection, this allowed a programmer to access portions of the operating system or functions that would not otherwise be available. Of course this also provided unlimited opportunities for user programs to hang the system. For example, a CP/M programmer might use a POKE function to allow BASIC to switch the console device to the serial port, if the system [BIOS] supported this. For machines with real-time clocks, a set of PEEK instructions might have been used to access the time. For more complex operations, MBASIC allowed user-defined functions that could be called from a BASIC program. These were typically placed in a reserved area of memory or POKEd into string constants. MBASIC also provided hardware INP and OUT instructions that read and wrote directly to the 8080 hardware input/output ports. This could be used to control peripheral devices, though on at least one common CP/M system, the Osborne 1, all I/O instructions were pre-empted for use by the system.

Microsoft also sold a BASIC compiler (known as BASCOM) which used a similar source language to MBASIC. A program debugged under MBASIC could be compiled with BASCOM and would gain access to more memory and speed increases of 8 to 10 fold.

MBASIC was an important tool during the era of 8-bit CP/M computers. Skilled users could write routines in MBASIC to automate tasks that in modern-day systems would be performed by powerful application program commands or scripting languages. Exchange of useful MBASIC programs was a common function of computer user groups. Keying in long BASIC listings from a magazine article was a common way of "bootstrapping" software into a new CP/M system. At least one compiler for a high-level language was written in MBASIC, and many small games and utility programs ranging from a few lines to a few thousand lines of code were written.

--Wtshymanski 22:55, 21 Nov 2004 (UTC)