Created
June 17, 2020 02:25
-
-
Save brandonros/4008b6a6bf3d8c002fa85ab75e9baf02 to your computer and use it in GitHub Desktop.
Parse TriCore instructions from hex in node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const parseInstructions = (input) => { | |
const instructions = [] | |
let i = 0 | |
while (i < input.length) { | |
const instructionLow = input.readUInt16LE(i) | |
const is16Bit = (instructionLow & 0x01) === 0x00 | |
if (is16Bit) { | |
instructions.push(instructionLow) | |
i += 2 | |
} else { | |
const instructionHigh = input.readUInt16LE(i + 2) | |
const instruction = ((instructionHigh << 16) | instructionLow) >>> 0 | |
instructions.push(instruction) | |
i += 4 | |
} | |
} | |
return instructions | |
} | |
const input = Buffer.from('3b 00 80 40 91 10 00 f6 9b 04 54 40 d9 ff 08 4a 82 05 20 08 82 16 40 a4 2d 0f 00 00 3b 50 44 04 54 af 9b 70 35 05 0b 0f 10 21 00 90'.replace(/ /g, ''), 'hex') | |
console.log(parseInstructions(input)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment