2
votes

I'm using ARMSim which I guess its a ARM simulator and I have this demo program. It basically reads a text file and prints the integers from the text file (only the first line).

Start:
@Open file for input.
LDR R0, =InputFileName
MOV R1, #0
SWI SWI_Open
BCS FileError

@Save file handle to memory.
LDR R1, =InputFileHandle
STR R0, [R1]

@Read integers.
LDR R0, =InputFileHandle
LDR R0, [R0]
SWI SWI_RdInt

@Print to ARMSIM console.
MOV R1, R0
MOV R0, #Stdout
SWI SWI_PrInt

BAL End

FileError:
MOV R0, #Stdout
LDR R1, =FileErrorMess
SWI SWI_PrStr
BAL Quit

End:
SWI SWI_Exit

.data
.align
InputFileHandle: .skip 4
InputFileName: .asciz "integers.txt"
FileErrorMess: .asciz "Can't open file."

It runs fine but I don't really understand how the LDR or STR instructions work. Especially the ones that look like LDR R0, [R0] or STR R0, [R1]. Can anyone clear things up on how these work?

1

1 Answers

6
votes

The LDR and STR instructions use post-indexed addressing to update their address registers.

STR instructions store a word to memory.

LDR instructions load a word from memory.

Read more