Skip to main content

MIX Assembly Language Simulator

Project description


Unit Tests Deploy Build Status Coverage Status Version Downloads License


A MIX assembly language simulator.


Make sure you have a C++ 11 compiler and execute:

pip install mixal

For MacOS users, you may need to use:

MACOSX_DEPLOYMENT_TARGET=10.9 pip install mixal


Following is a piece of sample code that finds the maximum value. There are upper-case letters in the names of functions and attributes as the codes were written with C++.

import random
import mixal

# Initialize an environment
computer = mixal.Computer()

# The location for register J
end_point = 3500

# Load the assembly codes.
# Note that the location for register J is set to HLT
# to make sure the codes halt eventually
    'X       EQU  1000',
    '        ORIG 3000',
    'INIT    ENT3 0,1',
    '        JMP  CHANGEM',
    'LOOP    CMPA X,3',
    '        JGE  *+3',
    'CHANGEM ENT2 0,3',
    '        LDA  X,3',
    '        DEC3 1',
    '        J3P  LOOP',
    'EXIT    JMP  *',
    '        ORIG {}'.format(end_point),
    '        HLT',

num_numbers, max_val = 100, 0
# Register I1 denotes the number of integers in the memory buffer
# Register J stores the returning location
for i in range(1001, 1001 + num_numbers):
    val = random.randint(0, 100000)
    # Set random values to memory
    max_val = max(max_val, val)
# Execute until the HLT operation
print('Expected:', max_val)
# Register A stores the final maximum value
print('Actual:', computer.rA.value())
# The units of time for executing the codes, exclude the halt operation.
print('Compute Cost:', computer.elapsed())

IO Devices

There are several pre-defined IO devices in the environment. You can set the initial values of the input devices before the execution. Following is the code that reads one word from the input device and writes the same one to the output device.

import mixal

# Initialize an environment
computer = mixal.Computer()

# Pre-defined indices for IO devices
card_reader_index = 16
card_punch_index = 17

        ORIG 3000
        IN   100(16)
LIN     JBUS LIN(16)
        OUT  100(17)
# Set the initial value of input device
computer.getDeviceWordAt(card_reader_index, 0).set('PRIME')
# Check the output text of the output device
print(computer.getDeviceWordAt(card_punch_index, 0).getCharacters())

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mixal-1.178.15.tar.gz (518.1 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page