MBASIC
Encyclopedia
MBASIC is the Microsoft BASIC
Microsoft BASIC
Microsoft BASIC was the foundation product of the Microsoft company. It first appeared in 1975 as Altair BASIC, which was the first BASIC, and the first high level programming language available for the MITS Altair 8800 hobbyist microcomputer....

 implementation of BASIC
BASIC
BASIC is a family of general-purpose, high-level programming languages whose design philosophy emphasizes ease of use - the name is an acronym from Beginner's All-purpose Symbolic Instruction Code....

 for the CP/M
CP/M
CP/M was a mass-market operating system created for Intel 8080/85 based microcomputers by Gary Kildall of Digital Research, Inc...

 operating system. MBASIC is a descendant of the original Altair BASIC
Altair BASIC
Altair BASIC was an interpreter for the BASIC programming language that ran on the MITS Altair 8800 and subsequent S-100 bus computers. It was Microsoft's first product , distributed by MITS under a contract...

 interpreters that were among Microsoft's first products. MBASIC was one of the two versions of BASIC bundled with the Osborne 1
Osborne 1
The Osborne 1 was the first commercially successful portable microcomputer, released on April 3, 1981 by Osborne Computer Corporation. It weighed 10.7 kg , cost USD$ 1795, and ran the then-popular CP/M 2.2 operating system...

 computer. The name "MBASIC" is derived from the disk file name of the BASIC interpreter.

Environment

MBASIC version 5 required a CP/M system with at least 28 kB of random access memory (RAM) and at least one diskette drive.

Unlike versions of Microsoft BASIC-80 that were customized by home computer
Home computer
Home computers were a class of microcomputers entering the market in 1977, and becoming increasingly common during the 1980s. They were marketed to consumers as affordable and accessible computers that, for the first time, were intended for the use of a single nontechnical user...

 manufacturers to use the particular hardware features of the computer, MBASIC relied only on the CP/M operating system calls for all input and output. Only the CP/M console (screen and keyboard), line printer, and disk devices were available.

MBASIC in the uncustomized form had no functions for graphics
Computer graphics
Computer graphics are graphics created using computers and, more generally, the representation and manipulation of image data by a computer with help from specialized software and hardware....

, color, joysticks, mice, serial communications
Serial port
In computing, a serial port is a serial communication physical interface through which information transfers in or out one bit at a time...

, networking
Ethernet
Ethernet is a family of computer networking technologies for local area networks commercially introduced in 1980. Standardized in IEEE 802.3, Ethernet has largely replaced competing wired LAN technologies....

, sound, or even a real-time clock function. MBASIC did not fully support the features of the host CP/M operating system, for example, it did not support CP/M's user areas for organizing files on a diskette. 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
Computer multitasking
In computing, multitasking is a method where multiple tasks, also known as processes, share common processing resources such as a CPU. In the case of a computer with a single CPU, only one task is said to be running at any point in time, meaning that the CPU is actively executing instructions for...

. Apart from these limitations, MBASIC was considered at the time to be a powerful and useful implementation of BASIC.

Language system

MBASIC is an interpreter
Interpreter (computing)
In computer science, an interpreter normally means a computer program that executes, i.e. performs, instructions written in a programming language...

. Program source text was stored in memory in tokenized
Bytecode
Bytecode, also known as p-code , is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code...

 form, with BASIC keywords replaced by one-byte tokens which saved memory space and speeded execution. Any line prefixed with a line number was stored as program text; BASIC statements not prefixed with a line number were executed immediately as commands. Programs could be listed on the screen for editing, or saved to disk in either a compressed binary format or as plain ASCII
ASCII
The American Standard Code for Information Interchange is a character-encoding scheme based on the ordering of the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that use text...

 text. Every source line was identified with a number, which could be used as the target of a GOTO
Goto
goto is a statement found in many computer programming languages. It is a combination of the English words go and to. It performs a one-way transfer of control to another line of code; in contrast a function call normally returns control...

 or GOSUB
GOSUB
GOSUB is a command in many versions of the BASIC computer programming language. A GOSUB statement jumps to a line elsewhere in the program. That line and the following lines up to a RETURN are used as a simple kind of a subroutine without parameters or local variables.The GOSUB command may be used...

 transfer. Only line editing commands were provided. It was often beneficial to save a program as plain text and edit it with a full featured editor.

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. Comment lines, prefixed with the REM keyword or an apostrophe, could be placed in the program text but took up valuable memory space, which discouraged BASIC users from fully documenting their code. 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
Chain loading
Chain loading is a method used by computer programs to replace the currently executing program with a new program, using a common data area to pass information from the current program to the new program. It occurs in several areas of computing.Chain loading is similar to the use of overlays...

" and MERGE statements). No support for "shell" command execution was provided, though this functionality could be duplicated by a determined programmer.

A particular advantage of MBASIC was the full-text error messages provided for syntax and run-time errors. MBASIC also had a "trace" function that displayed line numbers as they were executed. While this occupied the same screen space as normal program output, it was useful for detecting conditions such as endless loop
Endless Loop
Endless Loop is overall, the fifth EP by Japanese singer Eiko Shimamiya but this is her second EP produced by both I've Sound and Geneon Entertainment. It was released on December 14, 2005...

s.

Files and input/output

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 Microsoft Binary Format
Microsoft Binary Format
In computing, Microsoft Binary Format was a format for floating point numbers used in Microsoft's BASIC language products including MBASIC, QuickBasic and GW-BASIC....

 for floating point
Floating point
In computing, floating point describes a method of representing real numbers in a way that can support a wide range of values. Numbers are, in general, represented approximately to a fixed number of significant digits and scaled using an exponent. The base for the scaling is normally 2, 10 or 16...

 numbers was proprietary to the implementation, which meant that data could only be interchanged with other programs using ASCII text representation or else with extensive programming to convert the binary format.

Variables and data types

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
    Floating point
    In computing, floating point describes a method of representing real numbers in a way that can support a wide range of values. Numbers are, in general, represented approximately to a fixed number of significant digits and scaled using an exponent. The base for the scaling is normally 2, 10 or 16...

     (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 or operators worked on arrays; for example, there was no assignment of arrays. Unlike some other BASIC implementations of the time, MBASIC did not provide support for matrix
Matrix (mathematics)
In mathematics, a matrix is a rectangular array of numbers, symbols, or expressions. The individual items in a matrix are called its elements or entries. An example of a matrix with six elements isMatrices of the same size can be added or subtracted element by element...

 operations, complex number
Complex number
A complex number is a number consisting of a real part and an imaginary part. Complex numbers extend the idea of the one-dimensional number line to the two-dimensional complex plane by using the number line for the real part and adding a vertical axis to plot the imaginary part...

s, or a decimal (BCD) data type for financial calculations. All floating point operations were carried out in software since typical CP/M systems did not have floating point hardware. The built-in mathematics functions (sine, cosine, tangent, natural log, exponential, square root) only gave single precision results. A software pseudorandom number generator
Pseudorandom number generator
A pseudorandom number generator , also known as a deterministic random bit generator , is an algorithm for generating a sequence of numbers that approximates the properties of random numbers...

 was provided; this relied on the user to key in a seed number to obtain a sequence of numbers useful for games and some simulations. MBASIC permitted but did not require the LET keyword for assignment statements.

Early versions of BASIC on microcomputers were infamous for one- or two-character variable names, which made the meanings of variables difficult to recall in complex programs. MBASIC version 5 allowed identifiers up to 40 characters long, which permitted programmers to give variables readable names.

Program flow control

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... (computed GOTO) provided multi-way branches. Subroutines had no parameters and all variables were global. MBASIC did not make structured programming
Structured programming
Structured programming is a programming paradigm aimed on improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures and for and while loops - in contrast to using simple tests and jumps such as the goto statement which could...

 mandatory for programmers and it was easy to write spaghetti code
Spaghetti code
Spaghetti code is a pejorative term for source code that has a complex and tangled control structure, especially one using many GOTOs, exceptions, threads, or other "unstructured" branching constructs. It is named such because program flow tends to look like a bowl of spaghetti, i.e. twisted and...

.

PEEKs, POKEs, and user functions

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
PEEK and POKE
In computing, PEEK is a BASIC programming language extension used for reading the contents of a memory cell at a specified address. The corresponding command to set the contents of a memory cell is POKE.-Statement syntax:...

 functions for directly reading and writing to memory. Since these systems typically had no memory protection
Memory protection
Memory protection is a way to control memory access rights on a computer, and is a part of most modern operating systems. The main purpose of memory protection is to prevent a process from accessing memory that has not been allocated to it. This prevents a bug within a process from affecting...

, this allowed a programmer to access portions of the operating system, or functions that would not otherwise be available. This also provided 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
BIOS
In IBM PC compatible computers, the basic input/output system , also known as the System BIOS or ROM BIOS , is a de facto standard defining a firmware interface....

 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, as a series of machine codes (op codes). 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.

Any MBASIC programs that made use of PEEK and POKE, and of machine code
Machine code
Machine code or machine language is a system of impartible instructions executed directly by a computer's central processing unit. Each instruction performs a very specific task, typically either an operation on a unit of data Machine code or machine language is a system of impartible instructions...

 user functions, were not portable between machines.

Successors to MBASIC

Microsoft also sold a CP/M BASIC compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

 (known as BASCOM) which used a similar source language to MBASIC. A program debugged under MBASIC could be compiled with BASCOM. Since program text was no longer in memory and the run-time elements of the compiler were smaller than the interpreter, more memory was available for user data. Speed of program execution increased by 8 to 10 fold.

All the functions of CP/M MBASIC were available in the IBM PC disk-based BASICA or GWBASIC which made migration of programs from CP/M systems to PC-compatibles possible. The tokens used to represent keywords were different, so CP/M programs had to be saved in ASCII source form. Typically screen formatting escape sequences put into the CP/M version would be replaced with the cursor positioning commands found in the PC versions of BASIC, otherwise little rewriting would be needed.

Importance of MBASIC

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 users' group
Users' group
A users' group is a type of club focused on the use of a particular technology, usually computer-related....

s. Keying in long BASIC listings
Type-in program
A type-in program, or just type-in, is a computer program listing printed in a computer magazine or book, meant to be typed in by the reader in order to run the program on a computer....

 from a magazine article was one 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.

Other uses

MBASIC is also the name of a commercial BASIC
BASIC
BASIC is a family of general-purpose, high-level programming languages whose design philosophy emphasizes ease of use - the name is an acronym from Beginner's All-purpose Symbolic Instruction Code....

 compiler for the Microchip Technology
Microchip Technology
Microchip Technology is an American manufacturer of microcontroller, memory and analog semiconductors. Its products include microcontrollers , Serial EEPROM devices, Serial SRAM devices, KEELOQ devices, radio frequency devices, thermal, power and battery management analog devices, as well as...

 PIC microcontroller
PIC microcontroller
PIC is a family of Harvard architecture microcontrollers made by Microchip Technology, derived from the PIC1650 originally developed by General Instrument's Microelectronics Division...

family developed by Basic Micro, Inc., unrelated to the CP/M interpreter.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK