2012-11-21 190 views
1

任何人都可以向我解釋這個簡短的程序是幹什麼的?瞭解ARM彙編代碼

ORIGIN 0x1000 
one DEFW 13 
two DEFW 29 
three DEFW 0 
ORIGIN 0x1010 
ENTRY 
ADR R0, one 
LDR R1, [R0] 
LDR R2, [R0, #4] 
ADD R1, R2, R1 
STR R1, [R0, #8] 
SWI 2 

如果我想正確的,它增加了「一」到「二」,並將結果在「三」。我對麼?

+0

+1爲真棒圖標! –

+1

這是功課嗎?你爲什麼混淆它?如果你這樣做對別人沒用。 – tangrs

回答

7

是的。

ORIGIN 0x1000   # Start at address 0x1000 
one DEFW 13   # Allocate 4-bytes of space for a variable called one and set it to 13 
two DEFW 29   # Allocate 4-bytes of space for a variable called two and set it to 29 
three DEFW 0   # Allocate 4-bytes of space for a variable called three and set it to 0 
ORIGIN 0x1010   # Skip ahead to address 0x1010 (this really leaves a 4-byte gap) 
ENTRY     # Mark next instruction as the begining of program 
ADR R0, one   # Load address of one into R0 
LDR R1, [R0]   # Load contents of one (pointed to but R0) into R1 
LDR R2, [R0, #4]  # Load contents of two (pointed to but R0 + 4) into R2 
ADD R1, R2, R1   # R1 = R2 + R1 
STR R1, [R0, #8]  # Store R1 into three (pointed to but R0 + 8) 
SWI 2     # Execute a software interrupt 

three = one + two 

不知道的 'SWI 2' 這可能是特定於平臺的東西。也許只是程序調用的通用結束。

+0

+1:http://www.ee.ic.ac.uk/pcheung/teaching/ee2_computing/swi.pdf似乎暗示「SWI 2」會打印到某種調試流(至少在該系統上) 。 – Leo

+0

在某些ARM系統上,SWI代表「軟件中斷」。 –

+0

SWI是軟件中斷指令。正如@Pete Fordham所說,SWI 2取決於平臺。 –