Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Text File : 8,23,5,3,8,17,4,20,33 part1.s File : .include nios_macros.s .text /*****************************************************************************/ /* Main Program */ /* Sorts a list of 32-bit numbers in memory. */

Text File :

8,23,5,3,8,17,4,20,33

part1.s File :

.include "nios_macros.s" .text /*****************************************************************************/ /* Main Program */ /* Sorts a list of 32-bit numbers in memory. */ /* */ /* r8 - Address of the size of the list of numbers */ /* r9 - Address of the first number in the list */ /* r10 - Address of the current element being checked */ /* r16 - First number to be compared */ /* r17 - Second number to be compared */ /* r18 - Flag indicating that a swap of positions has occured */ /* r19 - Counter to check when every element has been checked */ /* r20 - Size of the list of numbers */ /*****************************************************************************/ .global _start _start: movia r8, SIZE /* Setup the size address */ movia r9, LIST /* Setup the first element address */ BEGIN_SORT: ldwio r20, 0(r8) /* Get the size of the list */ RESTART_SORT: mov r18, r0 /* Clear the flag register */ movi r19, 1 /* Reset the element counter */ mov r10, r9 /* Start at the first element */ SORT_LOOP: ldwio r16, 0(r10) /* Read in the first number */ ldwio r17, 4(r10) /* Read in the second number */ blt r16, r17, SKIP_SWAP /* Are the numbers already sorted? */ SWAP: stwio r17, 0(r10) /* Swap the numbers */ stwio r16, 4(r10) movi r18, 1 /* Set flag */ SKIP_SWAP: addi r19, r19, 1 /* Increament the element counter */ addi r10, r10, 4 /* Move to the next element in the list */ bne r19, r20, SORT_LOOP /* Loop through all the elements */ bne r18, r0, RESTART_SORT /* Were there no changes on this loop? */ END: br END /* Wait here once the program is done */ .org 0x01000 LIST_FILE: SIZE: .word 0 LIST: .end

part2.s File:

.include "nios_macros.s" .equ STACK, 0x10000 .text /*****************************************************************************/ /* Main Program */ /* Sorts a list of 32-bit numbers in memory. */ /* */ /* r8 - Address of the size of the list of numbers */ /* r9 - Address of the first number in the list */ /*****************************************************************************/ .global _start _start: movia sp, STACK /* Setup the stack and frame pointer */ mov fp, sp /* registers. */ movia XXXX, SIZE /* Setup the size address */ movia r9, LIST /* Setup the first element address */ ldwio r2, 0(r8) /* Set the subroutine parameter regs */ mov r3, r9 call XXXX END: br END /* Wait here once the program is done */ /*****************************************************************************/ /* SORT - Subroutine */ /* Sorts a list of 32-bits number in memory. */ /* */ /* r2 - Size of the list of numbers to be sorted */ /* r3 - Address of the first number in the list */ /* r8 - Address of the current element being checked */ /* r16 - First number to be compared */ /* r17 - Second number to be compared */ /* r18 - Flag indicating that a swap of positions has occured */ /* r19 - Counter to check when every element has been checked */ /*****************************************************************************/ SORT: subi sp, sp, 28 /* Save all used registers on the Stack */ stw ra, 0(sp) stw fp, 4(sp) stw r8, 8(sp) stw r16, 12(sp) stw r17, 16(sp) stw r18, 20(sp) stw r19, 24(sp) addi fp, sp, 28 BEGIN_SORT: RESTART_SORT: mov r18, r0 /* Clear the flag register */ movi r19, 1 /* Reset the element counter */ mov r8, r3 /* Start at the first element */ SORT_LOOP: ldwio r16, 0(r8) /* Read in the first number */ ldwio r17, 4(r8) /* Read in the second number */ blt r16, r17, XXXX /* Are the numbers already sorted? */ SWAP: stwio r17, 0(r8) /* Swap the numbers */ stwio r16, 4(r8) movi r18, 1 /* Set flag */ SKIP_SWAP: addi r19, r19, 1 /* Increament the element counter */ addi r8, r8, 4 /* Move to the next element in the list */ bne r19, r2, XXXX /* Loop through all the elements */ bne r18, r0, RESTART_SORT /* Were there no changes on this loop? */ END_SORT: ldw ra, 0(sp) /* Restore all used register to previous */ ldw fp, 4(sp) /* values */ ldw r8, 8(sp) ldw r16, 12(sp) ldw r17, 16(sp) ldw r18, 20(sp) ldw r19, 24(sp) addi sp, sp, 28 ret /* Return from the subroutine */ .org 0x01000 LIST_FILE: SIZE: .word 0 LIST: .end 

Read the Altera Monitor Program tutorial

Your preparation should include the assembly language programs for Parts I to II.

image text in transcribed

Part 1 Q1. Will the value of r18 change during experiment? Why? (2.5 marks) Q2. The comparison happens to which two registers? (2.5 marks) Part 2 Q3. What is the stack mechanism? (2.5 marks) Q4. What is the range of value change range for the stack point? (2.5 marks)

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

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

What is the difference between plated through-holes and via holes?

Answered: 1 week ago