如何切换到地址中的值。目前我有2个包含地址的寄存器。然后我有两个临时变量来存储这些地址。然后,我加载了这些值,因为我有地址。但是我想不出如何交换这些值。我正在尝试做冒泡排序。下面的代码就是我目前拥有的代码
IF ;swapping condition
ST R2,idata ;temporily hold the smaller data
ST R1,imindata ;temporaily hold the larger data
ST R2,iminaddres ;store the values into that address
ST R2,iaddress ;finish the swaping of the two values
LD R1,iminaddres ;reput the address back into the register
LD R2,iaddres ;reput the address back into the register to be used for next cycle发布于 2013-02-23 09:06:33
在C中你会怎么做呢?
temp = a;
a = b;
b = temp;然后理解需要从内存中加载这些值,这会稍微改变一些事情
tempa = a;
tempb = b;
b = tempa;
a = tempb;然后隔离加载和存储
rega <= load(a);
regb <= load(b);
store(a) <= regb;
store(b) <= rega;然后在汇编中实现它。这闻起来像是家庭作业,所以我不会帮你做的。
发布于 2013-02-23 03:32:23
如果你想做的就是交换两个寄存器的内容,有一个简单的小把戏:
XOR R1,R2
XOR R2,R1
XOR R1,R2这将在不使用任何内存的情况下交换两个寄存器的内容。
https://stackoverflow.com/questions/15030427
复制相似问题