Skip to content

cseberino/simple

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple

a minimal computer emulator and assembler

The computer has 16 registers of which the first is the instruction pointer.
The computer supports 32 bit words, a 32 bit address space, and, the following
functions:

        add
        sub
        mult
        div
        and
        or
        zjump
        gjump
        copy
        load
        store
        stop

Instructions begin with four bits denoting functions followed by arguments.  All
arguments are four bits denoting registers except for the first copy function
argument which is 24 bits.

The following table describes the actions for all instructions.  r₁, r₂ and r₃
denote registers.  [r₁], [r₂] and [r₃] denote register values.  M(<address>)
denotes the memory words beginning at the given addresses.  ip denotes the
instruction pointer:

   instruction             storage data                         storage location

    add( r₁, r₂, r₃)        ([r₁] + [r₂]) % 2³²                  r₃
    sub( r₁, r₂, r₃)        ([r₁] - [r₂]) % 2³²                  r₃
    mult(r₁, r₂, r₃)        ([r₁] * [r₂]) % 2³²                  r₃
    div( r₁, r₂, r₃)        ([r₁] / [r₂]) % 2³²                  r₃
    and( r₁, r₂, r₃)        [r₁] & [r₂]                          r₃
    or(  r₁, r₂, r₃)        [r₁] | [r₂]                          r₃
    copy(k, r₁)             k                                    r₁
    zjump(r₁, r₂)           [r₂] - 4 if [r₁] = 0    else ip      ip
    gjump(r₁, r₂, r₃)       [r₃] - 4 if [r₁] > [r₂] else ip      ip
    load( r₁, r₂)           M([r₁])                              r₂
    store(r₁, r₂)           [r₁]                                 M([r₂])
    stop()

Assembly lines specify words unless they are blank, contain only whitespace, or,
contain comments.  Comments are denoted with hashtags.

Assembly data can be expressed in base ten or hexadecimal.  Hexadecimal data
must begin with "0x".

Assembly memory address aliases are defined when they occur at the beginnings of
lines followed by colons.  They are set to the beginning addresses of the
corresponding words.

See the source code and other computer hardware resources for further details.

About

a minimal computer emulator and assembler

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages