function db(func) { let lines = []; for (let i = 0; i < 256; i += 16) { let items = []; for (let j = 0; j < 16; j++) { let x = i + j; items.push(func(x)); } lines.push(' .byte ' + items.join(', ')); } return lines.join('\n'); } let squares = []; for (let i = 0; i < 512; i++) { squares.push(Math.trunc((i * i + 1) / 2)); } console.log( `.segment "TABLES" .export mul_lobyte256 .export mul_hibyte256 .export mul_hibyte512 .export sqr_lobyte .export sqr_hibyte ; (i * i + 1) / 2 for the multiplier .align 256 mul_lobyte256: ${db((i) => squares[i] & 0xff)} .align 256 mul_hibyte256: ${db((i) => (squares[i] >> 8) & 0xff)} .align 256 mul_hibyte512: ${db((i) => (squares[i + 256] >> 8) & 0xff)} ; (i * i) for the plain squares .align 256 sqr_lobyte: ${db((i) => (i * i) & 0xff)} .align 256 sqr_hibyte: ${db((i) => ((i * i) >> 8) & 0xff)} `);