自己动手写CPU之第九阶段(2)加载存储指令说明2(lwl、lwr
将陆续上传新书《 自己动手写CPU 》,今天是第38篇,我尽量每周四篇,但是最近已经很久没有实现这个目标了,一直都有事,不好意思哈。 开展晒书评送书活动,在 亚马逊 、京东、当当三大图书网站上,发表《 自己动手写CPU 》书评的前十名读者,均可获赠《步步
将陆续上传新书《自己动手写CPU》,今天是第38篇,我尽量每周四篇,但是最近已经很久没有实现这个目标了,一直都有事,不好意思哈。
开展晒书评送书活动,在亚马逊、京东、当当三大图书网站上,发表《自己动手写CPU》书评的前十名读者,均可获赠《步步惊芯——软核处理器内部设计分析》一书,大家踊跃参与吧!活动时间:2014-9-11至2014-10-20
今天继续对MIPS32中加载存储指令进行说明(主要是lwl、lwr),上次已经介绍一些其他的加载存储指令,大家可以回顾。
9.1.4 加载指令lwl、lwr说明
加载指令lwl、lwr的格式如图9-6所示。

- 当指令中的指令码为6'b100010时,是lwl指令,非对齐加载指令,向左加载
指令用法为:lwl rt, offset(base)
指令作用为:从内存中指定的加载地址处,加载一个字的最高有效部分。lwl指令对加载地址没有要求,从而允许地址非对齐加载,这是与前面介绍的lh、lhu、lw指令的不同之处。在大端模式、小端模式下,lwl指令的效果不同,因为OpenMIPS是大端模式,所以此处只介绍在大端模式下lwl指令的效果。假设计算出来的加载地址是loadaddr,loadaddr的最低两位的值为n,将loadaddr最低两位设为0后的值称为loadaddr_align,如下。
加载地址loadaddr = signed_extended(offset) + GPR[base]
n = loadaddr[1:0]
loadaddr_align = loadaddr – n
例如:假设计算出来的加载地址是5,lwl指令要从地址5加载数据,那么loadaddr就等于5,n等于1,loadaddr_align等于4。
lwl指令的作用是从地址为loadaddr_align处加载一个字,也就是4个字节,然后将这个字的最低4-n个字节保存到地址为rt的通用寄存器的高位,并且保持低位不变。
继续上例,此时loadaddr_align为4,所以从地址4处加载一个字,对应的是地址为4、5、6、7的字节,因为n等于1,所以将加载到的字的最低3个字节保存到地址rt的通用寄存器的高3个字节。如图9-7所示。一个更加通用的描述如图9-8所示。

- 当指令中的指令码为6'b100110时,是lwr指令,非对齐加载指令,向右加载
指令用法为:lwr rt, offset(base)
指令作用为:从内存中指定的加载地址处,加载一个字的最低有效部分。还是假设计算出来的加载地址是loadaddr,loadaddr的最低两位的值为n,将loadaddr最低两位设为0后的值称为loadaddr_align,如下。
加载地址loadaddr = signed_extended(offset) + GPR[base]
n = loadaddr[1:0]
loadaddr_align = loadaddr – n
例如:假设计算出来的加载地址是9,lwr指令要从地址9加载数据,那么loadaddr就等于9,n等于1,loadaddr_align等于8。
lwr指令的作用是从地址为loadaddr_align处加载一个字,也就是4个字节,然后将这个字的最高n+1个字节保存到地址为rt的通用寄存器的低位,并且保持高位不变。
继续上例,此时loadaddr_align为8,所以从地址8处加载一个字,对应的是地址为8、9、10、11的字节,因为n等于1,所以将加载到的字的最高2个字节保存到地址rt的通用寄存器的低2个字节。如图9-9所示。一个更加通用的描述如图9-10所示。

lwl与lwr指令配合可以实现从一个非对齐地址加载一个字,而且只需要使用2条指令,提高了效率。例如:使用一般指令从地址7处加载一个字,那么可以使用以下代码实现,共5条指令。
lw $1, 4($0) # 取得地址0x4处的字,保存在$1中 lw $2, 8($0) # 取得地址0x8处的字,保存在$2中 sll $1, $1, 24 # $1左移24位 slr $2, $2, 8 # $2右移8位 or $1, $1, $2 # $1与$2进行逻辑“或”运算,得到最终结果
而有了lwl、lwr指令后,只需要2条指令即可。如下,图9-11是对这个过程的描述。
lwl $1, 7($0) lwr $1,10($0)


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to get items using commands in Terraria? 1. What is the command to give items in Terraria? In the Terraria game, giving command to items is a very practical function. Through this command, players can directly obtain the items they need without having to fight monsters or teleport to a certain location. This can greatly save time, improve the efficiency of the game, and allow players to focus more on exploring and building the world. Overall, this feature makes the gaming experience smoother and more enjoyable. 2. How to use Terraria to give item commands 1. Open the game and enter the game interface. 2. Press the "Enter" key on the keyboard to open the chat window. 3. Enter the command format in the chat window: "/give[player name][item ID][item quantity]".

1. First, we right-click the blank space of the taskbar and select the [Task Manager] option, or right-click the start logo, and then select the [Task Manager] option. 2. In the opened Task Manager interface, we click the [Services] tab on the far right. 3. In the opened [Service] tab, click the [Open Service] option below. 4. In the [Services] window that opens, right-click the [InternetConnectionSharing(ICS)] service, and then select the [Properties] option. 5. In the properties window that opens, change [Open with] to [Disabled], click [Apply] and then click [OK]. 6. Click the start logo, then click the shutdown button, select [Restart], and complete the computer restart.

According to news from this website on July 28, foreign media TechRader reported that Fujitsu introduced in detail the FUJITSU-MONAKA (hereinafter referred to as MONAKA) processor planned to be shipped in 2027. MONAKACPU is based on the "cloud native 3D many-core" architecture and adopts the Arm instruction set. It is oriented to the data center, edge and telecommunications fields. It is suitable for AI computing and can realize mainframe-level RAS1. Fujitsu said that MONAKA will achieve a leap in energy efficiency and performance: thanks to technologies such as ultra-low voltage (ULV) technology, the CPU can achieve 2 times the energy efficiency of competing products in 2027, and cooling does not require water cooling; in addition, the application performance of the processor It can also reach twice as much as your opponent. In terms of instructions, MONAKA is equipped with vector

IntelArrowLakeisexpectedtobebasedonthesameprocessorarchitectureasLunarLake,meaningthatIntel'sbrandnewLionCoveperformancecoreswillbecombinedwiththeeconomicalSkymontefficiencycores.WhileLunarLakeisonlyavailableasava

According to news from this website on June 1st, the source @CodeCommando tweeted today, sharing some screenshots of AMD’s upcoming presentation documents at the Computex2024 event. The content of the tweet was “AM4 will never die”, and the accompanying picture showed two new Ryzen5000XT series processors. The screenshots show the following two products: Ryzen 95900 Ryzen75800XT It is a faster variant of AMD's existing Ryzen75800X processor. Both processors are clocked up to 4.8G

This website reported on March 7 that Dr. Zhou Yuefeng, President of Huawei's Data Storage Product Line, recently attended the MWC2024 conference and specifically demonstrated the new generation OceanStorArctic magnetoelectric storage solution designed for warm data (WarmData) and cold data (ColdData). Zhou Yuefeng, President of Huawei's data storage product line, released a series of innovative solutions. Image source: Huawei's official press release attached to this site is as follows: The cost of this solution is 20% lower than that of magnetic tape, and its power consumption is 90% lower than that of hard disks. According to foreign technology media blocksandfiles, a Huawei spokesperson also revealed information about the magnetoelectric storage solution: Huawei's magnetoelectronic disk (MED) is a major innovation in magnetic storage media. First generation ME

Subtitles not working on Stremio on your Windows PC? Some Stremio users reported that subtitles were not displayed in the videos. Many users reported encountering an error message that said "Error loading subtitles." Here is the full error message that appears with this error: An error occurred while loading subtitles Failed to load subtitles: This could be a problem with the plugin you are using or your network. As the error message says, it could be your internet connection that is causing the error. So please check your network connection and make sure your internet is working properly. Apart from this, there could be other reasons behind this error, including conflicting subtitles add-on, unsupported subtitles for specific video content, and outdated Stremio app. like

When the computer is running, some users find that Google Chrome in the task manager occupies a very high CPU. If it is not processed in time, the computer will become more and more stuck, and even crash. So how to deal with the high CPU usage of Chrome browser? Let’s take a look at this issue together. High CPU usage issues in Google Chrome are usually due to "SoftwareReporterTool" running abnormally in Task Manager. This tool is actually a Chrome browser cleaning tool, used to clean up unnecessary or harmful extensions, applications or homepage hijackers. When Chrome is installed, Software_reporter_tool.exe is also downloaded to SwR
