【发布时间】:2021-04-19 00:56:37
【问题描述】:
不确定如何将#0x30 到#0x39 的内容初始化为#0x40 和#0x41。我知道我应该有 7 个偶数和 3 个赔率。我尝试制作一个 Loop2 将 R1(#0x30) 移动到 R5(#0x40),但我 不确定这是否正确,因为我觉得有一种更简单的方法可以将奇数和偶数实现到寄存器#0x40。另外,请不要在一开始就引用代码,因为那只是一些基准代码供我参考。不是在找人为我做这项工作,但一些提示或技巧会有所帮助,因为我对 8051 微控制器和汇编语言非常不熟悉。
; This code places some values into RAM at
; addresses 0x30 through 0x39:
MOV R0, #0x30
MOV R1, #0
MOV R2, #10
MOV R3, #0
MOV A, #144
MOV B, #253
again:
MUL AB
ADD A,B
DEC B
MOV @R0,A
ADD A,R2
XRL B,#11011010b
INC R0
DJNZ R2, again
CLR C
; Complete this program by writing code below
; that looks at the values in RAM at addresses 0x30 through 0x39,
; and determines the number of odd values and the number of even
; values. Your code should store at address 0x40 the number
; of even values found and at address 0x41 the number of odd
; values found.
MOV R1, #0x30
MOV R2, #0
MOV R3, #0
MOV R4, #10
MOV R5, #0x40
MOV R6, #0x41
Loop:
MOV A,@R1
ANL A, #00000001b
INC R1
JZ even
INC R2
JMP after
even:
INC R3
after:
DJNZ R4,Loop
Loop2:;Not sure if this second loop is needed
; to output the number of evens and odds in #0x40 and #0x41
MOV A,R1
MOV A,R5
DJNZ R4,Loop2
【问题讨论】:
-
您的奇数/偶数循环是有道理的。目前还不清楚你为什么要在最后一个循环。只需将
R3存储到0x40和R2到0x41。 -
好的,我会这样做:MOV R3,@R5?
-
逻辑上是的,但
@R5不是有效的寻址模式。你可以直接做MOV 0x40, R3。 -
谢谢我知道了!我不清楚我是否可以将值存储在文字寄存器中,但现在很有意义。