Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the swap_array and print_array subroutines in ARM, most of the code is provided just needs filled in, in two spots. The swap_array swaps two

Complete the swap_array and print_array subroutines in ARM, most of the code is provided just needs filled in, in two spots. The swap_array swaps two elements of an array, given the address of the array and two (valid) indexes of that array, use a temp variable on the stack as part of the swap and each element of the array is 1 byte in size.

CODE TO BE FILLED IN:

.equ SWI_Exit, 0x11 @ Terminate program code .equ SWI_Open, 0x66 @ Open a file @ inputs - R0: address of file name, R1: mode (0: input, 1: write, 2: append) @ outputs - R0: file handle, -1 if open fails .equ SWI_Close, 0x68 @ Close a file @ inputs - R0: file handle .equ SWI_RdInt, 0x6c @ Read integer from a file @ inputs - R0: file handle @ outputs - R0: integer .equ SWI_PrInt, 0x6b @ Write integer to a file @ inputs - R0: file handle, R1: integer .equ SWI_RdStr, 0x6a @ Read string from a file @ inputs - R0: file handle, R1: buffer address, R2: buffer size @ outputs - R0: number of bytes stored .equ SWI_PrStr, 0x69 @ Write string to a file @ inputs- R0: file handle, R1: address of string .equ SWI_PrChr, 0x00 @ Write a character to stdout @ inputs - R0: character .equ inputMode, 0 @ Set file mode to input .equ outputMode, 1 @ Set file mode to output .equ appendMode, 2 @ Set file mode to append .equ stdout, 1 @ Set output target to be Stdout @------------------------------------------------------- @ Main Program MOV R0, #stdout @ Print the array before the swap LDR R2, =_Data LDR R1, =Data SUB R2, R2, R1 STMFD SP!, {R2} @ Push length of list STMFD SP!, {R1} @ Push address of list BL print_array ADD SP, SP, #8 BL PrintLF @ Swap the array data MOV R1, #1 STMFD SP!, {R1} @ Push j MOV R1, #7 STMFD SP!, {R1} @ Push i LDR R1, =Data STMFD SP!, {R1} @ Push a BL swap_array ADD SP, SP, #12 BL PrintLF @ Print the array after the swap LDR R2, =_Data LDR R1, =Data SUB R2, R2, R1 STMFD SP!, {R2} @ Push length of list STMFD SP!, {R1} @ Push address of list BL print_array ADD SP, SP, #8 BL PrintLF SWI SWI_Exit @------------------------------------------------------- PrintLF: /* ------------------------------------------------------- Prints the line feed character ( ) ------------------------------------------------------- Uses: R0 - set to ' ' (SWI_PrChr automatically prints to stdout) ------------------------------------------------------- */ STMFD SP!, {R0, LR} MOV R0, #' ' @ Define the line feed character SWI SWI_PrChr @ Print the character to Stdout LDMFD SP!, {R0, PC} @------------------------------------------------------- swap_array: /* ------------------------------------------------------- Swaps location of two values in list. swap(a, i, j) Parameters passed on stack: Address of list Index of first value (i) Index of second value (j) Local variable temp ------------------------------------------------------- Uses: ------------------------------------------------------- */ STMFD SP!, {FP, LR} @ push frame pointer and link register onto the stack MOV FP, SP @ save current stack top to frame pointer SUB SP, SP, #4 @ set aside space for temp STMFD SP!, {?} @ preserve other registers @ your code here LDMFD SP!, {?} @ pop preserved registers ADD SP, SP, #4 @ remove local storage LDMFD SP!, {FP, PC} @ pop frame pointer and program counter @------------------------------------------------------- print_array: /* ------------------------------------------------------- Prints all integer values comma-separated in an array of bytes. (i.e. 2,4,7,1,6,...) with no trailing comma. Parameters passed on stack: Address of list Length of list ------------------------------------------------------- Uses: ------------------------------------------------------- */ @ your code here @------------------------------------------------------- .data Data: .byte 4,5,9,0,8,0,8,7,1 @ The list of data _Data: @ End of list address .end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

1) Execute the following R commands in RSTUDIO: thisNumber

Answered: 1 week ago