Inverted syntax: Difference between revisions

→‎{{header|ARM Assembly}}: Original text had nothing to do with the task. Rewrote with a better example.
(→‎{{header|ARM Assembly}}: Original text had nothing to do with the task. Rewrote with a better example.)
Line 104:
</pre>
=={{header|ARM Assembly}}==
Typically, instructions with a destination register and a source register will have the leftmost register be the destination and the registers to the right be the source.
{{works with | ARM7TDMI}}
 
This version of the ARM is limited in the distance a branch command can go. Standard branch statements cannot branch more than 4 kilobytes away in either direction. Admittedly, this is incredibly generous and is unlikely to be reached. To branch farther away, the most common method is the <code>BX</code> instruction, which means "Branch and Exchange." This takes a register as its operand and exchanges the program counter with the value in that register. This is most often used to exit subroutines with <code>BX LR</code>. You can also move a desired memory location into the program counter directly, but this is not recommended as there is no way to return where you came from.
<lang ARM Assembly>MOV R0,R3 ;copy R3 to R0
ADD R2,R1,R5 ;add R1 to R5 and store the result in R2.</lang>
 
However there is one exception: the <code>STR</code> command. Its source is on the left and its destination is on the right. This inverted syntax is not optional.
<lang ARM Assembly>STR r0,[r4] ;store the contents of R0 into the memory location specified by R4.</lang>
 
This was most likely done for symmetry with the "push/pop" commands:
<lang ARM Assembly>STMFD sp!,{r0-r12,lr} ;push r0 thru r12 and the link register
LDMFD sp!,{r0-r12,pc} ;pop r0 thru r12, and the value that was in the link register is popped into the program counter.</lang>
 
=={{header|Bracmat}}==
1,489

edits