因此,根据我所看到的几个来源,在32位mips中不可能使用32位立即数,因为机器指令是32位并且存储立即数值在机器说明书内。据我所知,最大的立即数可以是16位,为剩下的指令留出空间。但在MARS 4.5 mips中,此指令工作正常(使用默认设置):
#include<iostream>
using namespace std;
class linkedList{
public:
int content;
linkedList* pointerToBelow;
};
void freeTheMemory(linkedList *top) {
if(top != nullptr){
linkedList* temp = top->pointerToBelow;
delete top;
freeTheMemory(temp); // temp is now the top
}
}
void push(linkedList* top, int x){
// create new node, assign x
linkedList *node = new linkedList;
node->content = x;
// new node points to top element in the stack
node->pointerToBelow = top->pointerToBelow;
// top now points to the new node
top->pointerToBelow = node;
}
void pop(linkedList* top ){
linkedList* toDelete = top->pointerToBelow;
// case 1: stack is empty
if(toDelete == nullptr)
return; // do nothing
// case 2: deleting top element
top->pointerToBelow = toDelete->pointerToBelow;
delete toDelete;
}
void printList(linkedList *top) {
top = top->pointerToBelow;
while(top != nullptr) {
cout << top->content << " ";
top = top->pointerToBelow;
}
}
int main(){
int x;
linkedList *top = new linkedList;
top->pointerToBelow = nullptr; // indicates stack is empty
cout<<"Enter the elements of your list: ";
while(x != -9) {
cin >> x;
if(x! =- 9) {
if(x>0)
push(top, x);
else
pop(top);
}
}
printList(top);
freeTheMemory(top);
return 0;
}
这组装并且运行正常,这让我感到困惑,因为我认为它不应该出于上述原因(32位机器代码怎么能保持32位立即?)。我最好的猜测是MARS中的ori实际上运行伪指令,当直接字段高于0xffff时,lui&or; s和ori定期加载,但我不确定。有人可以对此有所了解吗?
答案 0 :(得分:0)
如果您注意到在火星4.5中组装该指令时,您会得到三条指令
lui $1,0xFFFFFFFF
ori $1,$1,0x0000FFFF
or $9,$0,$1
这仍然有点误导,但基本上它会为你修复它。