Skip to content

Instantly share code, notes, and snippets.

@guisehn
Last active September 27, 2017 00:10
Show Gist options
  • Save guisehn/f408a276bf7c4049fba37a9b6373553a to your computer and use it in GitHub Desktop.
Save guisehn/f408a276bf7c4049fba37a9b6373553a to your computer and use it in GitHub Desktop.
arr=[]
len=4
for (sub=0; sub<=0; sub++) {
for (i = 0; i < Math.pow(2,len); i++) {
for (j = 0; j < Math.pow(2,len); j++) {
let obj = {
sub: sub,
a: i.toString(2).padStart(len,'0'),
b: j.toString(2).padStart(len,'0'),
}
if (sub) obj.res = i-j; else obj.res = i+j;
obj.res = obj.res.toString(2).padStart(len+1,'0');
arr.push(obj)
}
}
}
arr=arr.map(itemToStr).join('\n');
function itemToStr(obj) {
let str = `Sub <= '${obj.sub}';\n`;
for(i=0;i<len;i++) str += `A${len-1-i} <= '${obj.a[i]}'; `;
str += '\n';
for(i=0;i<len;i++) str += `B${len-1-i} <= '${obj.b[i]}'; `;
str += '\n';
for(i=0;i<len+1;i++) str += `Val_S${len-i} := '${obj.res[i]}'; `;
str += '\ntestar;\n';
str += 'wait for 1 ns;\n';
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment