+1 (315) 557-6473 

Sorting Array Values Homework Help in C

This sample shows Rearranging Array Values Homework Help in C. The C Programming Homework Helper who solved it rearranged the elements of the given array from the smallest to the largest in the first section. In the second section, his Programming Homework Help shows how to generate a Fibonacci series and store its elements in different bytes. What’s more, he displays the results in different screenshots.
Sorting Array Values Homework Help

Rearranging Array Values Project help

Rearrange the values of the following array into the order shown. Use only MOV and XCHG to get the desired results. Don't use any immediate values except in the .data section. Use only direct offset addressing to accomplish the goal.
Original Array: MyArray WORD 4567h, 2348h, 3338h. At the end of this part of the homework, your code of the array will appear in increasing order.
You'll be using a new Irvine Library function. Call DumpMem.
To use this, you need this information;
ESI = Offset of myArray
ECX = # of elements in myArray. Use the $ directive to obtain this information.
EBX = unit size
Solution
INCLUDE irvine32.inc
.DATA
MyArray WORD 4567h, 2348h, 3338h
ArraySize = ($ - MyArray) / 2
.CODE
main PROC
        mov ax, [MyArray] ; load first value
        xchg ax, [MyArray + 4] ; save in third position and get previous value in ax
        xchg ax, [MyArray + 2] ; save in second position and get previous value in ax
        mov [MyArray], ax ; save in firt position to complete the sort
        ; Dump myArray contents to screen
        mov esi, OFFSET MyArray ; offset of myarray
        mov ecx, ArraySize ; number of elements in array
        mov ebx, TYPE WORD ; size of each element
        call DumpMem ; dump contents
        exit ; terminate the program
main ENDP
END main
Rearranging Array Values Project help
Sorting And Storing Fibonacci Array Values Homework Help In C
a). fib(n) for n = 2, 3, ..., 9 using an array of the appropriate size and type. If you like, you may declare a value for fib(0) and fib(1). However, all computation of the remaining elements if the array must be done by your program. No use of immediate value is allowed.
b). After your array is filled with required values, store fib(5) through fib(9) in consecutive bites of the EBX register starting from the lowest byte. That is, fib(5) is stored in the low byte (bl) of EBX, fib(6) in the next (bh), fib(7) in the next, and fib(8) in the highest byte.
Solution
INCLUDE irvine32.inc
.DATA
fib BYTE 0, 1, ?, ?, ?, ?, ?, ?, ?, ?
fib5 = fib + 5
.CODE
main PROC
        mov esi, OFFSET fib ; load address of fibonacci array
        mov al, [esi] ; load first fibonacci value
        inc esi ; advance to second position in array
        mov ah, [esi] ; load next fibonacci value
        inc esi ; advance to next position in array
        mov ecx, LENGTHOF fib - 2 ; initialize loop count to size - 2 elements
loop1:
        add al, ah ; add fib(n) + fib(n -1)
        mov [esi], al ; save result in fib(n+1)
        inc esi ; advance to next position in array
        xchg ah, al ; use fib(n+1) as fib(n) and fib(n) as fib(n-1) in next iteration
        loop loop1 ; loop through all elements in fib array
        ; save fib(5) to fib(9) in ebx
        mov ebx, DWORD PTR [fib5] ; load 4 bytes in ebx: fib(5), fib(6), fib(7) and fib(8)
        call DumpRegs ; Dump register contents to screen
        exit ; terminate the program
main ENDP
END main
Rearranging Array Values Project help
Related Blogs
Related Topics