看了很久网上没有现成的代码和好一点的图,因此当一回搬运工。转自stackoverflow

布斯乘法器的Mips实现方法:

.data

    promptStart:    .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" .text main:
#"welcome" screen
li $v0, # code for print_string
la $a0,promptStart # point $a0 to prompt string
syscall # print the prompt li $v0, # code for print_string
la $a0,endLine # point $a0 to prompt string
syscall # print the prompt #prompt for multiplicand
li $v0, # code for print_string
la $a0,getA # point $a0 to prompt string
syscall # print the prompt #acquire multiplicand
li $v0, # code for read_int
syscall # get an int from user --> returned in $v0
move $s0,$v0 # move the resulting int to $s0
move $s5,$s0 # copy of multiplicand to use in multu #prompt for multiplier
li $v0, # code for print_string
la $a0,getB # point $a0 to prompt string
syscall # print the prompt #acquire multiplier
li $v0, # code for read_int
syscall # get an int from user --> returned in $v0
move $s1,$v0 # move the resulting int to $s0 move $s6,$s1 # copy of multiplier to use in multu jal MyMult
j print MyMult:
move $s3, $ # lw product
move $s4, $ # hw product beq $s1, $, done
beq $s0, $, done move $s2, $ # extend multiplicand to bits loop:
andi $t0, $s0, # LSB(multiplier)
beq $t0, $, next # skip if zero
addu $s3, $s3, $s1 # lw(product) += lw(multiplicand)
sltu $t0, $s3, $s1 # catch carry-out( or )
addu $s4, $s4, $t0 # hw(product) += carry
addu $s4, $s4, $s2 # hw(product) += hw(multiplicand)
next:
# shift multiplicand left
srl $t0, $s1, # copy bit from lw to hw
sll $s1, $s1,
sll $s2, $s2,
addu $s2, $s2, $t0 srl $s0, $s0, # shift multiplier right
bne $s0, $, loop done:
jr $ra print:
# print result string
li $v0, # code for print_string
la $a0,result # point $a0 to string
syscall # print the result string # print out the result
li $v0, # code for print_int
move $a0,$s4 # put result in $a0
syscall # print out result li $v0, # code for print_string
la $a0,space # point $a0 to string
syscall # print the result string li $v0, # code for print_int
move $a0,$s3 # put result in $a0
syscall # print out result # print the line feed
li $v0, # code for print_string
la $a0,endLine # point $a0 to string
syscall # print the linefeed doMult:
#Do same computation using Mult
multu $s5, $s6
mfhi $t0
mflo $t1 li $v0, # code for print_string
la $a0,mipMult # point $a0 to string
syscall # print out the result
li $v0, # code for print_int
move $a0,$t0 # put high in $a0
syscall # print out result li $v0, # code for print_string
la $a0,space # point $a0 to string
syscall # print the result string # print out the result
li $v0, # code for print_int
move $a0,$t1 # put low in $a0
syscall # print out result # print the line feed
li $v0, # code for print_string
la $a0,endLine # point $a0 to string
syscall # print the linefeed # All done, thank you!
li $v0, # code for exit
syscall # exit program

网上的图太糊了,我重新做了以下,仅供参考。

本贴永久地址:http://www.cnblogs.com/liutianchen/p/6535776.html

布斯乘法 Mips实现 - Booth Algorithm的更多相关文章

  1. Booth算法

    Booth算法 算法描述(载自维基百科) 对于N位乘数Y,布斯算法检查其2的补码形式的最后一位和一个隐含的低位,命名为y-1,初始值为0.对于yi, i = 0, 1, ..., N - 1,考察yi ...

  2. 补码一位乘法 Booth算法 Java简易实现

    本文链接:https://www.cnblogs.com/xiaohu12138/p/11955619.html. 转载,请说明出处. 本程序为简易实现补码一位乘法,若代码中存在错误,可指出,本人会不 ...

  3. Booth Multiplication Algorithm [ASM-MIPS]

    A typical implementation Booth's algorithm can be implemented by repeatedly adding (with ordinary un ...

  4. [CF932E]Team Work & [BZOJ5093]图的价值

    CF题面 题意:求\(\sum_{i=0}^{n}\binom{n}{i}i^k\) \(n\le10^9,k\le5000\) 模\(10^9+7\) BZOJ题面 题意:求\(n*2^{\frac ...

  5. Verilog乘法器

    乘法器,不能用乘号直接表示,略坑呀 坑归坑,做还是要做的 思路:首先乘法分为有符号乘与无符号乘,所以建立两个module分别运算有符号与无符号.然后在总module中用case语句判断输出应赋的值. ...

  6. 【BZOJ】1754: [Usaco2005 qua]Bull Math

    [算法]高精度乘法 #include<cstdio> #include<algorithm> #include<cstring> using namespace s ...

  7. [Avito Code Challenge 2018 G] Magic multisets(线段树)

    题目链接:http://codeforces.com/contest/981/problem/G 题目大意: 有n个初始为空的‘魔法’可重集,向一个‘可重集’加入元素时,若该元素未出现过,则将其加入: ...

  8. 51nod 1832 前序后序遍历

    思路:设只有一颗子树的节点有ans个设前序边历数组为pre[100],后序遍历数组为pos[100]:前序遍历的第二个元素是A的一个子节点左右节点不知,设ax-ay表示一个树的前序遍历,bx-by表示 ...

  9. 补码一位乘法(Booth算法,C语言实现)

    补码一位乘法 首先了解下什么是补码? 补码概念的理解,需要先从“模”的概念开始. 我们可以把模理解为一个容器的容量.当超出这个 容量时,会自动溢出.如:我们最常见到的时钟,其容量 是 12,过了 12 ...

随机推荐

  1. teamviewer14商用试用期到期从新安装使用

    teamviewer14商用试用期到期从新安装使用 1)1.退出TeamViewer远程软件,卸载软件.2)2.按键盘的[win]+[R]组合键打开[运行],输入 %appdata%3)3.在弹出的窗 ...

  2. VS调试时JSON格式文件无法加载

    VS调试时JSON格式文件无法加载 报错: 解决:在项目中的web.config中进行配置,configuration节中添加以下部份: <system.webServer> <st ...

  3. mysql 随机查询 记录集

    有时候需求需要随机从数据库查询若干条记录集,网上搜了一下,几篇博文都是些重复的.....不知道他们谁抄的谁的,这里除了介绍提供一种笔者自己想到的方法,本质都是利用mysql 的rand() 第一种方法 ...

  4. umbraco

    在任意页面获取根节点 var locale = CurrentPage.Site(); 遍历根节点 @foreach (var module in CurrentPage.Site().Childre ...

  5. 【309】◀▶ Windows 相关功能实现

    目录: 共享文件夹失败的解决方法 导 栅 添 1. 共享文件夹失败的解决方法 参考:解决“你没有权限访问,请与网络管理员联系” 参考:WIN7局域网文件共享设置方法 2. 导 在 3. 栅 栅 4. ...

  6. 深入探究jvm之GC的算法及种类

    一.GC基本概念 GC(Garbage Collection)垃圾收集,1960年最早在List中使用.在Java中GC回收的对象是堆空间和永久区,可以有效避免程序员人为造成内存泄漏问题.将堆空间和永 ...

  7. Spring3.0+Hibernate+Atomikos集成构建JTA的分布式事务--解决多数据源跨库事务

    一.概念 分布式事务分布式事务是指事务的参与者.支持事务的服务器.资源服务器以及事务管理器分别位于不同的分布式系统的不同节点之上.简言之,同时操作多个数据库保持事务的统一,达到跨库事务的效果. JTA ...

  8. 实现SwipeRefreshLayout首次进入自动刷新

    看到了Android版知乎实现了这种效果,就自己也实现了一下. 先来一张效果图 实现方式: 方法一. ①在onWindowFocusChanged()方法中,设置为刷新状态为true @Overrid ...

  9. sqlserver全备份,差异备份和日志备份

      差异备份是以上一个全备为基点,这个期间所有差异数据的备份. 日志备份是基于前一个全备+日志备份为基点,这个期间的事务日志的备份.(日志备份用于确保还原数据库到某个时间点)   在利用全备+日志备份 ...

  10. Qt程序无法输入中文的问题

    问题 在Linux环境下,用Qt编写的程序运行时不能在诸如输入框.文本框中输入中文(不会激活中文输入法). 注意与输入法类型有关(基于iBus或Fcitx) 原因 Qt程序的中文输入支持需要用Qt插件 ...