Web based MIPS assembler and emulator

bootload.js 587B

1234567891011121314151617
  1. // put some stuff into memory
  2. const memory = require('../memory/memory.js')
  3. const utils = require('./utils.js')
  4. // Pads a string with 0's until it is the desired length
  5. const padAddress = (addr, len, ch) => (addr.length >= len) ?
  6. addr : ch.repeat(len-addr.length).concat(addr)
  7. const incrAddr = (addr, n) => padAddress((parseInt(addr, 2) + n).toString(2), 32, '0')
  8. const baseAddr = '0xbfc00000'
  9. const loadBootCode = (code) => code.map((c, i) => memory.storeWord(incrAddr(utils.hex2bin(baseAddr, 32), i*4), utils.hex2bin(c, 32)))
  10. module.exports = {
  11. 'loadBootCode': loadBootCode
  12. }