├── .gitignore ├── README.md ├── bin ├── lv └── usage.txt ├── build.sh ├── examples └── simple.js ├── index.js ├── lib ├── addr.js ├── asm.js ├── base.js ├── cond.js ├── context.js ├── func.js ├── index.js ├── instructs.js ├── iterator.js ├── literal.js ├── parser.js ├── registers.json ├── syscall.js └── types │ └── define.js ├── nasm ├── LICENSE ├── README ├── ldrdf ├── man1 │ ├── ldrdf.1 │ ├── nasm.1 │ ├── ndisasm.1 │ ├── rdf2bin.1 │ ├── rdf2com.1 │ ├── rdf2ihx.1 │ ├── rdf2ith.1 │ ├── rdf2srec.1 │ ├── rdfdump.1 │ ├── rdflib.1 │ └── rdx.1 ├── nasm ├── nasmdoc.pdf ├── ndisasm ├── rdf2bin ├── rdf2com ├── rdf2ihx ├── rdf2ith ├── rdf2srec ├── rdfdump ├── rdflib └── rdx ├── package-lock.json ├── package.json └── tests ├── .gitignore ├── asm-test.asm ├── asm.js ├── parser-test.asm ├── parser.js └── syscall.js /.gitignore: -------------------------------------------------------------------------------- 1 | **.mk 2 | **.log 3 | **.DS_Store 4 | **.out 5 | **.o 6 | 7 | out 8 | asm-test 9 | gyp-mac-tool 10 | node_modules 11 | 12 | build/ 13 | *.asm -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # LV 3 | 4 | JavaScript(ECMAScript) to Assembly tool based on [NASM](https://www.nasm.us/) project. 5 | 6 | This project is highly under being developed by [@yorkie](https://github.com/yorkie). 7 | 8 | ### Installation 9 | 10 | ```sh 11 | $ npm install lv -g 12 | ``` 13 | 14 | ### Usage 15 | 16 | ```sh 17 | lv [command] [file] 18 | 19 | Commands: 20 | run run your program directly 21 | compile compile your program to output path 22 | ``` 23 | 24 | compile and run demo(program): 25 | ```sh 26 | $ lv compile examples/simple.js build/simple 27 | $ ./build/simple # run 28 | ``` 29 | 30 | NB: Only support very little features 31 | 32 | ### LICENSE 33 | 34 | MIT 35 | -------------------------------------------------------------------------------- /bin/lv: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | var Parser = require('../').Parser; 6 | var util = require('util'); 7 | var exec = require('child_process').exec; 8 | var argv = require('minimist')(process.argv.slice(2)); 9 | var command = argv._[0]; 10 | var DEFAULT_PATH = '/tmp/out'; 11 | var enabledVerbose = false; 12 | 13 | function usage() { 14 | fs.createReadStream(path.join(__dirname, './usage.txt')) 15 | .on('end', process.exit) 16 | .pipe(process.stdout); 17 | } 18 | 19 | function verbose() { 20 | if (!enabledVerbose) 21 | return; 22 | console.log.apply(this, arguments); 23 | } 24 | 25 | if (argv.help || process.argv.slice(2).length === 0) { 26 | usage(); 27 | } 28 | 29 | if (argv.verbose) { 30 | enabledVerbose = true; 31 | } 32 | 33 | switch (command) { 34 | case 'run': 35 | lv_run(); 36 | break; 37 | case 'compile': 38 | lv_compile(); 39 | break; 40 | } 41 | 42 | function lv_run() { 43 | lv_compile(function(err, out) { 44 | if (err) return console.error(err.stack); 45 | var child = exec(out); 46 | child.stdout.pipe(process.stdout); 47 | child.stderr.pipe(process.stderr); 48 | }); 49 | } 50 | 51 | function lv_compile(callback) { 52 | var filename = argv._[1]; 53 | var out = argv._[2] || DEFAULT_PATH; 54 | if (!filename) 55 | throw new Error('filename required'); 56 | if (!/\.js$/.test(filename)) 57 | filename += '.js'; 58 | 59 | var mainparser = new Parser(filename); 60 | mainparser.on('error', function(err) { 61 | console.error(err.stack); 62 | }); 63 | mainparser.on('done', function(program) { 64 | verbose('-->', out+'.asm'); 65 | fs.writeFile(out+'.asm', program, function() { 66 | var child = exec(util.format('sh %s %s', path.join(__dirname, '../build.sh'), out), function(err) { 67 | if (callback && typeof callback === 'function') callback(err, out); 68 | }); 69 | }); 70 | }); 71 | } -------------------------------------------------------------------------------- /bin/usage.txt: -------------------------------------------------------------------------------- 1 | 2 | lv [command] [file] 3 | 4 | Commands: 5 | run run your program directly 6 | compile compile your program to output path 7 | 8 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ./nasm/nasm -f macho $1.asm && \ 4 | ld -e main \ 5 | -o $1 $1.o\ 6 | -macosx_version_min '10.6' -------------------------------------------------------------------------------- /examples/simple.js: -------------------------------------------------------------------------------- 1 | 2 | // const 3 | const bee = 'Hello World\n'; 4 | const str = '2\n'; 5 | 6 | sys.write(bee); 7 | sys.write(str); 8 | 9 | // variables 10 | var foo = 'abc\n'; 11 | var bar = 89; 12 | 13 | sys.write(foo); 14 | sys.write(bar); 15 | sys.write('\n'); 16 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | exports.Parser = require('./lib/parser'); -------------------------------------------------------------------------------- /lib/addr.js: -------------------------------------------------------------------------------- 1 | 2 | const util = require('util'); 3 | const assert = require('assert'); 4 | 5 | // mov eax, ebx 6 | exports.byRegister = function(reg) { 7 | return reg; 8 | }; 9 | 10 | // mov eax, 20 11 | exports.byImmediate = function(pos) { 12 | assert.ok(pos > 0); 13 | return pos; 14 | }; 15 | 16 | // mov eax, [2000h] 17 | exports.byDirectMemory = function(pos) { 18 | assert.equal(typeof pos, 'number'); 19 | return util.format('[%d]', pos); 20 | }; 21 | 22 | // mov eax, [ebx+4] 23 | exports.byDirectOffset = function(reg, pos) { 24 | assert.equal(typeof pos, 'number'); 25 | if (pos >= 0) 26 | return util.format('[%s+%d]', reg, pos); 27 | else 28 | return util.format('[%s-%d]', reg, -pos); 29 | }; 30 | 31 | // mov eax, [ebx] 32 | exports.byIndirectRegister = function(reg) { 33 | return util.format('[%s]', reg); 34 | }; 35 | -------------------------------------------------------------------------------- /lib/asm.js: -------------------------------------------------------------------------------- 1 | const util = require('util'); 2 | const base = require('./base'); 3 | const addr = require('./addr'); 4 | const func = require('./func'); 5 | const syscall = require('./syscall'); 6 | const instructs = require('./instructs'); 7 | const registers = require('./registers.json'); 8 | const types = require('./types/define'); 9 | 10 | class Assembly { 11 | constructor() { 12 | if (!(this instanceof Assembly)) 13 | return new Assembly(); 14 | this.variablesTable = {}; 15 | this.constants = { 16 | 'enter': 'main', 17 | 'globalScope': 0, 18 | 'stackSize': 25090 // keep consistent with v8 19 | }; 20 | this.section = { 21 | bss: [], 22 | text: [], 23 | data: [] 24 | }; 25 | this.runtime = { 26 | 'stack': { 27 | 'offset': 0x00 28 | }, 29 | 'heap': {}, 30 | 'scope': this.constants.globalScope 31 | }; 32 | this.source = ''; 33 | } 34 | 35 | getSectionText() { 36 | return this.section.text; 37 | } 38 | 39 | getSectionData() { 40 | return this.section.data; 41 | } 42 | 43 | pushSyscall(name, args) { 44 | this.section.text.push({ 45 | type: 'syscall', 46 | name: name, 47 | args: args 48 | }); 49 | } 50 | 51 | decl(kind, opt) { 52 | var name = opt.id.name; 53 | var init = opt.init; 54 | if (kind === 'const') { 55 | if (init.type !== 'Literal') 56 | throw new Error('`const` must own literal declaration'); 57 | if (this.runtime.scope !== this.constants.globalScope) 58 | throw new Error('`const` must be defined at global scope'); 59 | } 60 | 61 | this.variablesTable[name] = { 62 | type: typeof init.type, 63 | scope: this.runtime.scope, 64 | initValue: init 65 | }; 66 | 67 | this.section.text.push({ 68 | type: 'declaration.'+kind, 69 | args: [name, init] 70 | }); 71 | } 72 | 73 | trySyscall(syscall, args) { 74 | var args = Array.prototype.slice.call(arguments, 1); 75 | return '\n' + syscall.apply(this, args).map(function(item) { 76 | return '\t' + item; 77 | }).join('\n') + '\n\n'; 78 | } 79 | 80 | toString() { 81 | var self = this; 82 | this.source += 'section .bss\n\n'; 83 | this.source += 'section .text\n\n'; 84 | 85 | // define global variable 86 | this.source += util.format('global %s\n\n', this.constants.enter); 87 | 88 | // define main function 89 | this.source += util.format('%s:\n\n', this.constants.enter); 90 | this.source += func([], function() { 91 | // body 92 | var ret = self.section.text.map(function(item) { 93 | switch (item.type) { 94 | case 'syscall': 95 | return self.trySyscall.apply(self, [syscall[item.name]].concat(item.args)); 96 | case 'declaration.const': 97 | return base.declaration.apply(self, item.args); 98 | case 'declaration.var': 99 | return base.declaration2.apply(self, item.args); 100 | } 101 | }).join('\n')+'\n\n'; 102 | 103 | // process exit() 104 | ret += self.trySyscall(syscall.exit, 0); 105 | return ret; 106 | }); 107 | 108 | // declear .data section 109 | this.source += 'section .data\n\n'; 110 | 111 | // added typing system define 112 | this.source += Object.keys(types).map(function(key) { 113 | return '\t' + '__sys__type_' + key + ': dd 0x' + types[key]; 114 | }).join('\n') + '\n\n'; 115 | 116 | // added variables and constants setup 117 | this.source += this.section.data.map(function(item) { 118 | return '\t'+item; 119 | }).join('\n') + '\n\n'; 120 | return this.source; 121 | } 122 | }; 123 | 124 | module.exports = Assembly; -------------------------------------------------------------------------------- /lib/base.js: -------------------------------------------------------------------------------- 1 | 2 | const assert = require('assert'); 3 | const util = require('util'); 4 | const addr = require('./addr'); 5 | const instructs = require('./instructs'); 6 | const registers = require('./registers.json'); 7 | const types = require('./types/define'); 8 | 9 | // 10 | // for `const` declaration: const variable 11 | // 12 | exports.declaration = function(name, init) { 13 | assert.equal(init.type, 'Literal', 14 | 'const assignment must be `literal`'); 15 | 16 | var rtype = typeof init.value; 17 | literal.call(this, name, init.value); 18 | this.variablesTable[name] = { 19 | type: rtype, 20 | isConstant: true, 21 | scope: this.runtime.scope, 22 | initValue: init 23 | }; 24 | return ''; 25 | }; 26 | 27 | // 28 | // helper for declaration 29 | // 30 | function literal(name, value) { 31 | var lenSymbol = name + '_len'; 32 | var typeSymbol = name + '_type'; 33 | if (typeof value === 'number') { 34 | this.section.data.push(instructs.db(name, value)); 35 | this.section.data.push(instructs.db(typeSymbol, types['integer'])); 36 | } else { 37 | this.section.data.push(instructs.db(name, value)); 38 | this.section.data.push(instructs.equ(lenSymbol, '$-'+name)); 39 | this.section.data.push(instructs.db(typeSymbol, types['string'])); 40 | } 41 | }; 42 | 43 | // 44 | // for `var` declaration: local variable 45 | // 46 | exports.declaration2 = function(name, init) { 47 | // compute offset 48 | var offset = 0; 49 | var rtype = typeof init.value; 50 | if (init.type === 'Literal') { 51 | var size; 52 | if (rtype === 'string') 53 | size = name + '_len'; 54 | else 55 | size = 1; 56 | 57 | literal.call(this, name, init.value); 58 | this.variablesTable[name] = { 59 | type: rtype, 60 | isConstant: false, 61 | scope: this.runtime.scope, 62 | initValue: init, 63 | accessor: name, 64 | size: size 65 | }; 66 | return ''; 67 | } 68 | }; 69 | -------------------------------------------------------------------------------- /lib/cond.js: -------------------------------------------------------------------------------- 1 | 2 | const util = require('util'); 3 | const registers = require('./registers.json'); 4 | const instructs = require('./instructs'); 5 | 6 | exports.if = function(expr, iftrue) { 7 | return [ 8 | instructs.mov(expr, registers.EDX, 'l'), 9 | instructs.mov(0x00, registers.EAX, 'l'), 10 | instructs.cmp(registers.EAX, registers.EDX, 'l'), 11 | instructs.je(iftrue) 12 | ]; 13 | }; 14 | 15 | exports.switch = function(expr, cases) { 16 | const tables = cases 17 | .sort(function(prev, next) { 18 | return prev.key - next.key; 19 | }) 20 | .map(function(item) { 21 | return instructs.mov 22 | }); 23 | // TODO 24 | }; -------------------------------------------------------------------------------- /lib/context.js: -------------------------------------------------------------------------------- 1 | 2 | const StackSize = { 3 | large: 'large', 4 | small: 'small', 5 | flat: 'flat', 6 | flat64: 'flat64' 7 | }; 8 | 9 | const ContextBase = { 10 | 11 | $name: 'MainContext', 12 | $stacksize: StackSize.large, 13 | $arguments: [], 14 | $local: [], 15 | $text: '', 16 | 17 | get name() { 18 | return this.$name; 19 | }, 20 | 21 | set name(val) { 22 | this.$name = val; 23 | }, 24 | 25 | get stacksize() { 26 | return this.$stacksize; 27 | }, 28 | 29 | set stacksize(val) { 30 | var size = StackSize[val]; 31 | if (size) 32 | this.$stacksize = size; 33 | }, 34 | 35 | get args() { 36 | return this.$arguments.map(function(item) { 37 | return item + ':word'; 38 | }).join(','); 39 | }, 40 | 41 | set args(val) { 42 | if (Array.isArray(val)) 43 | this.$arguments = val; 44 | else if (typeof val === 'object') 45 | this.$arguments[0] = val; 46 | else 47 | throw new Error('invalid arguments setter with ' + val); 48 | }, 49 | 50 | get local() { 51 | return this.$local.map(function(item) { 52 | return item + ':word'; 53 | }).join(','); 54 | }, 55 | 56 | set local(val) { 57 | if (!Array.isArray(val)) 58 | throw new Error('invalid local setter with ' + val); 59 | else 60 | this.$local = val; 61 | }, 62 | 63 | get text() { 64 | return this.$text; 65 | }, 66 | 67 | set text(val) { 68 | this.$text = val || this.$text; 69 | }, 70 | 71 | /* 72 | * generate asm codes 73 | */ 74 | toString: function() { 75 | var ret = [ 76 | '', 77 | '%push ' +this.name, 78 | '%stacksize ' +this.stacksize, 79 | '', // %arg 80 | '', // %local 81 | this.text, 82 | '%pop', 83 | '' 84 | ]; 85 | 86 | if (this.args.length > 0) 87 | ret[3] = '%arg ' + this.args; 88 | if (this.local.length > 0) 89 | ret[4] = '%local ' + this.local; 90 | return ret.join('\n') + '\n'; 91 | } 92 | 93 | }; 94 | 95 | function createContext() { 96 | return Object.create(ContextBase); 97 | } 98 | 99 | exports.createContext = createContext; 100 | -------------------------------------------------------------------------------- /lib/func.js: -------------------------------------------------------------------------------- 1 | 2 | const instructs = require('./instructs'); 3 | const registers = require('./registers.json'); 4 | const createContext = require('./context').createContext; 5 | const table = '\t'; 6 | 7 | module.exports = function(args, progress) { 8 | if (typeof progress !== 'function') 9 | throw new Error('functional progress required'); 10 | 11 | const ctx = createContext(); 12 | ctx.name = 'main_context'; 13 | ctx.stacksize = 'large'; 14 | ctx.text = progress(); 15 | 16 | let ret = table+instructs.push(registers.EBP)+'\n'; 17 | ret += table+instructs.mov(registers.EBP, registers.ESP)+'\n'; 18 | ret += table+instructs.sub(registers.ESP, 10)+'\n'; 19 | ret += ctx.toString(); 20 | ret += table+instructs.mov(registers.ESP, registers.EBP)+'\n'; 21 | ret += table+instructs.pop(registers.EBP)+'\n'; 22 | ret += table+instructs.ret()+'\n\n'; 23 | 24 | return ret; 25 | }; 26 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | 2 | const fs = require('fs'); 3 | 4 | exports.compile = compile; 5 | 6 | function compile(files) { 7 | let src = fs.readFileSync(files[0], 'utf8'); 8 | src.split('\n').filter(function(item) { 9 | return item.length > 0; 10 | }); 11 | } 12 | -------------------------------------------------------------------------------- /lib/instructs.js: -------------------------------------------------------------------------------- 1 | 2 | const util = require('util'); 3 | 4 | exports.push = function(type, val, opt) { 5 | if (type !== 'dword' && val !== undefined) { 6 | type = type+',' 7 | } 8 | if (val === undefined) { 9 | val = ''; 10 | } 11 | if (opt === 'l') { 12 | return util.format('pushl %s %s', type, val); 13 | } else { 14 | return util.format('push %s %s', type, val); 15 | } 16 | }; 17 | 18 | exports.pop = function(type, opt) { 19 | if (opt === 'l') { 20 | return util.format('popl %s', type); 21 | } else { 22 | return util.format('pop %s', type); 23 | } 24 | }; 25 | 26 | exports.mov = function(reg, val, opt) { 27 | let cmd = 'mov'; 28 | if (/^[bwl]$/.test(opt)) { 29 | cmd += opt; 30 | } 31 | return util.format('%s %s, %s', cmd, reg, val); 32 | }; 33 | 34 | exports.sub = function(reg, val, opt) { 35 | return util.format('sub %s, %s', reg, val); 36 | }; 37 | 38 | exports.add = function(reg, val) { 39 | return util.format('add %s, %d', reg, val); 40 | }; 41 | 42 | exports.cmp = function(a, b, opt) { 43 | let cmd = 'cmp'; 44 | if (/^[bwl]$/.test(opt)) { 45 | cmd += opt; 46 | } 47 | return [cmd, a, b].join(' '); 48 | }; 49 | 50 | exports.test = function(a, b, opt) { 51 | let cmd = 'test'; 52 | if (/^[bwl]$/.test(opt)) { 53 | cmd += opt; 54 | } 55 | return [cmd, a, b].join(' '); 56 | }; 57 | 58 | // jump 59 | exports.jmp = function(label) { 60 | return 'jmp '+label; 61 | }; 62 | 63 | // jump if not equal 64 | exports.jne = function(label) { 65 | return 'jne '+label; 66 | }; 67 | 68 | // jump if equal 69 | exports.je = function(label) { 70 | return 'je '+label 71 | }; 72 | 73 | // jump if negative 74 | exports.js = function(label) { 75 | return 'js '+label; 76 | }; 77 | 78 | // jump if non-negative 79 | exports.jns = function(label) { 80 | return 'jns '+label; 81 | }; 82 | 83 | // jump if bigger 84 | exports.jg = function(label) { 85 | return 'jg '+label; 86 | }; 87 | 88 | // jump if bigger or equal 89 | exports.jge = function(label) { 90 | return 'jge '+label; 91 | }; 92 | 93 | // jump if less 94 | exports.jl = function(label) { 95 | return 'jl '+label; 96 | }; 97 | 98 | // jump if less or equal 99 | exports.jle = function(label) { 100 | return 'jle '+label; 101 | }; 102 | 103 | exports.int = function(val) { 104 | return 'int '+val; 105 | }; 106 | 107 | exports.db = function(symbol, val) { 108 | if (typeof val !== 'number') { 109 | let valarr = []; 110 | let valbuf = Buffer.from(val); 111 | for (let i = 0; i < valbuf.length; i++) 112 | valarr.push(valbuf[i]); 113 | return util.format('%s: db %s', symbol, valarr.join(', ')); 114 | } else { 115 | return util.format('%s: db %s', symbol, '0x' + val); 116 | } 117 | }; 118 | 119 | exports.dd = function(symbol, val) { 120 | return util.format('%s: dd %d', symbol, val); 121 | }; 122 | 123 | exports.equ = function(symbol, expr) { 124 | return util.format('%s: equ %s', symbol, expr); 125 | }; 126 | 127 | exports.ret = function() { 128 | return 'ret'; 129 | }; 130 | -------------------------------------------------------------------------------- /lib/iterator.js: -------------------------------------------------------------------------------- 1 | 2 | exports.for = function() { 3 | // TODO 4 | }; 5 | 6 | exports.for_in = function() { 7 | // TODO 8 | }; 9 | 10 | exports.for_of = function() { 11 | // TODO 12 | }; 13 | 14 | exports.while = function() { 15 | // TODO 16 | }; 17 | 18 | exports.doWhile = function() { 19 | // TODO 20 | }; -------------------------------------------------------------------------------- /lib/literal.js: -------------------------------------------------------------------------------- 1 | 2 | exports.object = function() { 3 | // TODO 4 | }; 5 | 6 | exports.array = function() { 7 | // TODO 8 | }; 9 | 10 | exports.number = function() { 11 | // TODO 12 | }; 13 | -------------------------------------------------------------------------------- /lib/parser.js: -------------------------------------------------------------------------------- 1 | 2 | const fs = require('fs'); 3 | const assert = require('assert'); 4 | const Assembly = require('./asm'); 5 | 6 | const esprima = require('esprima'); 7 | const EventEmitter = require('events').EventEmitter; 8 | 9 | class Parser extends EventEmitter { 10 | constructor(filename) { 11 | super(); 12 | this.program = new Assembly(); 13 | this.loadFile(filename); 14 | } 15 | 16 | loadFile(filename) { 17 | fs.readFile(filename, (err, file) => { 18 | if (err) 19 | return this.emit('error', err); 20 | else 21 | return this.parse(file.toString('utf8')); 22 | }); 23 | } 24 | 25 | parse(source) { 26 | this.source = source; 27 | this.esContext = esprima.parse(source); 28 | if (!this.esContext.body) { 29 | return console.warn('Empty Program'); 30 | } 31 | 32 | this.esContext.body.forEach((item) => { 33 | this._statement.call(this, item); 34 | }); 35 | this.emit('done', this.program.toString()); 36 | } 37 | 38 | // 39 | // statement parser 40 | // 41 | _statement(item) { 42 | switch (item.type) { 43 | case 'VariableDeclaration': 44 | this._decl(item); 45 | break; 46 | case 'ExpressionStatement': 47 | this._expr(item.expression); 48 | break; 49 | case 'IfStatement': 50 | this._ifstatement(item.test, item.consequent); 51 | break; 52 | }; 53 | } 54 | 55 | // 56 | // declearation 57 | // keywords: var, const 58 | // 59 | _decl(item) { 60 | assert.equal(item.type, 'VariableDeclaration'); 61 | item.declarations.forEach((decl) => { 62 | this.program.decl(item.kind, decl); 63 | }); 64 | } 65 | 66 | _expr(item) { 67 | switch (item.type) { 68 | case 'CallExpression': 69 | this._callee(item.callee, item.arguments); 70 | break; 71 | }; 72 | } 73 | 74 | _ifstatement(test, consequent) { 75 | console.log(test, consequent); 76 | // `Literal` that means i can decide it in compiler time 77 | if (test.type === 'Literal') { 78 | if (!test.value) { 79 | return; 80 | } 81 | consequent.body.forEach((item) => { 82 | this._statement.call(this, item); 83 | }); 84 | return; 85 | } 86 | 87 | // for other 88 | if (test.type === 'Identifier') { 89 | // TODO 90 | } 91 | } 92 | 93 | _symbol(item) { 94 | var ret = []; 95 | if (item.property) { 96 | ret.push(item.property.name); 97 | } 98 | 99 | switch (item.type) { 100 | case 'MemberExpression': 101 | return ret.concat(this._symbol(item.object)); 102 | case 'Identifier': 103 | return ret.push(item.name) && ret; 104 | }; 105 | } 106 | 107 | _callee(item, args) { 108 | var symbols = this._symbol(item).reverse(); 109 | if (symbols[0] == 'sys') { 110 | this.program.pushSyscall(symbols[1], args); 111 | } 112 | } 113 | }; 114 | 115 | module.exports = Parser; 116 | -------------------------------------------------------------------------------- /lib/registers.json: -------------------------------------------------------------------------------- 1 | { 2 | "EAX": "eax", 3 | "ECX": "ecx", 4 | "EDX": "edx", 5 | "EBX": "ebx", 6 | "ESI": "esi", 7 | "EDI": "edi", 8 | "ESP": "esp", 9 | "EBP": "ebp", 10 | 11 | "AX": "ax", 12 | "CX": "cx", 13 | "DX": "dx", 14 | "BX": "bx", 15 | "SI": "si", 16 | "DI": "di", 17 | "SP": "sp", 18 | "BP": "bp", 19 | 20 | "AH": "ah", 21 | "AL": "al", 22 | "CH": "ch", 23 | "CL": "cl", 24 | "DH": "dh", 25 | "DL": "dl", 26 | "BH": "bh", 27 | "BL": "bl" 28 | } -------------------------------------------------------------------------------- /lib/syscall.js: -------------------------------------------------------------------------------- 1 | 2 | const util = require('util'); 3 | const registers = require('./registers.json'); 4 | const instructs = require('./instructs'); 5 | 6 | exports.exit = function(signal) { 7 | return [ 8 | '; system call: exit', 9 | instructs.push('dword', signal || 0x00), 10 | instructs.mov(registers.EAX, 0x01), 11 | instructs.sub(registers.ESP, 0x04), 12 | instructs.int(0x80) 13 | ]; 14 | }; 15 | 16 | exports.fork = function() { 17 | return [ 18 | instructs.mov(registers.EAX, 0x02), 19 | instructs.sub(registers.ESP, 0x04), 20 | instructs.int(0x80) 21 | ]; 22 | }; 23 | 24 | exports.read = function(symbol, fd) { 25 | let strSymbol = symbol; 26 | let lenSymbol = strSymbol + '_len'; 27 | this.section.data.push(instructs.db(strSymbol, str)); 28 | this.section.data.push(instructs.equ(lenSymbol, '$-'+strSymbol)); 29 | return [ 30 | instructs.push('dword', lenSymbol), 31 | instructs.push('dword', strSymbol), 32 | instructs.push('dword', fd || 0x01), 33 | instructs.mov(registers.EAX, 0x03), 34 | instructs.sub(registers.ESP, 0x04), 35 | instructs.int(0x80), 36 | instructs.add(registers.ESP, 0x10) 37 | ]; 38 | }; 39 | 40 | exports.write = function(id, fd) { 41 | let strSymbol, lenSymbol; 42 | if (id.type === 'Literal') { 43 | id.value = id.value.toString(); 44 | strSymbol = util.format('__sys__def_%d', parseInt(Math.random()*100)); 45 | lenSymbol = strSymbol + '_len'; 46 | this.section.data.push(instructs.db(strSymbol, id.value)); 47 | this.section.data.push(instructs.equ(lenSymbol, '$-'+strSymbol)); 48 | } else { 49 | const variableInTable = this.variablesTable[id.name]; 50 | if (!variableInTable || variableInTable.scope !== this.runtime.scope) 51 | throw new Error('`' + id.name + '` not defined or unaccessible'); 52 | 53 | // only when constant, it has symbol in data section 54 | if (variableInTable.isConstant) { 55 | strSymbol = id.name; 56 | lenSymbol = strSymbol + '_len'; 57 | 58 | } else { 59 | lenSymbol = variableInTable.size; 60 | strSymbol = variableInTable.accessor; 61 | } 62 | } 63 | 64 | return [ 65 | '; system call: write', 66 | instructs.push('dword', lenSymbol), 67 | instructs.push('dword', strSymbol), 68 | instructs.push('dword', fd || 0x01), 69 | instructs.mov(registers.EAX, 0x04), 70 | instructs.sub(registers.ESP, 0x04), 71 | instructs.int(0x80), 72 | instructs.add(registers.ESP, 0x10) 73 | ]; 74 | }; 75 | 76 | exports.open = function(path, option, fd) { 77 | // TODO 78 | return [ 79 | instructs.push('dword', path) 80 | ]; 81 | }; 82 | 83 | exports.close = function(fd) { 84 | return [ 85 | instructs.push('dword', fd), 86 | instructs.mov(registers.EAX, 0x05), 87 | instructs.sub(registers.ESP, 0x04), 88 | instructs.int(0x80) 89 | ]; 90 | }; 91 | 92 | exports.waitpid = function() { 93 | // TODO 94 | }; 95 | 96 | exports.creat = function() { 97 | // TODO 98 | }; 99 | 100 | exports.link = function() { 101 | // TODO 102 | }; 103 | 104 | exports.unlink = function(path) { 105 | const symbol = util.format('_lamb_var_%d', parseInt(Math.random()*100)); 106 | this.section.data.push(instructs.db(symbol, path)); 107 | return [ 108 | '; system call: unlink', 109 | instructs.push('dword', symbol), 110 | instructs.mov(registers.EAX, 0x0a), 111 | instructs.sub(registers.ESP, 0x04), 112 | instructs.int(0x80) 113 | ]; 114 | }; 115 | 116 | exports.execve = function() { 117 | // TODO 118 | }; 119 | 120 | exports.chdir = function() { 121 | // TODO 122 | }; 123 | 124 | exports.time = function() { 125 | // TODO 126 | }; 127 | 128 | exports.mknod = function() { 129 | // TODO 130 | }; 131 | 132 | exports.chmod = function() { 133 | // TODO 134 | }; 135 | 136 | exports.lchown = function() { 137 | // TODO 138 | }; 139 | 140 | exports.stat = function() { 141 | // TODO 142 | }; 143 | 144 | exports.lseek = function() { 145 | // TODO 146 | }; 147 | 148 | exports.getpid = function() { 149 | return [ 150 | instructs.mov(registers.EAX, 0x14), 151 | instructs.sub(registers.ESP, 0x04), 152 | instructs.int(0x80) 153 | ]; 154 | }; 155 | 156 | exports.mount = function() { 157 | // TODO 158 | }; 159 | 160 | exports.oldumount = function() { 161 | // TODO 162 | }; 163 | 164 | exports.setuid = function() { 165 | // TODO 166 | }; 167 | 168 | exports.getuid = function() { 169 | // TODO 170 | }; 171 | 172 | exports.stime = function() { 173 | // TODO 174 | }; 175 | 176 | exports.ptrace = function() { 177 | // TODO 178 | }; 179 | 180 | exports.alarm = function() { 181 | // TODO 182 | }; 183 | 184 | exports.fstat = function() { 185 | // TODO 186 | }; 187 | 188 | exports.pause = function() { 189 | // TODO 190 | }; 191 | 192 | exports.utime = function() { 193 | // TODO 194 | }; 195 | 196 | exports.access = function() { 197 | // TODO 198 | }; 199 | 200 | exports.nice = function() { 201 | // TODO 202 | }; 203 | 204 | exports.sync = function() { 205 | // TODO 206 | }; 207 | 208 | exports.kill = function() { 209 | // TODO 210 | }; 211 | 212 | exports.rename = function() { 213 | // TODO 214 | }; 215 | 216 | exports.mkdir = function() { 217 | // TODO 218 | }; 219 | 220 | exports.rmdir = function() { 221 | // TODO 222 | }; 223 | -------------------------------------------------------------------------------- /lib/types/define.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'integer' : 0x00, 3 | 'double' : 0x01, 4 | 'char' : 0x02, 5 | 'boolean' : 0x03, 6 | 'array' : 0x04, 7 | 'string' : 0x05, 8 | 'object' : 0x06 9 | }; 10 | -------------------------------------------------------------------------------- /nasm/LICENSE: -------------------------------------------------------------------------------- 1 | NASM is now licensed under the 2-clause BSD license, also known as the 2 | simplified BSD license. 3 | 4 | Copyright 1996-2010 the NASM Authors - All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following 8 | conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following 14 | disclaimer in the documentation and/or other materials provided 15 | with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 18 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /nasm/README: -------------------------------------------------------------------------------- 1 | NASM, the Netwide Assembler. 2 | 3 | Many many developers all over the net respect NASM for what it is 4 | - a widespread (thus netwide), portable (thus netwide!), very 5 | flexible and mature assembler tool with support for many output 6 | formats (thus netwide!!). 7 | 8 | Now we have good news for you: NASM is licensed under the "simplified" 9 | (2-clause) BSD license. This means its development is open to even 10 | wider society of programmers wishing to improve their lovely 11 | assembler. 12 | 13 | The NASM project is now situated at SourceForge.net, the most 14 | popular Open Source development site on the Internet. 15 | 16 | Visit our website at http://nasm.sourceforge.net/ and our 17 | SourceForge project at http://sourceforge.net/projects/nasm/ 18 | 19 | See the file CHANGES for the description of changes between revisions, 20 | and the file AUTHORS for a list of contributors. 21 | 22 | With best regards, 23 | NASM crew. 24 | -------------------------------------------------------------------------------- /nasm/ldrdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yorkie/lv/2fb5e264abffa34959ac601567ab608535a79a79/nasm/ldrdf -------------------------------------------------------------------------------- /nasm/man1/ldrdf.1: -------------------------------------------------------------------------------- 1 | .TH LDRDF 1 "September 6, 1999" "Debian Project" "Debian Manual" 2 | .SH NAME 3 | ldrdf \- link RDOFF objects and libraries produced by rdflib(1) 4 | .SH SYNOPSIS 5 | .B ldrdf 6 | .RI "[-o " output-file ] 7 | .I object-file\c 8 | .RI "... [-l" library "...]" 9 | .SH DESCRIPTION 10 | .B ldrdf 11 | is a version of unix 12 | .BR ld (1) 13 | (or DOS LINK) for use with RDOFF files. It is capable of linking RDOFF 14 | objects, and libraries produced with the 15 | .BR rdflib (1) 16 | utility. 17 | .PP 18 | Libraries must be specified with their path as no search is performed. 19 | Modules in libraries are not linked to the program unless they are 20 | referred to. 21 | .SH OPTIONS 22 | .TP 23 | .RI "-o " output-file 24 | Specify an output file. The default output filename is 25 | .RI ' aout.rdx '. 26 | .TP 27 | -v 28 | Increase verbosity level. Currently 4 verbosity levels are available: 29 | default (which only prints error information), normal (which prints 30 | information about the produced object, -v), medium (which prints information 31 | about what the program is doing, -v -v) and high (which prints all available 32 | information, -v -v -v). 33 | .TP 34 | -p 35 | Change alignment value to which multiple segments combigned into a single 36 | segment should be aligned (must be either 1, 2, 4, 8, 16, 32 or 256; default 37 | is 16). 38 | .SH AUTHORS 39 | Julian Hall . 40 | .PP 41 | This manual page was written by Matej Vela . 42 | -------------------------------------------------------------------------------- /nasm/man1/nasm.1: -------------------------------------------------------------------------------- 1 | '\" t 2 | .\" Title: nasm 3 | .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] 4 | .\" Generator: DocBook XSL Stylesheets v1.78.1 5 | .\" Date: 10/20/2014 6 | .\" Manual: The Netwide Assembler Project 7 | .\" Source: NASM 8 | .\" Language: English 9 | .\" 10 | .TH "NASM" "1" "10/20/2014" "NASM" "The Netwide Assembler Project" 11 | .\" ----------------------------------------------------------------- 12 | .\" * Define some portability stuff 13 | .\" ----------------------------------------------------------------- 14 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 15 | .\" http://bugs.debian.org/507673 16 | .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html 17 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 18 | .ie \n(.g .ds Aq \(aq 19 | .el .ds Aq ' 20 | .\" ----------------------------------------------------------------- 21 | .\" * set default formatting 22 | .\" ----------------------------------------------------------------- 23 | .\" disable hyphenation 24 | .nh 25 | .\" disable justification (adjust text to left margin only) 26 | .ad l 27 | .\" ----------------------------------------------------------------- 28 | .\" * MAIN CONTENT STARTS HERE * 29 | .\" ----------------------------------------------------------------- 30 | .SH "NAME" 31 | nasm \- the Netwide Assembler, a portable 80x86 assembler 32 | .SH "SYNOPSIS" 33 | .sp 34 | \fBnasm\fR [\fB\-@\fR response file] [\fB\-f\fR format] [\fB\-o\fR outfile] [\fB\-l\fR listfile] [\fIoptions\fR\&...] filename 35 | .SH "DESCRIPTION" 36 | .sp 37 | The \fBnasm\fR command assembles the file \fIfilename\fR and directs output to the file \fIoutfile\fR if specified\&. If \fIoutfile\fR is not specified, \fBnasm\fR will derive a default output file name from the name of its input file, usually by appending \(oq\&.o\(cq or \(oq\&.obj\(cq, or by removing all extensions for a raw binary file\&. Failing that, the output file name will be \(oqnasm\&.out\(cq\&. 38 | .SH "OPTIONS" 39 | .PP 40 | \fB\-@\fR \fIfilename\fR 41 | .RS 4 42 | Causes 43 | \fBnasm\fR 44 | to process options from filename as if they were included on the command line\&. 45 | .RE 46 | .PP 47 | \fB\-a\fR 48 | .RS 4 49 | Causes 50 | \fBnasm\fR 51 | to assemble the given input file without first applying the macro preprocessor\&. 52 | .RE 53 | .PP 54 | \fB\-D\fR|\fB\-d\fR \fImacro[=value]\fR 55 | .RS 4 56 | Pre\-defines a single\-line macro\&. 57 | .RE 58 | .PP 59 | \fB\-E\fR|\fB\-e\fR 60 | .RS 4 61 | Causes 62 | \fBnasm\fR 63 | to preprocess the given input file, and write the output to 64 | \fIstdout\fR 65 | (or the specified output file name), and not actually assemble anything\&. 66 | .RE 67 | .PP 68 | \fB\-f\fR \fIformat\fR 69 | .RS 4 70 | Specifies the output file format\&. To see a list of valid output formats, use the 71 | \fB\-hf\fR 72 | option\&. 73 | .RE 74 | .PP 75 | \fB\-F\fR \fIformat\fR 76 | .RS 4 77 | Specifies the debug information format\&. To see a list of valid output formats, use the 78 | \fB\-y\fR 79 | option (for example 80 | \fB\-felf \-y\fR)\&. 81 | .RE 82 | .PP 83 | \fB\-g\fR 84 | .RS 4 85 | Causes 86 | \fBnasm\fR 87 | to generate debug information in selected format\&. 88 | .RE 89 | .PP 90 | \fB\-h\fR 91 | .RS 4 92 | Causes 93 | \fBnasm\fR 94 | to exit immediately, after giving a summary of its invocation options\&. 95 | .RE 96 | .PP 97 | \fB\-hf\fR 98 | .RS 4 99 | Same as 100 | \fB\-h\fR 101 | , but also lists all valid output formats\&. 102 | .RE 103 | .PP 104 | \fB\-I\fR|\fB\-i\fR \fIdirectory\fR 105 | .RS 4 106 | Adds a directory to the search path for include files\&. The directory specification must include the trailing slash, as it will be directly prepended to the name of the include file\&. 107 | .RE 108 | .PP 109 | \fB\-l\fR \fIlistfile\fR 110 | .RS 4 111 | Causes an assembly listing to be directed to the given file, in which the original source is displayed on the right hand side (plus the source for included files and the expansions of multi\-line macros) and the generated code is shown in hex on the left\&. 112 | .RE 113 | .PP 114 | \fB\-M\fR 115 | .RS 4 116 | Causes 117 | \fBnasm\fR 118 | to output Makefile\-style dependencies to stdout; normal output is suppressed\&. 119 | .RE 120 | .PP 121 | \fB\-MG\fR \fIfile\fR 122 | .RS 4 123 | Same as 124 | \fB\-M\fR 125 | but assumes that missing Makefile dependecies are generated and added to dependency list without a prefix\&. 126 | .RE 127 | .PP 128 | \fB\-MF\fR \fIfile\fR 129 | .RS 4 130 | Output Makefile\-style dependencies to the specified file\&. 131 | .RE 132 | .PP 133 | \fB\-MD\fR \fIfile\fR 134 | .RS 4 135 | Same as a combination of 136 | \fB\-M\fR 137 | and 138 | \fB\-MF\fR 139 | options\&. 140 | .RE 141 | .PP 142 | \fB\-MT\fR \fIfile\fR 143 | .RS 4 144 | Override the default name of the dependency target dependency target name\&. This is normally the same as the output filename, specified by the 145 | \fB\-o\fR 146 | option\&. 147 | .RE 148 | .PP 149 | \fB\-MQ\fR \fIfile\fR 150 | .RS 4 151 | The same as 152 | \fB\-MT\fR 153 | except it tries to quote characters that have special meaning in Makefile syntax\&. This is not foolproof, as not all characters with special meaning are quotable in Make\&. 154 | .RE 155 | .PP 156 | \fB\-MP\fR 157 | .RS 4 158 | Emit phony target\&. 159 | .RE 160 | .PP 161 | \fB\-O\fR \fInumber\fR 162 | .RS 4 163 | Optimize branch offsets\&. 164 | .sp 165 | .RS 4 166 | .ie n \{\ 167 | \h'-04'\(bu\h'+03'\c 168 | .\} 169 | .el \{\ 170 | .sp -1 171 | .IP \(bu 2.3 172 | .\} 173 | \fB\-O0\fR: No optimization 174 | .RE 175 | .sp 176 | .RS 4 177 | .ie n \{\ 178 | \h'-04'\(bu\h'+03'\c 179 | .\} 180 | .el \{\ 181 | .sp -1 182 | .IP \(bu 2.3 183 | .\} 184 | \fB\-O1\fR: Minimal optimization 185 | .RE 186 | .sp 187 | .RS 4 188 | .ie n \{\ 189 | \h'-04'\(bu\h'+03'\c 190 | .\} 191 | .el \{\ 192 | .sp -1 193 | .IP \(bu 2.3 194 | .\} 195 | \fB\-Ox\fR: Multipass optimization (default) 196 | .RE 197 | .RE 198 | .PP 199 | \fB\-o\fR \fIoutfile\fR 200 | .RS 4 201 | Specifies a precise name for the output file, overriding 202 | \fBnasm\fR\*(Aqs default means of determining it\&. 203 | .RE 204 | .PP 205 | \fB\-P\fR|\fB\-p\fR \fIfile\fR 206 | .RS 4 207 | Specifies a file to be pre\-included, before the main source file starts to be processed\&. 208 | .RE 209 | .PP 210 | \fB\-s\fR 211 | .RS 4 212 | Causes 213 | \fBnasm\fR 214 | to send its error messages and/or help text to stdout instead of stderr\&. 215 | .RE 216 | .PP 217 | \fB\-t\fR 218 | .RS 4 219 | Causes 220 | \fBnasm\fR 221 | to assemble in SciTech TASM compatible mode\&. 222 | .RE 223 | .PP 224 | \fB\-U\fR|\fB\-u\fR \fImacro\fR 225 | .RS 4 226 | Undefines a single\-line macro\&. 227 | .RE 228 | .PP 229 | \fB\-v\fR 230 | .RS 4 231 | Causes 232 | \fBnasm\fR 233 | to exit immediately, after displaying its version number\&. 234 | .RE 235 | .PP 236 | *\-W[no\-]foo\*(Aq 237 | .RS 4 238 | Causes 239 | \fBnasm\fR 240 | to enable or disable certain classes of warning messages, in gcc\-like style, for example 241 | \fB\-Worphan\-labels\fR 242 | or 243 | \fB\-Wno\-orphan\-labels\fR\&. 244 | .RE 245 | .PP 246 | \fB\-w\fR\fI[+\-]foo\fR 247 | .RS 4 248 | Causes 249 | \fBnasm\fR 250 | to enable or disable certain classes of warning messages, for example 251 | \fB\-w+orphan\-labels\fR 252 | or 253 | \fB\-w\-macro\-params\fR\&. 254 | .RE 255 | .PP 256 | \fB\-X\fR \fIformat\fR 257 | .RS 4 258 | Specifies error reporting format (gnu or vc)\&. 259 | .RE 260 | .PP 261 | \fB\-y\fR 262 | .RS 4 263 | Causes 264 | \fBnasm\fR 265 | to list supported debug formats\&. 266 | .RE 267 | .PP 268 | \fB\-Z\fR \fIfilename\fR 269 | .RS 4 270 | Causes 271 | \fBnasm\fR 272 | to redirect error messages to 273 | \fIfilename\fR\&. This option exists to support operating systems on which stderr is not easily redirected\&. 274 | .RE 275 | .PP 276 | \-\-prefix, \-\-postfix 277 | .RS 4 278 | Prepend or append (respectively) the given argument to all global or extern variables\&. 279 | .RE 280 | .SH "SYNTAX" 281 | .sp 282 | This man page does not fully describe the syntax of \fBnasm\fR\*(Aqs assembly language, but does give a summary of the differences from other assemblers\&. 283 | .sp 284 | \fIRegisters\fR have no leading \(oq%\(cq sign, unlike \fBgas\fR, and floating\-point stack registers are referred to as \fIst0\fR, \fIst1\fR, and so on\&. 285 | .sp 286 | \fIFloating\-point instructions\fR may use either the single\-operand form or the double\&. A \fITO\fR keyword is provided; thus, one could either write 287 | .sp 288 | .if n \{\ 289 | .RS 4 290 | .\} 291 | .nf 292 | fadd st0,st1 293 | fadd st1,st0 294 | .fi 295 | .if n \{\ 296 | .RE 297 | .\} 298 | .sp 299 | or one could use the alternative single\-operand forms 300 | .sp 301 | .if n \{\ 302 | .RS 4 303 | .\} 304 | .nf 305 | fadd st1 306 | fadd to st1 307 | .fi 308 | .if n \{\ 309 | .RE 310 | .\} 311 | .sp 312 | \fIUninitialised storage\fR is reserved using the \fIRESB\fR, \fIRESW\fR, \fIRESD\fR, \fIRESQ\fR, \fIREST\fR and \fIRESO\fR pseudo\-opcodes, each taking one parameter which gives the number of bytes, words, doublewords, quadwords or ten\-byte words to reserve\&. 313 | .sp 314 | \fIRepetition\fR of data items is not done by the \fIDUP\fR keyword as seen in DOS assemblers, but by the use of the \fITIMES\fR prefix, like this: 315 | .sp 316 | .if n \{\ 317 | .RS 4 318 | .\} 319 | .nf 320 | message: times 3 db \*(Aqabc\*(Aq 321 | times 64\-$+message db 0 322 | .fi 323 | .if n \{\ 324 | .RE 325 | .\} 326 | .sp 327 | which defines the string abcabcabc, followed by the right number of zero bytes to make the total length up to 64 bytes\&. 328 | .sp 329 | \fISymbol references\fR are always understood to be immediate (i\&.e\&. the address of the symbol), unless square brackets are used, in which case the contents of the memory location are used\&. Thus: 330 | .sp 331 | .if n \{\ 332 | .RS 4 333 | .\} 334 | .nf 335 | mov ax,wordvar 336 | .fi 337 | .if n \{\ 338 | .RE 339 | .\} 340 | .sp 341 | loads AX with the address of the variable wordvar, whereas 342 | .sp 343 | .if n \{\ 344 | .RS 4 345 | .\} 346 | .nf 347 | mov ax,[wordvar] 348 | mov ax,[wordvar+1] 349 | mov ax,[es:wordvar+bx] 350 | .fi 351 | .if n \{\ 352 | .RE 353 | .\} 354 | .sp 355 | all refer to the \fIcontents\fR of memory locations\&. The syntaxes 356 | .sp 357 | .if n \{\ 358 | .RS 4 359 | .\} 360 | .nf 361 | mov ax,es:wordvar[bx] 362 | es mov ax,wordvar[1] 363 | .fi 364 | .if n \{\ 365 | .RE 366 | .\} 367 | .sp 368 | are not legal at all, although the use of a segment register name as an instruction prefix is valid, and can be used with instructions such as \fILODSB\fR which can\(cqt be overridden any other way\&. 369 | .sp 370 | \fIConstants\fR may be expressed numerically in most formats: a trailing H, Q or B denotes hex, octal or binary respectively, and a leading \(oq0x\(cq or \(oq$\(cq denotes hex as well\&. Leading zeros are not treated specially at all\&. Character constants may be enclosed in single or double quotes; there is no escape character\&. The ordering is little\-endian (reversed), so that the character constant \fI\*(Aqabcd\fR\*(Aq denotes 0x64636261 and not 0x61626364\&. 371 | .sp 372 | Local labels begin with a period, and their \(oqlocality\(cq is granted by the assembler prepending the name of the previous non\-local symbol\&. Thus declaring a label \(oq\&.loop\(cq after a label \(oqlabel\(cq has actually defined a symbol called \(oqlabel\&.loop\(cq\&. 373 | .SH "DIRECTIVES" 374 | .sp 375 | \fISECTION\fR \fIname\fR or \fISEGMENT\fR \fIname\fR causes \fBnasm\fR to direct all following code to the named section\&. Section names vary with output file format, although most formats support the names \fI\&.text\fR, \fI\&.data\fR and \fI\&.bss\fR\&. (The exception is the \fIobj\fR format, in which all segments are user\-definable\&.) 376 | .sp 377 | \fIABSOLUTE\fR \fIaddress\fR causes \fBnasm\fR to position its notional assembly point at an absolute address: so no code or data may be generated, but you can use \fIRESB\fR, \fIRESW\fR and \fIRESD\fR to move the assembly point further on, and you can define labels\&. So this directive may be used to define data structures\&. When you have finished doing absolute assembly, you must issue another \fISECTION\fR directive to return to normal assembly\&. 378 | .sp 379 | \fIBITS\fR \fI16\fR, \fIBITS\fR \fI32\fR or \fIBITS\fR \fI64\fR switches the default processor mode for which \fBnasm\fR is generating code: it is equivalent to \fIUSE16\fR or \fIUSE32\fR in DOS assemblers\&. 380 | .sp 381 | \fIEXTERN\fR \fIsymbol\fR and \fIGLOBAL\fR \fIsymbol\fR import and export symbol definitions, respectively, from and to other modules\&. Note that the \fIGLOBAL\fR directive must appear before the definition of the symbol it refers to\&. 382 | .sp 383 | \fISTRUC\fR \fIstrucname\fR and \fIENDSTRUC\fR, when used to bracket a number of \fIRESB\fR, \fIRESW\fR or similar instructions, define a data structure\&. In addition to defining the offsets of the structure members, the construct also defines a symbol for the size of the structure, which is simply the structure name with \fIsize\fR tacked on to the end\&. 384 | .SH "FORMAT-SPECIFIC DIRECTIVES" 385 | .sp 386 | \fIORG\fR \fIaddress\fR is used by the \fIbin\fR flat\-form binary output format, and specifies the address at which the output code will eventually be loaded\&. 387 | .sp 388 | \fIGROUP\fR \fIgrpname\fR \fIseg1\fR \fIseg2\fR\&... is used by the obj (Microsoft 16\-bit) output format, and defines segment groups\&. This format also uses \fIUPPERCASE\fR, which directs that all segment, group and symbol names output to the object file should be in uppercase\&. Note that the actual assembly is still case sensitive\&. 389 | .sp 390 | \fILIBRARY\fR \fIlibname\fR is used by the \fIrdf\fR output format, and causes a dependency record to be written to the output file which indicates that the program requires a certain library in order to run\&. 391 | .SH "MACRO PREPROCESSOR" 392 | .sp 393 | Single\-line macros are defined using the \fI%define\fR or \fI%idefine\fR commands, in a similar fashion to the C preprocessor\&. They can be overloaded with respect to number of parameters, although defining a macro with no parameters prevents the definition of any macro with the same name taking parameters, and vice versa\&. \fI%define\fR defines macros whose names match case\-sensitively, whereas \fI%idefine\fR defines case\-insensitive macros\&. 394 | .sp 395 | Multi\-line macros are defined using \fI%macro\fR and \fI%imacro\fR (the distinction is the same as that between \fI%define\fR and \fI%idefine\fR), whose syntax is as follows 396 | .sp 397 | .if n \{\ 398 | .RS 4 399 | .\} 400 | .nf 401 | %macro name minprm[\-maxprm][+][\&.nolist] [defaults] 402 | 403 | %endmacro 404 | .fi 405 | .if n \{\ 406 | .RE 407 | .\} 408 | .sp 409 | Again, these macros may be overloaded\&. The trailing plus sign indicates that any parameters after the last one get subsumed, with their separating commas, into the last parameter\&. The \fIdefaults\fR part can be used to specify defaults for unspecified macro parameters after \fIminparam\fR\&. \fI%endm\fR is a valid synonym for \fI%endmacro\fR\&. 410 | .sp 411 | To refer to the macro parameters within a macro expansion, you use \fI%1\fR, \fI%2\fR and so on\&. You can also enforce that a macro parameter should contain a condition code by using \fI%+1\fR, and you can invert the condition code by using \fI%\-1\fR\&. You can also define a label specific to a macro invocation by prefixing it with a double \(oq%\(cq sign\&. 412 | .sp 413 | Files can be included using the \fI%include\fR directive, which works like C\&. 414 | .sp 415 | The preprocessor has a \(oqcontext stack\(cq, which may be used by one macro to store information that a later one will retrieve\&. You can push a context on the stack using \fI%push\fR, remove one using \fI%pop\fR, and change the name of the top context (without disturbing any associated definitions) using \fI%repl\fR\&. Labels and \fI%define\fR macros specific to the top context may be defined by prefixing their names with %$, and things specific to the next context down with %$$, and so on\&. 416 | .sp 417 | Conditional assembly is done by means of \fI%ifdef\fR, \fI%ifndef\fR, \fI%else\fR and \fI%endif\fR as in C\&. (Except that \fI%ifdef\fR can accept several putative macro names, and will evaluate TRUE if any of them is defined\&.) In addition, the directives \fI%ifctx\fR and \fI%ifnctx\fR can be used to condition on the name of the top context on the context stack\&. The obvious set of \(oqelse\-if\(cq directives, \fI%elifdef\fR, \fI%elifndef\fR, \fI%elifctx\fR and \fI%elifnctx\fR are also supported\&. 418 | .SH "BUGS" 419 | .sp 420 | Please report bugs through the bug tracker function at \m[blue]\fBhttp://nasm\&.us\fR\m[]\&. 421 | .SH "SEE ALSO" 422 | .sp 423 | \fBas\fR(1), \fBld\fR(1)\&. 424 | -------------------------------------------------------------------------------- /nasm/man1/ndisasm.1: -------------------------------------------------------------------------------- 1 | '\" t 2 | .\" Title: ndisasm 3 | .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] 4 | .\" Generator: DocBook XSL Stylesheets v1.78.1 5 | .\" Date: 10/20/2014 6 | .\" Manual: The Netwide Assembler Project 7 | .\" Source: NASM 8 | .\" Language: English 9 | .\" 10 | .TH "NDISASM" "1" "10/20/2014" "NASM" "The Netwide Assembler Project" 11 | .\" ----------------------------------------------------------------- 12 | .\" * Define some portability stuff 13 | .\" ----------------------------------------------------------------- 14 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 15 | .\" http://bugs.debian.org/507673 16 | .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html 17 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 18 | .ie \n(.g .ds Aq \(aq 19 | .el .ds Aq ' 20 | .\" ----------------------------------------------------------------- 21 | .\" * set default formatting 22 | .\" ----------------------------------------------------------------- 23 | .\" disable hyphenation 24 | .nh 25 | .\" disable justification (adjust text to left margin only) 26 | .ad l 27 | .\" ----------------------------------------------------------------- 28 | .\" * MAIN CONTENT STARTS HERE * 29 | .\" ----------------------------------------------------------------- 30 | .SH "NAME" 31 | ndisasm \- the Netwide Disassembler, an 80x86 binary file disassembler 32 | .SH "SYNOPSIS" 33 | .sp 34 | \fBndisasm\fR [ \fB\-o\fR origin ] [ \fB\-s\fR sync\-point [\&...]] [ \fB\-a\fR | \fB\-i\fR ] [ \fB\-b\fR bits ] [ \fB\-u\fR ] [ \fB\-e\fR hdrlen ] [ \fB\-p\fR vendor ] [ \fB\-k\fR offset,length [\&...]] infile 35 | .SH "DESCRIPTION" 36 | .sp 37 | The \fBndisasm\fR command generates a disassembly listing of the binary file infile and directs it to stdout\&. 38 | .SH "OPTIONS" 39 | .PP 40 | \fB\-h\fR 41 | .RS 4 42 | Causes 43 | \fBndisasm\fR 44 | to exit immediately, after giving a summary of its invocation options\&. 45 | .RE 46 | .PP 47 | \fB\-r\fR|\fB\-v\fR 48 | .RS 4 49 | Causes 50 | \fBndisasm\fR 51 | to exit immediately, after displaying its version number\&. 52 | .RE 53 | .PP 54 | \fB\-o\fR \fIorigin\fR 55 | .RS 4 56 | Specifies the notional load address for the file\&. This option causes 57 | \fBndisasm\fR 58 | to get the addresses it lists down the left hand margin, and the target addresses of PC\-relative jumps and calls, right\&. 59 | .RE 60 | .PP 61 | \fB\-s\fR \fIsync\-point\fR 62 | .RS 4 63 | Manually specifies a synchronisation address, such that 64 | \fBndisasm\fR 65 | will not output any machine instruction which encompasses bytes on both sides of the address\&. Hence the instruction which starts at that address will be correctly disassembled\&. 66 | .RE 67 | .PP 68 | \fB\-e\fR \fIhdrlen\fR 69 | .RS 4 70 | Specifies a number of bytes to discard from the beginning of the file before starting disassembly\&. This does not count towards the calculation of the disassembly offset: the first 71 | \fIdisassembled\fR 72 | instruction will be shown starting at the given load address\&. 73 | .RE 74 | .PP 75 | \fB\-k\fR \fIoffset,length\fR 76 | .RS 4 77 | Specifies that 78 | \fIlength\fR 79 | bytes, starting from disassembly offset 80 | \fIoffset\fR, should be skipped over without generating any output\&. The skipped bytes still count towards the calculation of the disassembly offset\&. 81 | .RE 82 | .PP 83 | \fB\-a\fR|\fB\-i\fR 84 | .RS 4 85 | Enables automatic (or intelligent) sync mode, in which 86 | \fBndisasm\fR 87 | will attempt to guess where synchronisation should be performed, by means of examining the target addresses of the relative jumps and calls it disassembles\&. 88 | .RE 89 | .PP 90 | \fB\-b\fR \fIbits\fR 91 | .RS 4 92 | Specifies 16\-, 32\- or 64\-bit mode\&. The default is 16\-bit mode\&. 93 | .RE 94 | .PP 95 | \fB\-u\fR 96 | .RS 4 97 | Specifies 32\-bit mode, more compactly than using \(oq\-b 32\(cq\&. 98 | .RE 99 | .PP 100 | \fB\-p\fR \fIvendor\fR 101 | .RS 4 102 | Prefers instructions as defined by 103 | \fIvendor\fR 104 | in case of a conflict\&. Known 105 | \fIvendor\fR 106 | names include 107 | \fBintel\fR, 108 | \fBamd\fR, 109 | \fBcyrix\fR, and 110 | \fBidt\fR\&. The default is 111 | \fBintel\fR\&. 112 | .RE 113 | .SH "RESTRICTIONS" 114 | .sp 115 | \fBndisasm\fR only disassembles binary files: it has no understanding of the header information present in object or executable files\&. If you want to disassemble an object file, you should probably be using \fBobjdump\fR(1)\&. 116 | .sp 117 | Auto\-sync mode won\(cqt necessarily cure all your synchronisation problems: a sync marker can only be placed automatically if a jump or call instruction is found to refer to it \fIbefore\fR \fBndisasm\fR actually disassembles that part of the code\&. Also, if spurious jumps or calls result from disassembling non\-machine\-code data, sync markers may get placed in strange places\&. Feel free to turn auto\-sync off and go back to doing it manually if necessary\&. 118 | .SH "SEE ALSO" 119 | .sp 120 | \fBobjdump\fR(1) 121 | -------------------------------------------------------------------------------- /nasm/man1/rdf2bin.1: -------------------------------------------------------------------------------- 1 | .TH RDF2BIN 1 "September 6, 1999" "Debian Project" "Debian Manual" 2 | .SH NAME 3 | rdf2bin, rdf2com \- convert an RDOFF object file to flat binary 4 | .SH SYNOPSIS 5 | .B rdf2bin 6 | .RI "[\-o " relocation-origin ] 7 | .RI "[\-p " segment-alignment ] 8 | .RI "[\-f " format ] 9 | .I input-file 10 | .I output-file 11 | .br 12 | .B rdf2com 13 | .RI "[\-p " segment-alignment ] 14 | .I input-file 15 | .I output-file 16 | .br 17 | .B rdf2ith 18 | .RI "[\-o " relocation-origin ] 19 | .RI "[\-p " segment-alignment ] 20 | .I input-file 21 | .I output-file 22 | .br 23 | .B rdf2srec 24 | .RI "[\-o " relocation-origin ] 25 | .RI "[\-p " segment-alignment ] 26 | .I input-file 27 | .I output-file 28 | .SH OPTIONS 29 | .TP 30 | .RI "\-o " relocation-origin 31 | Relocate at origin 32 | .IR relocation-origin . 33 | If invoked as 34 | .BR rdf2com , 35 | the default relocation origin will be 0x100. Else, the default origin is 0. 36 | .TP 37 | .RI "\-p " segment-alignment 38 | Pad segments until their size is a multiple of 39 | .IR segment-alignment . 40 | By default, 16 is used. 41 | .TP 42 | .RI "\-f " format 43 | Specify the output format. The currently supported formats are binary 44 | .RI ( bin ), 45 | DOS COM (binary with origin 0x100) 46 | .RI ( com ) 47 | Intel hex 48 | .RI ( ith 49 | or 50 | .IR ihx ), 51 | and 52 | Motorola S-Records 53 | .RI ( srec ). 54 | If not specified, the format is set by the command name. 55 | .SH AUTHORS 56 | Julian Hall , H. Peter Anvin . 57 | .PP 58 | This manual page was written by Matej Vela . 59 | .SH BUGS 60 | This utility currently only supports the classic segments 61 | .IR .text , 62 | .I .data 63 | and 64 | .IR .bss . 65 | 66 | -------------------------------------------------------------------------------- /nasm/man1/rdf2com.1: -------------------------------------------------------------------------------- 1 | .so man1/rdf2bin.1 2 | -------------------------------------------------------------------------------- /nasm/man1/rdf2ihx.1: -------------------------------------------------------------------------------- 1 | .so man1/rdf2bin.1 2 | -------------------------------------------------------------------------------- /nasm/man1/rdf2ith.1: -------------------------------------------------------------------------------- 1 | .so man1/rdf2bin.1 2 | -------------------------------------------------------------------------------- /nasm/man1/rdf2srec.1: -------------------------------------------------------------------------------- 1 | .so man1/rdf2bin.1 2 | -------------------------------------------------------------------------------- /nasm/man1/rdfdump.1: -------------------------------------------------------------------------------- 1 | .TH RDFDUMP 1 "September 6, 1999" "Debian Project" "Debian Manual" 2 | .SH NAME 3 | rdfdump \- dumps an RDOFF object in human-readable form 4 | .SH SYNOPSIS 5 | .B rdfdump 6 | [-v] 7 | .RI < filename > 8 | .SH DESCRIPTION 9 | .B rdfdump 10 | prints a list of the header records in an RDOFF object in human-readable 11 | form, and optionally prints a hex dump of the contents of the segments. 12 | .PP 13 | .B rdfdump 14 | supports both version 1 and 2 of RDOFF. It will give warnings if the RDOFF2 15 | format is violated (it looks for incorrect lengths for header records, and 16 | checks the overall length count at the start of the file). 17 | .SH OPTIONS 18 | .TP 19 | -v 20 | Print a hex dump of the contents of the segments. 21 | .SH AUTHORS 22 | Julian Hall . 23 | .PP 24 | This manual page was written by Matej Vela . 25 | -------------------------------------------------------------------------------- /nasm/man1/rdflib.1: -------------------------------------------------------------------------------- 1 | .TH RDFLIB 1 "September 6, 1999" "Debian Project" "Debian Manual" 2 | .SH NAME 3 | rdflib \- manage a library file for use with ldrdf(1) 4 | .SH SYNOPSIS 5 | .B rdflib 6 | .I command 7 | .I arguments 8 | .SH DESCRIPTION 9 | .B rdflib 10 | manages a library file which can be used by 11 | .BR ldrdf (1). 12 | It is supplied with a shell script 13 | .B makelib 14 | which should probably be used to create libraries. 15 | .SH COMMANDS 16 | .TP 17 | .BI c " library-file" 18 | Create (or truncate) a library. 19 | .TP 20 | .BI a " library-file object-file module" 21 | Add the 22 | .I object-file 23 | to the library under the name 24 | .IR module . 25 | .TP 26 | .BI x " library-file module object-file" 27 | Extract a 28 | .I module 29 | from the library to the file 30 | .IR object-file . 31 | .TP 32 | .B t " library-file" 33 | Display a list of modules in the library. 34 | .SH NOTES 35 | A remove command will be added soon. 36 | .SH AUTHORS 37 | Julian Hall . 38 | .PP 39 | This manual page was written by Matej Vela . 40 | -------------------------------------------------------------------------------- /nasm/man1/rdx.1: -------------------------------------------------------------------------------- 1 | .TH RDX 1 "September 6, 1999" "Debian Project" "Debian Manual" 2 | .SH NAME 3 | rdx \- load and execute an RDOFF object 4 | .SH SYNOPSIS 5 | .B rdx 6 | .I object 7 | .SH DESCRIPTION 8 | .B rdx 9 | loads an RDOFF 10 | .IR object , 11 | and then calls 12 | .RB ` _main ', 13 | which it expects to be a C-style function, accepting two parameters, 14 | .I argc 15 | and 16 | .I argv 17 | in normal C style. 18 | .SH AUTHORS 19 | Julian Hall . 20 | .PP 21 | This manual page was written by Matej Vela . 22 | -------------------------------------------------------------------------------- /nasm/nasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yorkie/lv/2fb5e264abffa34959ac601567ab608535a79a79/nasm/nasm -------------------------------------------------------------------------------- /nasm/nasmdoc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yorkie/lv/2fb5e264abffa34959ac601567ab608535a79a79/nasm/nasmdoc.pdf -------------------------------------------------------------------------------- /nasm/ndisasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yorkie/lv/2fb5e264abffa34959ac601567ab608535a79a79/nasm/ndisasm -------------------------------------------------------------------------------- /nasm/rdf2bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yorkie/lv/2fb5e264abffa34959ac601567ab608535a79a79/nasm/rdf2bin -------------------------------------------------------------------------------- /nasm/rdf2com: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yorkie/lv/2fb5e264abffa34959ac601567ab608535a79a79/nasm/rdf2com -------------------------------------------------------------------------------- /nasm/rdf2ihx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yorkie/lv/2fb5e264abffa34959ac601567ab608535a79a79/nasm/rdf2ihx -------------------------------------------------------------------------------- /nasm/rdf2ith: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yorkie/lv/2fb5e264abffa34959ac601567ab608535a79a79/nasm/rdf2ith -------------------------------------------------------------------------------- /nasm/rdf2srec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yorkie/lv/2fb5e264abffa34959ac601567ab608535a79a79/nasm/rdf2srec -------------------------------------------------------------------------------- /nasm/rdfdump: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yorkie/lv/2fb5e264abffa34959ac601567ab608535a79a79/nasm/rdfdump -------------------------------------------------------------------------------- /nasm/rdflib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yorkie/lv/2fb5e264abffa34959ac601567ab608535a79a79/nasm/rdflib -------------------------------------------------------------------------------- /nasm/rdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yorkie/lv/2fb5e264abffa34959ac601567ab608535a79a79/nasm/rdx -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lv", 3 | "version": "0.0.3", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "balanced-match": { 8 | "version": "1.0.0", 9 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", 10 | "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" 11 | }, 12 | "brace-expansion": { 13 | "version": "1.1.11", 14 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", 15 | "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", 16 | "requires": { 17 | "balanced-match": "^1.0.0", 18 | "concat-map": "0.0.1" 19 | } 20 | }, 21 | "cli": { 22 | "version": "1.0.1", 23 | "resolved": "https://registry.npmjs.org/cli/-/cli-1.0.1.tgz", 24 | "integrity": "sha1-IoF1NPJL+klQw01TLUjsvGIbjBQ=", 25 | "requires": { 26 | "exit": "0.1.2", 27 | "glob": "^7.1.1" 28 | } 29 | }, 30 | "concat-map": { 31 | "version": "0.0.1", 32 | "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", 33 | "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" 34 | }, 35 | "console-browserify": { 36 | "version": "1.1.0", 37 | "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.1.0.tgz", 38 | "integrity": "sha1-8CQcRXMKn8YyOyBtvzjtx0HQuxA=", 39 | "requires": { 40 | "date-now": "^0.1.4" 41 | } 42 | }, 43 | "core-util-is": { 44 | "version": "1.0.2", 45 | "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", 46 | "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" 47 | }, 48 | "date-now": { 49 | "version": "0.1.4", 50 | "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", 51 | "integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs=" 52 | }, 53 | "deep-equal": { 54 | "version": "0.0.0", 55 | "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-0.0.0.tgz", 56 | "integrity": "sha1-mWedO70EcVb81FDT0B7rkGhpHoM=", 57 | "dev": true 58 | }, 59 | "defined": { 60 | "version": "0.0.0", 61 | "resolved": "https://registry.npmjs.org/defined/-/defined-0.0.0.tgz", 62 | "integrity": "sha1-817qfXBekzuvE7LwOz+D2SFAOz4=", 63 | "dev": true 64 | }, 65 | "dom-serializer": { 66 | "version": "0.2.1", 67 | "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.2.1.tgz", 68 | "integrity": "sha512-sK3ujri04WyjwQXVoK4PU3y8ula1stq10GJZpqHIUgoGZdsGzAGu65BnU3d08aTVSvO7mGPZUc0wTEDL+qGE0Q==", 69 | "requires": { 70 | "domelementtype": "^2.0.1", 71 | "entities": "^2.0.0" 72 | }, 73 | "dependencies": { 74 | "domelementtype": { 75 | "version": "2.0.1", 76 | "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.0.1.tgz", 77 | "integrity": "sha512-5HOHUDsYZWV8FGWN0Njbr/Rn7f/eWSQi1v7+HsUVwXgn8nWWlL64zKDkS0n8ZmQ3mlWOMuXOnR+7Nx/5tMO5AQ==" 78 | }, 79 | "entities": { 80 | "version": "2.0.0", 81 | "resolved": "https://registry.npmjs.org/entities/-/entities-2.0.0.tgz", 82 | "integrity": "sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw==" 83 | } 84 | } 85 | }, 86 | "domelementtype": { 87 | "version": "1.3.1", 88 | "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.1.tgz", 89 | "integrity": "sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==" 90 | }, 91 | "domhandler": { 92 | "version": "2.3.0", 93 | "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.3.0.tgz", 94 | "integrity": "sha1-LeWaCCLVAn+r/28DLCsloqir5zg=", 95 | "requires": { 96 | "domelementtype": "1" 97 | } 98 | }, 99 | "domutils": { 100 | "version": "1.5.1", 101 | "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz", 102 | "integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=", 103 | "requires": { 104 | "dom-serializer": "0", 105 | "domelementtype": "1" 106 | } 107 | }, 108 | "entities": { 109 | "version": "1.0.0", 110 | "resolved": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz", 111 | "integrity": "sha1-sph6o4ITR/zeZCsk/fyeT7cSvyY=" 112 | }, 113 | "esprima": { 114 | "version": "1.0.4", 115 | "resolved": "https://registry.npmjs.org/esprima/-/esprima-1.0.4.tgz", 116 | "integrity": "sha1-n1V+CPw7TSbs6d00+Pv0drYlha0=" 117 | }, 118 | "exit": { 119 | "version": "0.1.2", 120 | "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", 121 | "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=" 122 | }, 123 | "fs.realpath": { 124 | "version": "1.0.0", 125 | "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", 126 | "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" 127 | }, 128 | "glob": { 129 | "version": "7.1.4", 130 | "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", 131 | "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", 132 | "requires": { 133 | "fs.realpath": "^1.0.0", 134 | "inflight": "^1.0.4", 135 | "inherits": "2", 136 | "minimatch": "^3.0.4", 137 | "once": "^1.3.0", 138 | "path-is-absolute": "^1.0.0" 139 | } 140 | }, 141 | "htmlparser2": { 142 | "version": "3.8.3", 143 | "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz", 144 | "integrity": "sha1-mWwosZFRaovoZQGn15dX5ccMEGg=", 145 | "requires": { 146 | "domelementtype": "1", 147 | "domhandler": "2.3", 148 | "domutils": "1.5", 149 | "entities": "1.0", 150 | "readable-stream": "1.1" 151 | } 152 | }, 153 | "inflight": { 154 | "version": "1.0.6", 155 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", 156 | "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", 157 | "requires": { 158 | "once": "^1.3.0", 159 | "wrappy": "1" 160 | } 161 | }, 162 | "inherits": { 163 | "version": "2.0.4", 164 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 165 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 166 | }, 167 | "isarray": { 168 | "version": "0.0.1", 169 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", 170 | "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" 171 | }, 172 | "jshint": { 173 | "version": "2.10.2", 174 | "resolved": "https://registry.npmjs.org/jshint/-/jshint-2.10.2.tgz", 175 | "integrity": "sha512-e7KZgCSXMJxznE/4WULzybCMNXNAd/bf5TSrvVEq78Q/K8ZwFpmBqQeDtNiHc3l49nV4E/+YeHU/JZjSUIrLAA==", 176 | "requires": { 177 | "cli": "~1.0.0", 178 | "console-browserify": "1.1.x", 179 | "exit": "0.1.x", 180 | "htmlparser2": "3.8.x", 181 | "lodash": "~4.17.11", 182 | "minimatch": "~3.0.2", 183 | "shelljs": "0.3.x", 184 | "strip-json-comments": "1.0.x" 185 | } 186 | }, 187 | "jsonify": { 188 | "version": "0.0.0", 189 | "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", 190 | "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=", 191 | "dev": true 192 | }, 193 | "lodash": { 194 | "version": "4.17.15", 195 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", 196 | "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" 197 | }, 198 | "minimatch": { 199 | "version": "3.0.4", 200 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", 201 | "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", 202 | "requires": { 203 | "brace-expansion": "^1.1.7" 204 | } 205 | }, 206 | "minimist": { 207 | "version": "0.0.10", 208 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", 209 | "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=" 210 | }, 211 | "once": { 212 | "version": "1.4.0", 213 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", 214 | "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", 215 | "requires": { 216 | "wrappy": "1" 217 | } 218 | }, 219 | "path-is-absolute": { 220 | "version": "1.0.1", 221 | "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", 222 | "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" 223 | }, 224 | "readable-stream": { 225 | "version": "1.1.14", 226 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", 227 | "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", 228 | "requires": { 229 | "core-util-is": "~1.0.0", 230 | "inherits": "~2.0.1", 231 | "isarray": "0.0.1", 232 | "string_decoder": "~0.10.x" 233 | } 234 | }, 235 | "shelljs": { 236 | "version": "0.3.0", 237 | "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz", 238 | "integrity": "sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=" 239 | }, 240 | "string_decoder": { 241 | "version": "0.10.31", 242 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", 243 | "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" 244 | }, 245 | "strip-json-comments": { 246 | "version": "1.0.4", 247 | "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-1.0.4.tgz", 248 | "integrity": "sha1-HhX7ysl9Pumb8tc7TGVrCCu6+5E=" 249 | }, 250 | "tape": { 251 | "version": "1.0.4", 252 | "resolved": "https://registry.npmjs.org/tape/-/tape-1.0.4.tgz", 253 | "integrity": "sha1-4ujlxt0/AP3CpeRRT2L8Ih5Z+cQ=", 254 | "dev": true, 255 | "requires": { 256 | "deep-equal": "~0.0.0", 257 | "defined": "~0.0.0", 258 | "jsonify": "~0.0.0", 259 | "through": "~2.3.4" 260 | } 261 | }, 262 | "through": { 263 | "version": "2.3.8", 264 | "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", 265 | "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", 266 | "dev": true 267 | }, 268 | "wrappy": { 269 | "version": "1.0.2", 270 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 271 | "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" 272 | } 273 | } 274 | } 275 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lv", 3 | "version": "0.0.3", 4 | "description": "a compiler for javascript", 5 | "main": "index.js", 6 | "bin": { 7 | "lv": "./bin/lv" 8 | }, 9 | "scripts": { 10 | "test": "tape tests/*.js", 11 | "asm": "sh build.sh tests/parser-test" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/yorkie/lv.git" 16 | }, 17 | "keywords": [ 18 | "javascript", 19 | "assembly", 20 | "language" 21 | ], 22 | "dependencies": { 23 | "esprima": "~1.0.4", 24 | "jshint": "^2.5.4", 25 | "minimist": "~0.0.8" 26 | }, 27 | "devDependencies": { 28 | "tape": "~1.0.0" 29 | }, 30 | "author": "Yorkie Neil ", 31 | "license": "MIT", 32 | "bugs": { 33 | "url": "https://github.com/yorkie/lv/issues" 34 | }, 35 | "homepage": "https://github.com/yorkie/lv" 36 | } 37 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | *.o -------------------------------------------------------------------------------- /tests/asm-test.asm: -------------------------------------------------------------------------------- 1 | section .bss 2 | 3 | section .text 4 | 5 | global main 6 | 7 | main: 8 | 9 | push ebp 10 | mov ebp, esp 11 | sub esp, 10 12 | 13 | %push main_context 14 | %stacksize large 15 | 16 | 17 | 18 | 19 | 20 | ; system call: exit 21 | push dword 0 22 | mov eax, 1 23 | sub esp, 4 24 | int 128 25 | 26 | 27 | %pop 28 | 29 | mov esp, ebp 30 | pop ebp 31 | ret 32 | 33 | section .data 34 | 35 | __sys__type_integer: dd 0x0 36 | __sys__type_double: dd 0x1 37 | __sys__type_char: dd 0x2 38 | __sys__type_boolean: dd 0x3 39 | __sys__type_array: dd 0x4 40 | __sys__type_string: dd 0x5 41 | __sys__type_object: dd 0x6 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /tests/asm.js: -------------------------------------------------------------------------------- 1 | 2 | const fs = require('fs'); 3 | const path = require('path'); 4 | const exec = require('child_process').exec; 5 | const asm = require('../lib/asm'); 6 | 7 | const tar = new asm(); 8 | const outputPath = path.join(__dirname, './outputs/asm-test') 9 | 10 | fs.writeFile(outputPath, tar.toString(), function() { 11 | console.log('write successfully'); 12 | const ch = exec(`sh build.sh ${outputPath}`); 13 | ch.stdout.pipe(process.stdout); 14 | ch.stderr.pipe(process.stderr); 15 | }); 16 | -------------------------------------------------------------------------------- /tests/parser-test.asm: -------------------------------------------------------------------------------- 1 | section .text 2 | 3 | global main 4 | 5 | main: 6 | 7 | ; system call: write 8 | push dword _lamb_var_69_len 9 | push dword _lamb_var_69 10 | push dword 1 11 | mov eax, 4 12 | sub esp, 4 13 | int 128 14 | add esp, 16 15 | 16 | ; system call: exit 17 | push dword 0 18 | mov eax, 1 19 | sub esp, 4 20 | int 128 21 | 22 | section .data 23 | 24 | _lamb_var_69: db "Hello World!", 0x0a 25 | _lamb_var_69_len: equ $-_lamb_var_69 26 | 27 | -------------------------------------------------------------------------------- /tests/parser.js: -------------------------------------------------------------------------------- 1 | 2 | var fs = require('fs'); 3 | var path = require('path'); 4 | var Parser = require('../lib/parser'); 5 | 6 | var parser = new Parser('../examples/simple.js'); 7 | 8 | parser.on('error', function(err) { 9 | console.error(err); 10 | }) 11 | 12 | parser.on('done', function(program) { 13 | fs.writeFile(path.join(__dirname, './parser-test.asm'), program); 14 | }); 15 | -------------------------------------------------------------------------------- /tests/syscall.js: -------------------------------------------------------------------------------- 1 | 2 | const syscalls = require('../lib/syscall'); 3 | console.log(syscalls.exit()); 4 | --------------------------------------------------------------------------------