Skip to main content

MIX Assembly Language Simulator

Project description

MIXAL

Unit Tests Deploy Build Status Coverage Status Version Downloads License

[中文|English]

A MIX assembly language simulator.

Install

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

Sample

A sample code that finds the maximum value:

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.loadCodes([
    '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.memoryAt(i).set(val)
    max_val = max(max_val, val)
# Execute until the HLT operation
computer.executeUntilHalt()
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())

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

Uploaded Source

File details

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

File metadata

  • Download URL: mixal-1.168.14.tar.gz
  • Upload date:
  • Size: 516.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for mixal-1.168.14.tar.gz
Algorithm Hash digest
SHA256 3e47c994a730b53a5d560d2db0a3535f418527efa82e2165f0183fc67577ff4c
MD5 390b25d1dcd1afcdf2241e573b640c93
BLAKE2b-256 c38bdec1ed053019941f11a7e0a0c66d52fbc5a28f1b2b6393ae7981b9de10ab

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