Jump to content

MBASIC.COM

From Alfawiki
Adapted from the English Wikipedia article MBASIC.COM, available under CC BY-SA 4.0Updated 9 August 2025
MBASIC
Company typeSoftware
IndustryComputer software
PredecessorAltair BASIC
Founded1970s
ProductsBASIC interpreter for CP/M

MBASIC represents Microsoft's version of BASIC designed for the CP/M operating system, originating from the early Altair BASIC interpreters, which were among Microsoft's initial offerings. This interpreter was included as one of two BASIC options provided with the Osborne 1 computer. The designation "MBASIC" is derived from its executable file name, MBASIC.COM. Similar to earlier 8-bit Microsoft BASIC interpreters, MBASIC was heavily influenced by Digital Equipment Corporation's PDP-10 BASIC-PLUS.

Environment

MBASIC version 5 demanded a CP/M environment equipped with a minimum of 28 KB of random-access memory (RAM) alongside a single diskette drive.

In contrast to tailored versions of Microsoft BASIC-80 that were customized by home computer manufacturers to support specific hardware features, MBASIC operated exclusively through CP/M system calls for input and output operations. Access was limited to the CP/M console (keyboard and screen), line printer, and disk storage devices.

The standard MBASIC package did not include capabilities for graphics, color display, joystick or mouse input, serial communication ports, networking functions, sound output, or real-time clock integration. It also did not fully leverage CP/M's user areas for file management. Since CP/M platforms were generally single-user and non-networked environments, MBASIC lacked file locking mechanisms and multitasking support. Despite these constraints, it remained a robust and practical BASIC interpreter during its era.

Language system

MBASIC functions as an interpreter that stores program source code in memory using tokenization—where BASIC keywords are replaced by single-byte tokens—to conserve memory and enhance execution speed. Lines assigned numbers were retained as part of the program text; lines without numbers executed immediately as direct commands. Programs could be displayed for editing or saved onto disk in either compressed binary form or plain ASCII text. Line numbers served both as identifiers for source lines and as destinations for control flow commands such as GOTO or GOSUB. Only line-level editing commands were supported natively; full-screen editing required separate terminal-specific software. Saving programs in plain text format allowed users to employ more sophisticated external editors.

Within the 64 KB addressable memory space of the 8080 CPU, program code, variables, disk buffers, and the CP/M operating system all coexisted. Typically, fewer than 32 KB remained available for user programs and data even on systems equipped with the full 64 KB RAM. Comment statements introduced with REM or apostrophes occupied valuable memory space, which discouraged extensive use of inline documentation.

To accommodate larger applications, later releases of MBASIC introduced dynamic loading of program segments through CHAIN and MERGE commands. Although it did not provide native support for executing shell commands directly, similar functionality could be simulated through programming techniques.

One notable benefit was MBASIC’s provision of comprehensive textual error messages during both syntax checking and runtime execution. Additionally, it incorporated a trace feature that displayed the currently executing line number—an aid for debugging infinite loops or other logic errors—though this trace output replaced the normal program display area.

Files and input/output

Data handling supported both sequential files formatted with CP/M-style carriage return/line feed (CR/LF) endings and fixed-length random access files, allowing database-like record manipulation when properly programmed. However, Microsoft’s proprietary binary format for floating-point numbers restricted data interchangeability to ASCII text unless complex conversion routines were implemented.

Data types and variables

MBASIC supported several data formats:

  • Character strings up to 255 characters using 8-bit encoding
  • 16-bit integer values
  • Single-precision floating-point numbers with 32 bits, offering approximately six decimal digits and a two-digit exponent
  • Double-precision floating-point numbers using 64 bits, providing sixteen decimal digits precision and a two-digit exponent

String manipulation included operations such as extracting substrings, concatenation, assignment, and equality checks. Arrays could have as many as seven dimensions; however, they lacked built-in operators or functions, and assigning arrays directly was not possible. Unlike some contemporary BASIC dialects, MBASIC did not feature matrix math, complex number support, or decimal (BCD) types commonly used in financial applications. Floating-point calculations were implemented in software due to the typical hardware constraints of CP/M systems. The language offered standard mathematical functions—such as sine, cosine, tangent, natural logarithm, exponential, and square root—returning results in single precision. A software-based pseudorandom number generator was included but required the user to provide a seed value.

The use of the LET keyword for variable assignment was optional in MBASIC. Early microcomputer BASIC interpreters limited variable name lengths; however, version 5 of MBASIC expanded identifier length to 40 characters, enhancing code clarity and maintainability.

Control structures

MBASIC provided standard control flow constructs including IF...THEN...ELSE, WHILE...WEND, GOTO, and GOSUB. Although it lacked a dedicated CASE statement, multi-way branching could be achieved using ON...GOTO. Subroutines did not accept parameters, and all variables were globally scoped. The absence of enforced structured programming often resulted in tangled "spaghetti" code.

Memory access commands and user-defined routines

Similar to other 8-bit platforms from the late 1970s to early 1980s, MBASIC included PEEK and POKE commands that allowed direct memory manipulation. Due to the lack of memory protection, users could access operating system memory or restricted areas at the risk of causing system instability. For instance, CP/M developers might employ POKE instructions to redirect the BASIC console output to a serial port if supported by the system BIOS. On systems equipped with real-time clocks, time information could be read via PEEK commands.

MBASIC also enabled user-defined functions callable within BASIC programs; these were commonly stored in reserved memory regions or embedded as machine code (opcodes) encoded within string literals. Additionally, hardware-level input/output operations were accessible through INP and OUT commands for direct control over 8080 processor I/O ports, allowing peripheral device management when supported by the hardware. Programs utilizing PEEK, POKE, or embedded machine code routines typically required adjustments to ensure compatibility when ported between different computer systems.

MBASIC derivatives

In addition to Microsoft's BASIC-80 designed for CP/M environments, there was a version adapted for the ISIS-II operating system.

One prominent successor was MSX-BASIC, which incorporated additional features specifically designed for MSX hardware.

All functionalities present in CP/M MBASIC were retained in IBM PC disk-based interpreters such as BASICA and GWBASIC, facilitating transitions from CP/M machines to IBM PC compatibles. Since token encoding differed between platforms, CP/M programs had to be saved as ASCII text source files. Escape sequences used for screen formatting were generally replaced by PC BASIC cursor control commands, requiring only minor modifications during porting.

BASCOM

Microsoft introduced a CP/M BASIC compiler known as BASCOM, which utilized a source language closely related to MBASIC. Programs initially debugged in MBASIC could be compiled using BASCOM, which conserved memory by removing the program text from RAM and minimized runtime overhead. This process resulted in an approximate threefold increase in execution speed.

BASCOM gained recognition as a quicker and more effective alternative to the widely used but slower CBASIC. Unlike CBASIC, BASCOM did not require a separate preprocessor for MBASIC source code, allowing for interactive debugging sessions. Nevertheless, in December 1980, analyst Jerry Pournelle expressed concerns about Microsoft's imposition of a 9% royalty fee on each compiled binary and an additional $40 charge when hardware was bundled with the software. Microsoft also maintained the right to audit developers’ financial records. Considering that typical software royalties ranged between 10% and 25%, InfoWorld cautioned that BASCOM’s extra 9% royalty might make software development financially unviable, concluding that while Microsoft had addressed CBASIC's technical limitations, its economic issues remained unresolved.

Importance of MBASIC

MBASIC played a crucial role for 8-bit CP/M systems by empowering proficient users to automate processes that contemporary platforms now manage through sophisticated application commands or scripting languages. The sharing of MBASIC programs was widespread within computer users' groups. Typing lengthy BASIC programs published in magazines was a common approach to "bootstrap" software onto new CP/M machines. Additionally, MBASIC facilitated the creation of at least one high-level language compiler along with numerous small-scale games and utilities, ranging from brief scripts to extensive programs consisting of thousands of lines.

Other uses

The name MBASIC is also associated with a commercial BASIC compiler designed for the Microchip Technology PIC microcontroller series by Basic Micro, Inc., which is unrelated to the CP/M interpreter version.