填写“n”汇编器中的内存位置
我正在努力完成这项工作,但我做不到。任何人都可以帮助我并解释如何进行分配:“用值-1填充地址中的n个内存位置” // R1 <- n // R2 <- 地址
I'm trying to do the job, but I can't. Can anyone help me and explain how to make the assignment: "fill n memory locations from address with value -1" // R1 <- n
// R2 <- addr
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个想法是将问题分开并解决各个部分,然后将这些部分组合成一个整体解决方案。
排名不分先后:
一种用于设置内存的算法,用 C 编写:
您不必用汇编语言思考来想出算法。用你所知道的语言来完成,然后将其中的一部分进行汇编要容易得多。
您将需要进行内存写入。
内存写入是通过执行
M=
指令来执行的,例如M=D
。该操作将执行Memory[A]=D
- 因此您需要A
寄存器中的内存地址和要存储在D
中的值在执行此操作之前先注册。您被告知将值放在
R2
引用的位置,因此获取R2
中变量的值并将其放入A
> 注册。R2
是数据内存位置 2 的别名,因此这里,R2
是一个位于内存中的指针变量。系统告诉您使用 -1 来填充内存,因此请将 -1 放入
D
中。我们可以直接在 C 指令中执行此操作,因此不需要@
指令来加载 -1:通过上述设置,您可以执行
M=D
用-1 填充一个内存位置。要存储在连续的位置,您需要增加
R2
中的指针。您将需要一个计数循环。
由于其他寄存器(
A
、D
)将忙于在循环内执行操作,因此计数器必须位于内存中的某个位置。并且您被告知计数器位于R1
中 — 与Memory[1]
相同。您可以使用简单的序列递减计数器,如下所示:
但是,如果您还想测试计数器,请将计数器放入 D 寄存器并将其存储回内存并添加向后条件分支继续循环:
这将完成,例如:
The idea is to pick apart the problem and solve pieces, then put the pieces together into an overall solution.
In no particular order:
An algorithm for setting memory, in C:
You don't have to think in assembly language to come up with an algorithm. Much easier to do in a language you know then take pieces of that into assembly.
You will need to do memory writes.
Memory writes are performed by doing an
M=
instruction, such asM=D
. That operation will doMemory[A]=D
— so you need a memory address in theA
register and a value to store in theD
register before performing this operation.You're told to put the values at the location referred to by
R2
, so fetch the value of variable inR2
and put it into theA
register.R2
is an alias for data memory location 2, so here,R2
is a pointer variable that lives in memory.You're told to use -1 to fill the memory, so put a -1 in
D
. We can do this directly in a C-instruction, so don't need an@
instruction to load the -1:With the above setup, you can do an
M=D
to fill one memory location with -1.To store at successive locations, you'll need to increment the pointer in
R2
.You will need a counted loop.
Since the other registers (
A
,D
) will be busy doing things inside the loop the counter will have to be located somewhere in memory. And you're told that the counter is inR1
— the same asMemory[1]
.You can decrement the counter with a simple sequence as follows:
However, if you want to also want to also test the counter, bring the counter into the
D
register as well as storing it back to memory and add a backward conditional branch to continue the loop:This will accomplish, for example: