快活林资源网 Design By www.csstdc.com
本文实例讲述了JavaScript实现MIPS乘法模拟的方法。分享给大家供大家参考。具体如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>MIPS MULTIPLICATION SIMULATOR </title> <script type="text/javascript"> /* CREATED BY SERKAN SENDUR */ function StringToNumberArray(Bin) { var numberArray = []; for (var i = 0; i < Bin.length; i++) { numberArray.push(Bin.substring(i, i + 1)); } return numberArray; } function ConvertToDecimal(Bin) { var decimalNumber = 0; var numberArray = StringToNumberArray(Bin); numberArray.reverse(); for (var i = 0; i < numberArray.length; i++) { decimalNumber += numberArray[i] * Math.pow(2, i); } return decimalNumber; } function ConvertToBinary(dec) { var bits = []; var dividend = dec; var remainder = 0; while (dividend >= 2) { remainder = dividend % 2; bits.push(remainder); dividend = (dividend - remainder) / 2; } bits.push(dividend); bits.reverse(); return bits.join(""); } function Multiply() { var firstNumber = document.getElementById("txtFirst").value; var secondNumber = document.getElementById("txtSecond").value; var multiplier = ConvertToBinary(firstNumber); var multiplicant = ConvertToBinary(secondNumber); var product = 0; var step = "Initial values"; var iteration = 0; AppendToTable(iteration, step, multiplier, multiplicant, product); multiplicationAlgoritm(multiplier, multiplicant, product, 4); } function multiplicationAlgoritm(multiplier, multiplicant, product, counter) { if (counter > 0) { var iteration = 5 - counter; var decProduct = ConvertToDecimal(product); var decMultiplier = ConvertToDecimal(multiplier); var decMultiplicant = ConvertToDecimal(multiplicant); if (Right(multiplier, 1) == "1") { decProduct = decProduct + decMultiplicant; product = ConvertToBinary(decProduct); AppendToTable(iteration, "1a", multiplier, multiplicant, product); } else { AppendToTable(iteration, 1, multiplier, multiplicant, product); } decMultiplicant = ConvertToDecimal(multiplicant); decMultiplicant = decMultiplicant << 1; multiplicant = ConvertToBinary(decMultiplicant); AppendToTable(iteration, 2, multiplier, multiplicant, product); decMultiplier = ConvertToDecimal(multiplier); decMultiplier = decMultiplier 1; multiplier = ConvertToBinary(decMultiplier); AppendToTable(iteration, 3, multiplier, multiplicant, product); counter--; multiplicationAlgoritm(multiplier, multiplicant, product, counter); } } function AppendToTable(iteration, step, multiplier, multiplicant, product) { var row = document.getElementById("tblResults").insertRow(); var cell = row.insertCell(); cell.innerText = iteration; var cell = row.insertCell(); cell.innerText = step; var cell = row.insertCell(); cell.innerText = multiplier; var cell = row.insertCell(); cell.innerText = multiplicant; var cell = row.insertCell(); cell.innerText = product; } function ResetTable() { for (var i = document.getElementById("tblResults").rows.length; i > 1; i--) { document.getElementById("tblResults").deleteRow(i - 1); } } function Right(str, n) { if (n <= 0) return ""; else if (n > String(str).length) return str; else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } } </script> <style type="text/css"> .style1 { border-collapse: collapse; border-style: solid; border-width: 1px; } .style2 { width: 6px; } .style4 { color: #3366FF; } .style5 { color: #0066FF; } </style> </head> <body> <br /> <h3 class="style4"> WELCOME TO MIPS MULTIPLICATION SIMULATOR</h3> <hr style="color: #0033CC" /> <table> <tr> <td class="style5"> Multiplier : </td> <td> <input id="txtFirst" type="text" /> </td> </tr> <tr> <td class="style5"> Multiplicant : </td> <td> <input id="txtSecond" type="text" /> </td> </tr> <tr> <td align="center" colspan="2"> <input id="btnMultiply" type="button" value="Multiply" onclick="ResetTable();Multiply();" style="color: #3399FF" /> </td> </tr> </table> <table class="style1" cellpadding="2" cellspacing="2" id="tblResults"> <tr style="color: White"> <td bgcolor="#3366FF"> Iteration </td> <td bgcolor="#3366FF"> Step </td> <td bgcolor="#3366FF"> Multiplier </td> <td bgcolor="#3366FF" class="style2"> Multiplicant </td> <td bgcolor="#3366FF"> Product </td> </tr> </table> </body> </html>
希望本文所述对大家的javascript程序设计有所帮助。
快活林资源网 Design By www.csstdc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
快活林资源网 Design By www.csstdc.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2025年01月18日
2025年01月18日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]