Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Rewrite Example 13.5 using an empty descending stack. Assume that SRAM_BASE = 0x20002000. EXAMPLE 13.5 The same shift routine we wrote earlier could be written
Rewrite Example 13.5 using an empty descending stack. Assume that SRAM_BASE = 0x20002000. EXAMPLE 13.5 The same shift routine we wrote earlier could be written as shown below, now passing the address of our parameters in SRAM to the subroutine through register 13. Again, the target is the LPC2132. SRAM_BASE 0x40000000 AREA Passbymem, CODE, READONLY EQU ENTRY LDR sp, =SRAM_BASE ; stack pointer initialized LDR r3, =SRAM_BASE+100 ; writable memory for parameters ; try out a positive case (this should saturate) MOV ri, #0x40000000 MOV r2, #2 STMIA r3, {ri, r2) i save off parameters BL saturate ; try out a negative case (should not saturate) MOV ri, #OxFFFFFFFE MOV r2, #8 STMIA r3, {r1,r2) BL saturate stop B stop 286 ARM Assembly Language 286 ARM Assembly Language saturate ; Subroutine saturate32 ; Parameters are read from memory, and the ; starting address is in register r3. The result ; is placed at the start of parameter memory. Registers used: ; r3 - holds address of parameters in memory i r4 - result ; r5 - operand to be shifted ; r6 - scratch register i r7 - shift amount (m) i save off used registers i get parameters ; r4 = saturate32 (r5 m) STMIA sp!, (r4-17, 1r} LDMIA r3, {r5, r7) MOV r6, 0xFFFFFFF MOV r4, r5, LSL r7 TEQ r5, r4, ASR r7 EORNE r4, r6, r5, ASR #31 STR r4, [r3) LDMDB sp!, {r4-27, pe} ; if (r5! = (r4 >>m)) ; r4 = Ox7FFFFFFF*sign (r5) ; move result to memory i return END The operand to be shifted and the shift count are stored in memory starting at address SRAM_BASE + 100, where they are read by the subroutine. The entry to the subroutine does some housekeeping by saving off the registers about to be corrupted to the stack, including the Link Register. This is required by the ARM Application Procedure Call Standard (AAPCS), which is covered shortly. There are two options for returning a value from this subroutine. The first is to just store it back in memory for later reading by some other code. The second option is to return the value in a register, say register 13. In our example, the value is stored back to memory. If you were doing string comparisons, you might call a subroutine and send the addresses of the two strings to the subroutine, expecting either a one (they matched) or a zero (they did not match) to be stored in a register as the result. Rewrite Example 13.5 using an empty descending stack. Assume that SRAM_BASE = 0x20002000. EXAMPLE 13.5 The same shift routine we wrote earlier could be written as shown below, now passing the address of our parameters in SRAM to the subroutine through register 13. Again, the target is the LPC2132. SRAM_BASE 0x40000000 AREA Passbymem, CODE, READONLY EQU ENTRY LDR sp, =SRAM_BASE ; stack pointer initialized LDR r3, =SRAM_BASE+100 ; writable memory for parameters ; try out a positive case (this should saturate) MOV ri, #0x40000000 MOV r2, #2 STMIA r3, {ri, r2) i save off parameters BL saturate ; try out a negative case (should not saturate) MOV ri, #OxFFFFFFFE MOV r2, #8 STMIA r3, {r1,r2) BL saturate stop B stop 286 ARM Assembly Language 286 ARM Assembly Language saturate ; Subroutine saturate32 ; Parameters are read from memory, and the ; starting address is in register r3. The result ; is placed at the start of parameter memory. Registers used: ; r3 - holds address of parameters in memory i r4 - result ; r5 - operand to be shifted ; r6 - scratch register i r7 - shift amount (m) i save off used registers i get parameters ; r4 = saturate32 (r5 m) STMIA sp!, (r4-17, 1r} LDMIA r3, {r5, r7) MOV r6, 0xFFFFFFF MOV r4, r5, LSL r7 TEQ r5, r4, ASR r7 EORNE r4, r6, r5, ASR #31 STR r4, [r3) LDMDB sp!, {r4-27, pe} ; if (r5! = (r4 >>m)) ; r4 = Ox7FFFFFFF*sign (r5) ; move result to memory i return END The operand to be shifted and the shift count are stored in memory starting at address SRAM_BASE + 100, where they are read by the subroutine. The entry to the subroutine does some housekeeping by saving off the registers about to be corrupted to the stack, including the Link Register. This is required by the ARM Application Procedure Call Standard (AAPCS), which is covered shortly. There are two options for returning a value from this subroutine. The first is to just store it back in memory for later reading by some other code. The second option is to return the value in a register, say register 13. In our example, the value is stored back to memory. If you were doing string comparisons, you might call a subroutine and send the addresses of the two strings to the subroutine, expecting either a one (they matched) or a zero (they did not match) to be stored in a register as the result
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started