Question

Assembly MASM x86 Write a complete program that sorts dword unsigned integer array in descending order....

Assembly MASM x86

Write a complete program that sorts dword unsigned integer array in descending order.

Assume that the user doesn’t enter more than 40 integers.

You MUST use the template and follow all the directions there.

You can’t add any more procedures to the template.

The procedures can’t use any global variables (variables that are inside .data segment).

The caller of any procedures sends its argument through the stack.

Inside any procedures, if you need to use a register, you have to preserve its original value. You can't use uses, pushad operators.

The callee is in charge of cleaning the stack.

Your lines must not exceed 80 columns

Sample run:

Enter up to 40 unsigned dword integers. To end the array, enter 0.

After each element press enter:

1

4

3

8

99

76

34

5

2

17

0

Initial array:

1 4 3 8 99 76 34 5 2 17

Array sorted in descending order:

99 76 34 17 8 5 4 3 2 1

Press any key to continue . . .

//////////////////////////////////////////////////////////////////////////////////////////////////////////

Template :

include irvine32.inc
; ===============================================
.data

array dword 40 dup(?)
string1 byte "Enter up to 40 unsigned dword integers. To end the array, enter 0.",0
string2 byte "After each element press enter:", 0
string3 byte "Initial array:",0
string4 byte "Array sorted in descending order:",0

;=================================================
.code
main proc
; YOU NEED TO CALL ENTER_ELEM, SORT_ARR AND PRINT_ARR PROCEDURES

mov edx, offset string1
call writeString
call crlf
call crlf

mov edx, offset string2
call writeString
call crlf

mov esi, offset array
mov ecx, LENGTHOF array
push esi
mov eax, 0
L1:
call Readdec ; read integer into EAX
mov [esi],eax ; store in array
cmp eax, 0
JE end01
add esi,TYPE array ; next integer
call enter_elem
loop L1

end01:
mov edx, offset string3
call writeString

call print_arr

exit
main endp

; ================================================
; void enter_elem(arr_addr)
;
; Input:
; ARR_ADDRESS THROUGH THE STACK
; Output:
; ARR_LENGTH THROUGH THE STACK
; Operation:
; ?
;
enter_elem proc
push ebp ;set ebp
mov ebp, esp
push eax ; save register
mov esi, [ebp + 12]; pointing to value in array
mov ecx, [ebp+8]
add esi, 4 ; move pointer to next value in array
pop eax
pop ebp

ret 4
enter_elem endp
; ================================================
; void print_arr(arr_addr,arr_len)
;
; Input:
; ?
; Output:
; ?
; Operation:
; ?
;

print_arr proc

push ebp ;set ebp
mov ebp, esp
push eax

L2:
mov eax, DWORD ptr [esi] ;store in new array
call writeDec
add esi, TYPE array ;next integer
mov al,', '
call writeChar ;Displays value in EAX
loop L2
pop eax
pop ebp

ret 4
print_arr endp
       ; ================================================
       ; void sort_arr(arr_addr,arr_len)
       ;
       ; Input:
       ; ?
       ; Output:
       ; ?
       ; Operation:
       ; ?
       ;

   sort_arr proc

       ; FILL YOUR CODE HERE
       ; YOU NEED TO CALL COMPARE_AND_SWAP PROCEDURE

   sort_arr endp

       ; ===============================================
       ; void compare_and_swap(x_addr,y_addr)
       ;
       ; Input:
       ; ?
       ; Output:
       ; ?
       ; Operation:
       ; ?
       ;

   compare_and_swap proc

       ; FILL YOUR CODE HERE
       ; YOU NEED TO CALL SWAP PROCEDURE

   compare_and_swap endp

       ; =================================================
       ; void swap(x_addr,y_addr)
       ;
       ; Input:
       ; ?
       ; Output:
       ; ?
       ; Operation:
       ; SWAP ONLY IF Y > X
       ;

   swap proc

       ; FILL YOUR CODE HERE

swap endp

end main

0 0
Add a comment Improve this question Transcribed image text
Answer #1
                                         enter_elem proc
mov eax, 0
    L1:
call    Readdec         ; read integer into EAX
    mov [esi],eax           ; store in array
cmp eax, 0
JE end01
    push ebp          
mov ebp, esp
push eax          ; save register
push esi          ; save register
mov esi, [ebp+12]  ; pointing to value in array
add esi,4

        pop esi pop eax pop ebp add esi, 4 ; move pointer to next value in array

    end01: 

   ret 4
   enter_elem endp
Add a comment
Know the answer?
Add Answer to:
Assembly MASM x86 Write a complete program that sorts dword unsigned integer array in descending order....
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
  • X86 Assembly Language Help to implement the CipherChar Procedure at the end of the given code...

    X86 Assembly Language Help to implement the CipherChar Procedure at the end of the given code INCLUDE Irvine32.inc         .data       KeyPrompt BYTE "Enter the passphrase: ",0       TextPrompt BYTE "Enter the plaintest: ",0           str1 BYTE "The passphrase has length:",0           str2 BYTE "The plaintest has length:",0       KeyIs BYTE "The passphrase: ",0       PlainTextIs BYTE "The plaintext: ",0       CipherTextIs BYTE "The ciphertext: ",0       KMAX = 64                        ; passphrase buffer maximum size       BMAX = 128                       ; test...

  • Task is to implement the following algorithms in Assembly language for x86 processor

    Task is to implement the following algorithms in Assembly language for x86 processor1) Insertion sort Demonstrate Sorted Array of 10 elements in Watch Window for each one Running time of each algorithmsample bubble sort code:;----------------------------------------------------------BubbleSort PROC USES eax ecx esi,pArray:PTR DWORD, ; pointer to arrayCount:DWORD ; array size;; Sort an array of 32-bit signed integers in ascending; order, using the bubble sort algorithm.; Receives: pointer to array, array size; Returns: nothing;-----------------------------------------------------------mov ecx,Countdec ecx ; decrement count by 1L1: push ecx ; save outer...

  • MASM Assembly Language programming question. I'm having serious issues. I am attempting to scan through a...

    MASM Assembly Language programming question. I'm having serious issues. I am attempting to scan through a string and replace all the "o" characters with an exclamation mark (!). However my program does not work and no change seems to occur to the string. Also the loop breaks once the first "o" character is encountered.Is there anyone in this Universe that can help me???Please main PROC    ;mov edi,OFFSET string    mov ecx, LENGTHOF string    mov edi,OFFSET string    L1:...

  • NOTE: explain the lines in comments for better understanding Write an assembly program (for x86 processors...

    NOTE: explain the lines in comments for better understanding Write an assembly program (for x86 processors - Irvine) that has two procedures, a main procedure and a procedure called Fib. The fib procedure is to uses a loop to calculate and printout the first N Fibonacci numbers. Fibonacci sequence is described by the following formula: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n – 1) + Fib(n – 2). The value of N is to be communicated to this...

  • Write a program that turns a 32-bit numeric value (e.g., 0xFFFFh) and converts it to a...

    Write a program that turns a 32-bit numeric value (e.g., 0xFFFFh) and converts it to a byte array such that it can be printed to the screen using a system call method. A loop is necessary for converting the numeric value to ASCII for output. Again, use a system call (e.g., int 80h) to print the value to the console. Calling external functions (e.g. printf) is not allowed. You may use the starter file attached to this assignment. PLEASE WRITE...

  • ASSEMBLY LANGUAGE Write a program using author's routine, WriteString, to print "Hello World". This routine will...

    ASSEMBLY LANGUAGE Write a program using author's routine, WriteString, to print "Hello World". This routine will output to the screen any character data pointed to by the EDX register. It will continue to print until it runs into the null character (zero). We need only to move the address into the EDX register and calll his routine. Lookup in the ASCII code chart the value reqresented by CR and LF. In the program I will define these values using the...

  • Convert this C++ program to x86 assembly language using the Irvine library: #include <iostream> unsigned int...

    Convert this C++ program to x86 assembly language using the Irvine library: #include <iostream> unsigned int x; unsigned int c; unsigned int result; // f(x) = 8x + c // Make sure to push and pop all necessary registers to the stack to // ensure only the EAX register is modified upon return from the function unsigned int Equation(unsigned int x, unsigned int c) { // You CANNOT use the mul or imul operations to perform the multiplication return (8...

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