0

关于ARM7 ViSUAL EMulator和Keil uVision4有两个问题。

  • 在 ARM7 ViSUAL Emulator 上运行它并解释它的作用。
  • 考虑如何声明变量 Value1、Value2、Value3 和 Result。解释为什么这不能使用 Keil uVision4 编译。

我已经运行了代码,但我仍然不明白它的作用。

 Main
  LDR r1, =Value1 
  LDR R2, =Value2 
  LDR r1,[r1]
  LDR r2,[r2]
Return
  ANDS R3, R1,R2 
  BNE SEND 
  BEQ NEXT 
  END
SEND
  LDR r4, =Result 
  LDR r4,[r4] 
  STR r3, [r4] 
  END
NEXT
   MOV R1, R2 
   LDR R2, =Value3 
   LDR R2, [r2]
   B       Return
   END
 Value1 DCD &0202
 Value2 DCD  &0101
 Value3 DCD &0001
 Result DCD  &FFFFFFF0

ARM7 模拟器上的结果

4

1 回答 1

2

内存分配 ( DCD) 在与代码声明相同的区域中完成。这意味着它可能会像AREA PROGRAM, CODE, READONLY设置一样被使用,因此 keil 不会组装它。这也意味着如果它被组装,数据位置将是READONLY. 变量的正确声明将在前面AREA <a section name>, DATA, READWRITE

 Main
  LDR R1, =Value1 -- load Value1 inside R1
  LDR R2, =Value2 -- load Value2 inside R2
  LDR R1,[R1]  -- load indirect the address pointed to by the value of R1 to R1 -- (I have reservations about the functionality of this code)
  LDR R2,[R2]  -- load indirect the address pointed to by the value of R2 to R2 -- (I have reservations about the functionality of this code)
Return
  ANDS R3, R1,R2 -- R3 = R1 AND R2
  BNE SEND -- branch if not equal to SEND label
  BEQ NEXT -- branch to NEXT if equal
  END 
SEND
  LDR R4, =Result -- load Result to R4
  LDR R4,[R4]  -- load indirect the address pointed to by the value of R4 to R4 -- (I have reservations about the functionality of this code)
  STR R3, [R4] -- store indirect to address pointed to by the value of R4 with the value of R3
  END
NEXT
   MOV R1, R2  -- copy R2 to R1
   LDR R2, =Value3  -- load Value3 to R2
   LDR R2, [R2] -- load indirect the address pointed to by the value of R2 to R2 -- (I have reservations about the functionality of this code)
   B       Return -- unconditional branch to Return label
   END
 Value1 DCD &0202  -- word allocation with hex value of 
 Value2 DCD &0101  -- word allocation with hex value of 
 Value3 DCD &0001  -- word allocation with hex value of 
 Result DCD &FFFFFFF0 -- word allocation with hex value of 

此代码试图保存r2r1相等的事实,否则由于保存在其中的值的静态性质,将发生无限循环Value<1-3>

于 2019-05-28T08:14:29.383 回答