Jump to content

MBASIC

From Alfawiki
Microsoft MBASIC
Company typeSoftware
IndustryComputer software
Founded1970s
FounderMicrosoft
ProductsMBASIC (BASIC interpreter for CP/M)

MBASIC represents Microsoft's version of BASIC designed for the CP/M operating system, tracing its origins back to the original Altair BASIC interpreters, which were among the company’s first software offerings. It was included as one of two BASIC interpreters provided with the Osborne 1 machine. The designation "MBASIC" comes from its executable file name, MBASIC.COM. This interpreter and its related 8-bit variants drew inspiration from Digital Equipment Corporation's BASIC-PLUS used on the PDP-10 platform.

Environment

Running MBASIC version 5 necessitated a CP/M environment equipped with a minimum of 28 KB RAM and a disk drive.

In contrast to Microsoft BASIC-80 versions customized by various home computer manufacturers for particular hardware, MBASIC depended exclusively on CP/M system calls for input and output operations, supporting only the CP/M console, line printer, and disk storage devices.

The standard MBASIC release did not include capabilities for graphics, color display, joystick or mouse input, serial communication, networking, audio output, or real-time clock functions. It also did not fully utilize certain CP/M features such as user areas for file management. Given CP/M’s design as a single-user, non-multitasking operating system, features like file locking or concurrent processing were absent. Nevertheless, MBASIC was recognized as a robust and practical BASIC interpreter during its era.

Language system

MBASIC operates as an interpreter that stores program code in a tokenized format to conserve memory and enhance execution speed. Lines assigned numbers were saved as part of the program text; conversely, unnumbered lines executed immediately as commands. Users could list program code, edit individual lines, or save programs either in compressed binary form or as plain ASCII text. Line numbers functioned as jump targets for GOTO and GOSUB instructions. Full-screen editing was not built-in but could be implemented through external terminal-specific configurations; many programmers preferred to edit saved plain text files using external editors.

The Intel 8080 processor’s 64 KB address space was divided among program instructions, variables, disk buffers, and the operating system itself—leaving generally less than 32 KB available for user programs even on fully configured systems. Comment lines introduced via REM or apostrophe statements occupied memory space, which limited the extent of inline documentation.

To accommodate larger applications, subsequent MBASIC versions allowed dynamic loading of code segments through CHAIN and MERGE commands. Although there was no direct support for executing shell commands from within MBASIC, experienced developers could simulate this functionality.

A distinctive feature of MBASIC was its comprehensive textual error reporting for both syntax and runtime errors. Additionally, it included a trace facility that displayed line numbers during execution—an aid in debugging issues such as infinite loops—though this shared screen space with program output.

Files and input/output

Data handling supported sequential file access using CP/M’s carriage return/line feed (CR/LF) line endings as well as fixed-length random access files that enabled record-based data management akin to simple databases when programmed appropriately. Floating point numbers were stored in Microsoft’s proprietary Binary Format, which limited interoperability with other systems unless data was converted into ASCII text or complex transformations were applied.

Variables and data types

Supported data types in MBASIC included:

  • Character strings up to 255 characters (8-bit)
  • Integers occupying 16 bits
  • Single-precision floating point numbers using 32 bits (approximately six decimal digits)
  • Double-precision floating point numbers using 64 bits (about sixteen decimal digits)

String manipulation encompassed substring extraction, concatenation, assignment operations, and equality comparisons. Arrays could have up to seven dimensions but lacked dedicated functions or array-wide assignments. Unlike some contemporaneous BASIC dialects, MBASIC did not offer built-in support for matrix mathematics, complex number calculations, or decimal (BCD) data types commonly used in financial applications. Floating point arithmetic was performed entirely in software due to typical hardware constraints on CP/M machines; built-in mathematical routines returned single-precision results. The pseudorandom number generator required users to provide initial seeds for use in simulations or games. The use of the LET keyword for variable assignment was optional.

Earlier microcomputer BASIC implementations often restricted variable names to very short identifiers that reduced readability; MBASIC version 5 extended allowable identifier length up to 40 characters, significantly enhancing code clarity and maintainability.

Control Structures for Program Flow

MBASIC provided flow control through constructs such as IF...THEN...ELSE, WHILE...WEND loops, and the use of GOTO and GOSUB statements. Although it did not include a CASE statement, it allowed multi-branch decisions via the ON...GOTO command. Subroutines were parameterless, with all variables being global in scope, which offered programming flexibility but often led to unorganized code structures susceptible to spaghetti code.

Direct Memory Access and Custom Functions

Similar to many 8-bit systems from the late 1970s and early 1980s, MBASIC featured PEEK and POKE commands that granted direct access to memory locations. Without memory protection, users could alter operating system regions or restricted functions, occasionally resulting in system freezes. For instance, CP/M developers might utilize POKE instructions to redirect the BASIC console output to a serial port if supported by the system BIOS. Systems equipped with real-time clocks often relied on PEEK operations to retrieve the current time.

MBASIC allowed programmers to define their own functions callable within BASIC programs; these were usually stored in designated memory areas or embedded as machine code (opcodes) within string literals. The language also included hardware-level commands like INP and OUT, enabling direct control of I/O ports for peripheral device management when hardware permitted. However, programs utilizing PEEK, POKE, or embedded machine code functions lacked portability without modification.

MBASIC's Successor Versions

Besides Microsoft's BASIC-80 designed for CP/M, there was a version adapted for the ISIS-II operating system. The MSX-BASIC variant, developed for MSX computers, expanded on MBASIC's original features.

The full feature set of CP/M MBASIC was preserved in IBM PC disk-based interpreters such as BASICA and GWBASIC, easing transitions to PC-compatible platforms. Although tokenized keywords differed—necessitating CP/M programs be saved as ASCII source files—only minimal adjustments were needed aside from adapting commands related to screen display.

BASCOM Compiler

Microsoft offered BASCOM, a CP/M BASIC compiler closely mirroring MBASIC's syntax. Code developed and debugged in MBASIC could be compiled using BASCOM, resulting in roughly three times faster execution and freeing memory by eliminating interpreter overhead during runtime.

BASCOM gained preference over the slower and more complex CBASIC. Unlike CBASIC, BASCOM did not require a preprocessing step, allowing developers to debug interactively. Nonetheless, Microsoft faced criticism for imposing a 9% royalty fee per compiled binary along with a $40 hardware-software licensing charge, plus audit rights over developers' financial records. Considering typical software royalties ranged from 10–25%, InfoWorld cautioned in 1980 that these extra fees could undermine software profitability despite BASCOM’s technical benefits.

MBASIC's Significance

MBASIC played an essential role on 8-bit CP/M machines by enabling automation of tasks that contemporary systems now perform through sophisticated application commands or scripting languages. It facilitated software sharing within computer users' groups and supported "bootstrapping" through manual entry of lengthy BASIC listings published in magazines. Additionally, MBASIC served as a foundation for developing compilers targeting higher-level languages and hosted numerous small-scale games and utility programs ranging from brief scripts to extensive codebases.

Other applications

The term MBASIC is also used to identify a commercial BASIC compiler designed for the Microchip Technology PIC microcontroller series, developed by Basic Micro, Inc. This product is distinct and separate from the CP/M interpreter.

References

  • Thom Hogan and Mike Iannamico, Osborne 1 User's Reference Guide, (1982) Osborne Computer Corporation
  • David A. Lien, The BASIC Handbook, 2nd Edition Encyclopedia of the BASIC Computer Language, (1981), Compusoft Publishing
  • BASIC 80 Reference Manual, Microsoft Corporation, undated