ARM Code Fragment 62). What instruction in the ARM ISA is used to call a functio
ID: 3566443 • Letter: A
Question
ARM Code Fragment 62). What instruction in the ARM ISA is used to call a function or subroutine? 63). What is the MACHINE language instruction associated with the assembly language statement given below? 64). What is the address at which the assembly instruction given below is located? 65). Provide an example of a load/store instruction from the code fragment. 66). Provide an example of a pseudo-instruction from the code fragment. 67). Examining the portion of the provided code fragment which services the timer Interrupt, explain the possible mechanisms for optimizing, or reducing the number of instructions required to service the Timer Interrupt.Explanation / Answer
62.
Calling an ARM subroutine from Thumb
The simplest way to carry out a Thumb-to-ARM interworking subroutine call is to BL to an intermediate Thumb code segment that executes the BX instruction. The BL instruction loads the link register immediately before the BX instruction is executed.
In addition, the Thumb instruction set version of BL sets bit 0 when it loads the link register with the return address. When a Thumb-to-ARM interworking subroutine call returns using a BX lr instruction, it causes the required state change to occur automatically.
If you always use the same register to store the address of the ARM subroutine that is being called from Thumb, this segment can be used to send an interworking call to any ARM subroutine. The __call_via_r4 procedure in Example 7.2demonstrates this technique.
Note
You must use a BX lr instruction at the end of the ARM subroutine to return to the caller. You cannot use the MOV pc,lrinstruction to return in this situation because it does not cause the required change of state.
example:
63. 0b110000001000010
64. 0x580c
65.0x58e: 0x2101 movs R1, #1
66.0x5a0: 0xb530 PUSH {R4,R5,LR}
67.
Avoid complex instructions ( lods, stos, movs, cmps, scas, loop, xadd, enter, leave). Complex instructions are instructions that do multiple things. For instance stosb writes a byte to memory and also increments EDI. They stopped making these fast with the original Pentium because they were trying to make it more RISC like. Using REP and the string instructions is still fast. That is the only exception to the case.
This is an oldie, but I am including it anyway. It also has a side benefit of clearing dependencies on the register. That is why sometimes you will see people use XOR in that fashion, before doing a partial register access. I prefer using MOVZX to doing it that way because it is trickier to do using a XOR ( read my above comments about in #12 above talking about MOVZX) . On the P4 they also added support for PXOR to break dependencies in that fashion. I think the P3 does the same thing.
Eliminate branch where possible. This might seem obvious, but I have seen some people use too many branches in their assembler code. Keep it simple. Use as few branches as possible.'
Avoiding memory accesses
Re-structing the code to avoid memory accesses ( or other I/O). One method is to accumulate a value in a register before writing it to memory. Here is an example of that below. In this example assuming we are adding 3 bytes from the source array to the destination array which is an array of dwords. The destination array is zeroed.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.