Skyler Bang
Skyler Bang

Reputation: 51

ARM7 ViSUAL Emulator and Keil uVision4

There are two questions about ARM7 ViSUAL EMulator and Keil uVision4.

I have run the code but I still don't understand what it does.

 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

Result on the ARM7 Emulator

Upvotes: 0

Views: 198

Answers (1)

Tarick Welling
Tarick Welling

Reputation: 3255

The memory allocations (DCD) are done in the same area as the code declaration. Which means that it probably will be used as if AREA PROGRAM, CODE, READONLY was set and as such keil won't assemble it. It also means that if it was assembled the data locations will be READONLY. A proper declaration of variables would be preceded by 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 

This code tries to save the fact that r2 and r1 are equal or an infinite loop will occur because of the static nature of the values saved inside Value<1-3>

Upvotes: 2

Related Questions