IT관련 지식들 2010. 3. 6. 10:47
병일이가 물어본 질문에 대한 답.

- STM r0!, {r1-r12}
- LDM r0!, {r1-r12}


저장을 1~12순서로 해 놓으면 마지막에 스택 포인터는 12에 가 있다.

그런데 LOAD에서도 1~12 순서로 로드를 하면 거꾸로 로드가 되지 않을까?

그런데 잘 생각해보니, ARM에서는 스택을 사용하지 않는다. 아니 그거 하고는 상관없을지도 모른다. 그냥 저장할 공간의 수를 보고, 그 숫자에 맞춰서 시작 주소와 끝 주소를 계산해서 저장하고 불러오기 때문에 그렇지 않을까 막연히 생각만 했다.

ARM Architecture reference manual중에서 

--- LDM
<registers>
Is a list of registers, separated by commas and surrounded by { and }. It specifies the set of registers to be loaded by the LDM instruction. The registers are loaded in sequence, the lowest-numbered register from the lowest memory address (start_address), through to the highest-numbered register from the highest memory address (end_address). If the PC is specified in the register list (opcode bit[15] is set), the instruction causes a branch to the address (data) loaded into the PC. For each of i=0 to 15, bit[i] in the register_list field of the instruction is 1 if Ri is in the list and 0 otherwise. If bits[15:0] are all zero, the result is UNPREDICTABLE.

Operation
MemoryAccess(B-bit, E-bit)
if ConditionPassed(cond) then
address = start_address
for i = 0 to 14
if register_list[i] == 1 then
Ri = Memory[address,4]
address = address + 4

if register_list[15] == 1 then
value = Memory[address,4]
if (architecture version 5 or above) then
pc = value AND 0xFFFFFFFE
T Bit = value[0]
else
pc = value AND 0xFFFFFFFC
address = address + 4
assert end_address == address - 4

STM
<registers> Is a list of registers, separated by commas and surrounded by { and }. It specifies the set of registers to be stored by the STM instruction. The registers are stored in sequence, the lowest-numbered register to the lowest memory address (start_address), through to the highest-numbered register to the highest memory address (end_address). For each of i=0 to 15, bit[i] in the register_list field of the instruction is 1 if Ri is in the list and 0 otherwise. If bits[15:0] are all zero, the result is UNPREDICTABLE. If R15 is specified in <registers>, the value stored is IMPLEMENTATION DEFINED. For more details, see Reading the program counter on page A2-9.

Operation
MemoryAccess(B-bit, E-bit)
processor_id = ExecutingProcessor()
if ConditionPassed(cond) then
address = start_address
for i = 0 to 15
if register_list[i] == 1 then
Memory[address,4] = Ri
address = address + 4
if Shared(address) then /* from ARMv6 */
physical_address = TLB(address)
ClearExclusiveByAddress(physical_address,processor_id,4)
/* See Summary of operation on page A2-49 */
assert end_address == address - 4

내 생각이 맞았던것같다. 스택 포인터로 계산하는게 아니라 시작주소를 미리 계산해서 address변수에 넣고 4씩 증가시키면서 저장하고 불러들인다.
posted by 동글동글82
: