Skip to main content

A MIX assembly language emulator..

Project description

MIXAL Emulator

A MIX assembly language emulator.

Online MIXAL Emulator

Install

Python (requires cmake):

pip install mixal

NPM:

node i mixal-emulator

Sample

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
computer.load_codes([
    'X       EQU  1000',
    '        ORIG 3000',
    'MAXIMUM STJ  EXIT',
    '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
computer.rI1.set(num_numbers)
# Register J stores the returning location
computer.rJ.set(end_point)
for i in range(1001, 1001 + num_numbers):
    val = random.randint(0, 100000)
    # Set random values to memory
    computer.memory_at(i).set(val)
    max_val = max(max_val, val)
# Execute until the HLT operation
computer.execute_until_halt()
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

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

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-2.1.0.tar.gz (60.9 kB view details)

Uploaded Source

File details

Details for the file mixal-2.1.0.tar.gz.

File metadata

  • Download URL: mixal-2.1.0.tar.gz
  • Upload date:
  • Size: 60.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for mixal-2.1.0.tar.gz
Algorithm Hash digest
SHA256 98c10c8dd73586556b23227230657d5991d7245c72cce1c35c59db813ecffda8
MD5 8e78dd111b3d442c09933b8a1426cc64
BLAKE2b-256 ce25aa04592e904aa6476a005e72b486e5d284567c921d53de181a5437fe9b28

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page