布斯乘法 Mips实现 - Booth Algorithm
看了很久网上没有现成的代码和好一点的图,因此当一回搬运工。转自stackoverflow
布斯乘法器的Mips实现方法:
.datapromptStart: .asciiz "This program does AxB without using mult or div"getA: .asciiz "Please enter the first number(multiplicand): "getB: .asciiz "Please enter the second number(multiplier): "space: .asciiz " "result: .asciiz "The product, using my program is: "mipMult: .asciiz "The product, using MIPs multu is: "endLine: .asciiz "\n".textmain:#"welcome" screenli $v0,4 # code for print_stringla $a0,promptStart # point $a0 to prompt stringsyscall # print the promptli $v0,4 # code for print_stringla $a0,endLine # point $a0 to prompt stringsyscall # print the prompt#prompt for multiplicandli $v0,4 # code for print_stringla $a0,getA # point $a0 to prompt stringsyscall # print the prompt#acquire multiplicandli $v0,5 # code for read_intsyscall # get an int from user --> returned in $v0move $s0,$v0 # move the resulting int to $s0move $s5,$s0 # copy of multiplicand to use in multu#prompt for multiplierli $v0,4 # code for print_stringla $a0,getB # point $a0 to prompt stringsyscall # print the prompt#acquire multiplierli $v0,5 # code for read_intsyscall # get an int from user --> returned in $v0move $s1,$v0 # move the resulting int to $s0move $s6,$s1 # copy of multiplier to use in multujal MyMultj printMyMult:move $s3, $0 # lw productmove $s4, $0 # hw productbeq $s1, $0, donebeq $s0, $0, donemove $s2, $0 # extend multiplicand to 64 bitsloop:andi $t0, $s0, 1 # LSB(multiplier)beq $t0, $0, next # skip if zeroaddu $s3, $s3, $s1 # lw(product) += lw(multiplicand)sltu $t0, $s3, $s1 # catch carry-out(0 or 1)addu $s4, $s4, $t0 # hw(product) += carryaddu $s4, $s4, $s2 # hw(product) += hw(multiplicand) next:# shift multiplicand leftsrl $t0, $s1, 31 # copy bit from lw to hwsll $s1, $s1, 1sll $s2, $s2, 1addu $s2, $s2, $t0srl $s0, $s0, 1 # shift multiplier rightbne $s0, $0, loopdone:jr $raprint:# print result stringli $v0,4 # code for print_stringla $a0,result # point $a0 to stringsyscall # print the result string# print out the resultli $v0,1 # code for print_intmove $a0,$s4 # put result in $a0syscall # print out resultli $v0,4 # code for print_stringla $a0,space # point $a0 to stringsyscall # print the result stringli $v0,1 # code for print_intmove $a0,$s3 # put result in $a0syscall # print out result# print the line feedli $v0,4 # code for print_stringla $a0,endLine # point $a0 to stringsyscall # print the linefeeddoMult: #Do same computation using Multmultu $s5, $s6mfhi $t0mflo $t1li $v0,4 # code for print_stringla $a0,mipMult # point $a0 to stringsyscall# print out the resultli $v0,1 # code for print_intmove $a0,$t0 # put high in $a0syscall # print out resultli $v0,4 # code for print_stringla $a0,space # point $a0 to stringsyscall # print the result string# print out the resultli $v0,1 # code for print_intmove $a0,$t1 # put low in $a0syscall # print out result# print the line feedli $v0,4 # code for print_stringla $a0,endLine # point $a0 to stringsyscall # print the linefeed# All done, thank you!li $v0,10 # code for exitsyscall # exit program
网上的图太糊了,我重新做了以下,仅供参考。
本贴永久地址:http://www.cnblogs.com/liutianchen/p/6535776.html
转载于:https://www.cnblogs.com/liutianchen/p/6535776.html
布斯乘法 Mips实现 - Booth Algorithm相关推荐
- 计算机乘法算法流程,布斯乘法算法
布斯乘法算法是计算机中一种利用数的2的补码形式来计算乘法的算法.该算法由安德鲁·唐纳德·布斯于1950 年发明,当时他在伦敦大学伯克贝克学院做晶体学研究.布斯曾使用过台式计算器,由于用这种计算器来做移 ...
- 布斯乘法以及带符号数的运算
乘法理解 对于最熟悉的十进制乘法很最基本的运算原理就是一个乘数乘以另一个乘数的个位.十位.百位···数字然后求和.比如 放到二进制来看其实它也是这样的,多位数的乘法就是一个乘数乘上另一个乘数的各位求和 ...
- 【Verilog】布斯算法(Booth Algorithm)乘法器的 Verilog 实现
目录 布斯算法介绍 计算步骤 计算流程图 举个栗子 Verilog 实现 设计思想 Verilog 代码 TestBench 代码 仿真波形 布斯算法介绍 Booth 的算法检查有符号二的补码表示中 ...
- C语言布斯乘法算法,布斯Booth算法带符号位的乘法verilog语言实现booth算法
Booth算法的推倒表示看不懂,举例说明:算法的计算过程. 求M*Q的值 M=5,Q=6 按二进制分解M和Q :M3M2M1M0×Q3Q2Q1Q0: 0110×0101 (有符号数用补码表示,最高位表 ...
- 布斯乘法算法的流程图
Created with Raphaël 2.1.0开始装填被乘数Q装填乘数M置A=0,Q-1=0置循环计数count=32取Q的最低位Q0Q0=Q-1?取出A的最低位A0A与Q逻辑右移一位A0=0? ...
- 布斯(booth)乘法详解和例子
布斯乘法是用于计算带符号数乘法的规则,它是通过如下的规定完成乘法运算的: ①:booth乘法的乘数和被乘数还有结果都应由补码表示. ②:booth乘法计算前应在乘数末尾补零. ③:booth乘法的符号 ...
- 【汇编语言与计算机系统结构笔记17】MIPS 汇编初步
本次笔记内容: 25.MIPS汇编初步-1 26.MIPS汇编初步-2 27.MIPS指令集与汇编程序设计 注:我找到了对应内容的课件,请见我于GitHub的CS笔记仓库.因此,为了节省时间,我只记录 ...
- verilog乘法器以及booth编码改进
第一章 整数乘法器 1.1 整数的概念 整数在IEEE 的规定上有,短整数short integer , 中整数integer 和 长整数long integer ,它们之间的关系如下: 整数 字节空 ...
- 乘法器,也不过如此!
乘法器,也不过如此! 乘法器要点: 逐位进位并行乘法器:常规乘法计算一样 进位节省乘法器:含有超前进位加法器电路 基本时序乘法器:循环复用,左移,加法利用状态机 查找表乘法器:面积换速度典型 Wall ...
最新文章
- OA项目12:系统管理之用户管理
- 尤雨溪创立 Vue.js 的心路历程纪录片
- spring原理案例-基本项目搭建 01 spring framework 下载 官网下载spring jar包
- Design Pattern - Adapter Pattern
- Python与用户的交互 ,格式化输出的三种方式
- Java Review - 并发编程_PriorityBlockingQueue原理源码剖析
- python 中的__future__模块
- ios订阅其他国家节假日日历
- 设计任务调度依赖配置表
- 保研面试/考研复试中文自我介绍模板(30秒、1分钟、2分钟、3分钟)
- ORA-15018: diskgroup cannot be created
- error: dst ref refs/heads/dev receives from more than one src.
- 链表之Reverselist
- 淘宝客小程序制作(4)-小程序(微信支付宝)
- 米4用linux刷机救转,小米Mi4(小米4 电信4G版)手机快速救砖,线刷教程分享,小白轻松救活手机...
- it可以拥有的证书含金量和途径
- NVL、NVL2、NULLIF、COALESCE的区别是什么?
- 看看安卓开发者在APP推广路途中是如何被金山“恶霸”所“黑打”的!
- 二叉树的遍历-先序遍历、中序遍历、后序遍历
- jenkins执行状态stable unstable是什么