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.
All instructions are 32 bits. Immediate values are 2s complement.
Arithmetic
| Name | Value |
| 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
| Name | Value |
| Prefix |
%01 |
| Instruction code |
5 bits |
| Register |
5 bits |
| Address register |
4 bits (must be an integer register) |
| Offset |
16 bits (immediate) |
Branch
| Name | Value |
| Prefix |
%10 |
| Instruction code |
3 bits |
| Condition register |
4 bits (must be an integer register) |
| Destination |
23 bits (register or immediate) |
Miscellaneous
| Name | Value |
| Prefix |
%11 |
| Instruction code |
4 bits |
| Data |
26 bits |
Integer Arithmetic Instructions
| Code | Symbol | Description |
| %000000 | add | Add |
| %000001 | addi | Add immediate |
| %000010 | sub | Subtract |
| %000011 | subi | Subtract immediate |
| %000100 | mul | Multiply |
| %000101 | muli | Multiply immediate |
| %000110 | div | Divide |
| %000111 | divi | Divide immediate |
| %001000 | mod | Modulus |
| %001001 | modi | Modulus immediate |
| %001010 | and | Bitwise AND |
| %001011 | andi | Bitwise AND immediate |
| %001100 | or | Bitwise OR |
| %001101 | ori | Bitwise OR immediate |
| %001110 | oru | Bitwise OR upper half word |
| %001111 | orui |
Bitwise OR upper half word immediate |
| %010000 | xor | Bitwise XOR |
| %010001 | xori | Bitwise XOR immediate |
| %010010 | nor | Bitwise NOR |
| %010011 | nori | Bitwise NOR immediate |
| %010100 | pow | Power |
| %010101 | powi | Power immediate |
| %010110 | seteq | Set if equal |
| %010111 | seteqi | Set if equal to immediate |
| %011000 | setne | Set if not equal |
| %011001 | setnei | Set if not equal to immediate |
| %011010 | setgt | Set if greater than |
| %011011 | setgti | Set if greater than immediate |
| %011100 | setge |
Set if greater than or equal to |
| %011101 | setgei |
Set if greater than or equal to immediate |
Floating Point Arithmetic Instructions
| Code | Symbol | Description |
| %100000 | addf | Add |
| %100001 | subf | Subtract |
| %100010 | mulf | Multiply |
| %100011 | divf | Divide |
| %100100 | powf | Power |
| %100101 | setgtf | Set if greater than |
| %100110 | setgef |
Set if greater than or equal to |
| %110000 | mtirf |
Move to integer register |
| %110001 | mfirf |
Move from integer register |
| %110010 | mfiruf |
Move from integer register unsigned |
Load/Store Instructions
| Code | Symbol | Description |
| %00000 | ldb | Load byte |
| %00001 | ldbe | Load byte and extend |
| %00010 | ldh | Load half word |
| %00011 | ldhe | Load half word and extend |
| %00100 | ldw | Load word |
| %00101 | ldwe | Load word and extend |
| %00110 | ldd | Load double word |
| %00111 | ldde | Load double word and extend |
| %01000 | stb | Store byte |
| %01001 | sth | Store half word |
| %01010 | stw | Store word |
| %01011 | std | Store double word |
| %10000 | lds | Load from stack |
| %10001 | sts | Store to stack |
Branch Instructions
| Code | Symbol | Description |
| %000 | jt | Jump if true |
| %001 | jf | Jump if false |
| %010 | call | Call |
| %011 | ret | Return |
| %100 | jtr | Jump if true to register |
| %101 | jfr | Jump if false to register |
| %110 | callr | Call register |
Miscellaneous Instructions
| Code | Symbol | Description |
| %0000 | push | Push a register on the stack |
| %0001 | pushi |
Push an immediate on the stack |
| %0010 | pop | Pop a register off of the stack |
| %0100 | alloc |
Allocate words on the integer data stack |
| %0101 | alloci |
Allocate words on the integer data stack (immediate) |
| %0110 | free |
Free words off of the integer data stack |
| %0111 | freei |
Free words off of the integer data stack (immediate) |
| %1000 | allocf |
Allocate double words on the float data stack |
| %1001 | allocfi |
Allocate double words on the float data stack (immediate) |
| %1010 | freef |
Free double words off of the float data stack |
| %1011 | freefi |
Free double words off of the float data stack (immediate) |
| %1110 | sys | System call |
| %1111 | sysi | System 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.
| Number | Description |
| 0 | void exit(int code) |
| 1 | char *allocate(int size) |
| 2 | char *reallocate(char *ptr, int size) |
| 3 | void release(char *ptr) |
| 4 | int print(char value) |
| 5 | int print(int value) |
| 6 | int print(float value) |
| 7 | int print(char *value) |
| 8 | int read() |
| 9 | int open(string fileName, int mode) |
| 10 | void close(int fd) |
| 11 | boolean isEOF(int fd) |
| 12 | int isError(int fd) |
| 13 | int fprint(int fd, char value) |
| 14 | int fprint(int fd, int value) |
| 15 | int fprint(int fd, float value) |
| 16 | int fprint(int fd, string value) |
| 17 | int fread(int fd) |
| 18 | int time() |
| 19 | void srand(int seed) |
| 20 | int rand() |
| 64 | string createString(int length) |
| 65 | void addStringRef(string str) |
| 66 | void removeStringRef(string str) |
| 67 | char getChar(string str, int index) |
| 68 | void setChar(string str, int index, char ch) |
| 69 | string strcat(string dest, string src) |
| 70 | void strcpy(string dest, string src) |
| 71 | int strlen(string str) |
| 72 | string itoa(int value) |
| 73 | string ftoa(float value) |
| 74 | string ptoa(int value) |
| 75 | int atoi(string str) |
| 76 | float atof(string str) |
| 128 | var gui(..., int code) |
Home /
Programs /
Jargon