Question

Write an ARM assembly language program for Heap Sort.

Write an ARM assembly language program for Heap Sort.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
/*
R0 address of string used with printf ti output %d
R4 address of numbers to sort
R5 current number to be compared
R6 offset index for outer loop through numbers
R7 offset index for inner loop
R8 current smallest identified value
R9 current offset index of next uncompared value
*/
.global main
main:
  push {ip, lr}
  MOV R6, #0 @outerloop offset to numbers to be sorted
  MOV R7, #0 @innerloop offers to number to be sorted
  MOV R9, #0 @init value for index to next uncompared value
outerLoop:
  MOV R8, #99 @reset large default for next loop comparison
  MOV R7,R6 @copy outerloop offset to next starting offset for the innerloop
innerLoop:
  LDR R0, =output @load addr of output string
  LDR R4, =nums @load addr of nums to compare to R4
  LDR R5,[R4,R7] @load current num to R5 from R4 with offset R7
  MOV R1,R5 @move num for output
  BL printf
  CMP R5,R8 @is current < smallest so far
  BLT swapSmallest @if true, swap smallest to current first position then continue
continue:
  CMP R7,#16 @ 0 plus 4*4bytes for 5 entries in array
  ADD R7, R7,#4 @inc offset by 4 bytes
  BLT innerLoop
continueOuterLoop:
  CMP R6, #16 @check if we've looped through all values
  ADD R6, R6, #4
BLT outerLoop @if not, branch back to start of outer loop
_exit:
  POP {ip, lr}
resetLoopOffsets:
  MOV R7, #0 @reset loop counter
writeFinalSoredList: @TODO: this is a near copy of the innner loop - refactor this to function
  LDR R0, =writeSorted @load addr of output string
  LDR R4, =nums @load addr of nums
  LDR R5,[R4,R7] @load current num to R5 from R4 with offset R7
  MOV R1,R5 @move num for output
  BL printf
  CMP R7,#16 @ 0 plus 4*4bytes for 5 entries in array
  ADD R7, R7,#4 @inc offset by 4 bytes
  BLT writeFinalSoredList
doExit:
  MOV R1, #0
  MOV R7, #1
  SWI 0
swapSmallest:
  MOV R8,R5 @keep copy of smallest in the current loop
  LDR R10, [R4,R6] @tmp copy first position to R10
  LDR R11, [R4,R7] @tmp copy value in position currently being compared
  STR R10, [R4, +R7] @swap first position value to current position being compared
  STR R11, [R4, +R6] @swap the current smallest value into the current first position
  BX lr @return
.data
nums:
.word 5,2,7,1,8
output:
.asciz "%d\n"
writeSorted:
.asciz "%d\n"
Add a comment
Know the answer?
Add Answer to:
Write an ARM assembly language program for Heap Sort.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ARM assembly language Write a program "fibonacci.s" that computes the Nth Fibonacci number where N is...

    ARM assembly language Write a program "fibonacci.s" that computes the Nth Fibonacci number where N is not so large that overflow of integer arithmetic is a concern. When your assembly language program is called it should expect the value of N to be passed using register r0 and your program should return the Nth Fibonacci number in register r0. Please include comments as well. Do not just use the output generated by gcc -S

  • Using ARM assembly language to write a program, the program can take the full (unsigned) 10-bit...

    Using ARM assembly language to write a program, the program can take the full (unsigned) 10-bit number selected via the switches, and display its value on the 7-segment display as four hexadecimal digits. For example, the switch settings of 1010111001 would display as 02B9, and 1111101101 would display as 03ED.

  • Write an ARM assembly language program to collect the correct amount of road toll tax from...

    Write an ARM assembly language program to collect the correct amount of road toll tax from a vehicle. If the vehicle is a motorbike then the correct road toll tax should be 2, otherwise the road toll tax should be 5. The vehicle type is given to you, so you don’t have to guess. Assume that someone has already put the vehicle type value in register R0. Therefore, R0 contains a value, 0 or some other value. If the value...

  • Four Integer Stats Write an ARM Assembly Language (I will not accept Intel Assembly code) program...

    Four Integer Stats Write an ARM Assembly Language (I will not accept Intel Assembly code) program to prompt the user to enter four integers. Have your program output to the screen the four integers that were entered at the keyboard, along with the following: sum of the four integers, smallest value, largest value, and the average of the four values. You must utilize the scanf function for reading in the user input and the printf function for outputting the results...

  • Write a program in ARM assembly language that copies each element of array A to consecutive...

    Write a program in ARM assembly language that copies each element of array A to consecutive fourth elements of array B, i.e., A[0] to B[0], A[1] to B[3], A[2] to B[7], etc. The array A is 12 elements long, and each element is a number that is 32 bits (1 word) wide. Assume the base address of array A is in register R2, and the base address of array B is in R3.

  • Write an ARM assembly language program to translate the following sequence of statements . Assume x...

    Write an ARM assembly language program to translate the following sequence of statements . Assume x and y are memory locations that store two unsigned integers. Use the following: x is in R1, y is in R2, and z in R3. Make sure that your program works for any value of x and y. if (x > 15) {     x = 1;     if (y > 15) {          y = 2;         } else {       y =...

  • Write a simple program in arm, assembly language , using only Registers, to test if 371...

    Write a simple program in arm, assembly language , using only Registers, to test if 371 is an Armstrong number. The program written should only have instruction set from the Cortex m0+. And then put a 1 in a register to show it It is, or 0 if it isn’t. The second program is about the Armstrong numbers. You assume it will be a 3-digit number which will be entered through the data area. You can use a register so...

  • IN ARM7TDMI Problem 2 ARM Assembly Programming; Splitting Array an - Write an ARM assembly program...

    IN ARM7TDMI Problem 2 ARM Assembly Programming; Splitting Array an - Write an ARM assembly program to split to the end. This program first accepts an array. Then splits specification. Now it becomes 2 parts and then add first part of an array at the end of the second part. Assume an array of size 50 elements and define its elements using DCD directive an array from specified position and add first part an array according to the user Draw...

  • Write an Assembly language program to: A- Store the following text " Welcome to Assembly Language" in the ROM a...

    Write an Assembly language program to: A- Store the following text " Welcome to Assembly Language" in the ROM at 200H B- Find how many e letters in this word and store the count in the RAM in location 40H Write an Assembly language program to: A- Store the following text " Welcome to Assembly Language" in the ROM at 200H B- Find how many e letters in this word and store the count in the RAM in location 40H

  • I need to create a bubble sort program for the numbers 1,2,3,4,5 in assembly language using...

    I need to create a bubble sort program for the numbers 1,2,3,4,5 in assembly language using Microsoft visual studio

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT