Jargon Machine Code

The Jargon Machine Code Specification v0.1 20030729 <> 20031018
by Joe Wingbermuehle

Background

Jargon Machine Code (JMC) was devised as a simple method to allow platform independence. JMC can be either interpreted or compiled into native machine code using an external program. Furthermore, JMC could be run through an optimizer.

Registers

Integer Registers
Jargon Machine Code has 16 32-bit integer registers. In Jargon Assembly Language, these registers are denoted by r0 through r15. In Jargon Machine Code, these registers are represented as the hex values 00 through 0F. r0 always contains zero.

Float Registers
Jargon Machine Code has 16 64-bit floating point registers. In Jargon Assembly Language, these registers are denoted by f0 through f15. In Jargon Machine Code, these registers are represented as the hex values 10 through 1F. f0 always contains zero.

Instruction Formats

All instructions are 32 bits. Immediate values are 2s complement.

Arithmetic
NameValue
Prefix %00
Instruction code 6 bits
Destination register 4 bits (register type determined by code)
Source A 4 bits (register type determined by code)
Source B 16 bits (register or immediate)

Load/Store
NameValue
Prefix %01
Instruction code 5 bits
Register 5 bits
Address register 4 bits (must be an integer register)
Offset 16 bits (immediate)

Branch

NameValue
Prefix %10
Instruction code 3 bits
Condition register 4 bits (must be an integer register)
Destination 23 bits (register or immediate)

Miscellaneous

NameValue
Prefix %11
Instruction code 4 bits
Data 26 bits

Integer Arithmetic Instructions

CodeSymbolDescription
%000000addAdd
%000001addiAdd immediate
%000010subSubtract
%000011subiSubtract immediate
%000100mulMultiply
%000101muliMultiply immediate
%000110divDivide
%000111diviDivide immediate
%001000modModulus
%001001modiModulus immediate
%001010andBitwise AND
%001011andiBitwise AND immediate
%001100orBitwise OR
%001101oriBitwise OR immediate
%001110oruBitwise OR upper half word
%001111orui Bitwise OR upper half word immediate
%010000xorBitwise XOR
%010001xoriBitwise XOR immediate
%010010norBitwise NOR
%010011noriBitwise NOR immediate
%010100powPower
%010101powiPower immediate
%010110seteqSet if equal
%010111seteqiSet if equal to immediate
%011000setneSet if not equal
%011001setneiSet if not equal to immediate
%011010setgtSet if greater than
%011011setgtiSet if greater than immediate
%011100setge Set if greater than or equal to
%011101setgei Set if greater than or equal to immediate

Floating Point Arithmetic Instructions

CodeSymbolDescription
%100000addfAdd
%100001subfSubtract
%100010mulfMultiply
%100011divfDivide
%100100powfPower
%100101setgtfSet if greater than
%100110setgef Set if greater than or equal to
%110000mtirf Move to integer register
%110001mfirf Move from integer register
%110010mfiruf Move from integer register unsigned

Load/Store Instructions

CodeSymbolDescription
%00000ldbLoad byte
%00001ldbeLoad byte and extend
%00010ldhLoad half word
%00011ldheLoad half word and extend
%00100ldwLoad word
%00101ldweLoad word and extend
%00110lddLoad double word
%00111lddeLoad double word and extend
%01000stbStore byte
%01001sthStore half word
%01010stwStore word
%01011stdStore double word
%10000ldsLoad from stack
%10001stsStore to stack

Branch Instructions

CodeSymbolDescription
%000jtJump if true
%001jfJump if false
%010callCall
%011retReturn
%100jtrJump if true to register
%101jfrJump if false to register
%110callrCall register

Miscellaneous Instructions

CodeSymbolDescription
%0000pushPush a register on the stack
%0001pushi Push an immediate on the stack
%0010popPop a register off of the stack
%0100alloc Allocate words on the integer data stack
%0101alloci Allocate words on the integer data stack (immediate)
%0110free Free words off of the integer data stack
%0111freei Free words off of the integer data stack (immediate)
%1000allocf Allocate double words on the float data stack
%1001allocfi Allocate double words on the float data stack (immediate)
%1010freef Free double words off of the float data stack
%1011freefi Free double words off of the float data stack (immediate)
%1110sysSystem call
%1111sysiSystem call immediate

Calling Conventions

All arguments are pushed on the stack with the first argument pushed first. The return value, if any, is returned in the first register appropriate for holding the value. Registers are not preserved across function calls.

System Calls

NumberDescription
0void exit(int code)
1char *allocate(int size)
2char *reallocate(char *ptr, int size)
3void release(char *ptr)
4int print(char value)
5int print(int value)
6int print(float value)
7int print(char *value)
8int read()
9int open(string fileName, int mode)
10void close(int fd)
11boolean isEOF(int fd)
12int isError(int fd)
13int fprint(int fd, char value)
14int fprint(int fd, int value)
15int fprint(int fd, float value)
16int fprint(int fd, string value)
17int fread(int fd)
18int time()
19void srand(int seed)
20int rand()
64string createString(int length)
65void addStringRef(string str)
66void removeStringRef(string str)
67char getChar(string str, int index)
68void setChar(string str, int index, char ch)
69string strcat(string dest, string src)
70void strcpy(string dest, string src)
71int strlen(string str)
72string itoa(int value)
73string ftoa(float value)
74string ptoa(int value)
75int atoi(string str)
76float atof(string str)
128var gui(..., int code)

Home / Projects / Jargon