Question

In: Computer Science

Using x86 assembly language, create a flowchart and write an example of code that will sort...

Using x86 assembly language, create a flowchart and write an example of code that will sort 2 arrays of unsigned doubleword integers in ascending order and output the largest element in each array. Any sorting procedure can be used, but this procedure must be called twice for each array. The first time it is called, the first array should be sorted and the second time it is called, the second array must be sorted. As well as outputting which is largest in each array.

You can use these unsigned doubleword integers in the example.

Array 1: 00000000, 84728372, E222111F

Array 2: 81002346, 22222222, FFFFFFFF

Solutions

Expert Solution

Assuming that the numbers are stored from memory address 2000 : 501 and the size of the array n is stored in 2000:500.

Algorithm -

  1. Load data from offset 500 to register CL (for count).
  2. Travel from starting memory location to last and compare two numbers if first number is greater than second number then swap them.
  3. First pass fix the position for last number.
  4. Decrease the count by 1.
  5. Again travel from starting memory location to (last-1, by help of count) and compare two numbers if first number is greater than second number then swap them.
  6. Second pass fix the position for last two numbers.
  7. Repeat.
MEMORY ADDRESS MNEMONICS COMMENT
400 MOV SI, 500 SI<-500
403 MOV CL, [SI] CL<-[SI]
405 DEC CL CL<-CL-1
407 MOV SI, 500 SI<-500
40A MOV CH, [SI] CH<-[SI]
40C DEC CH CH<-CH-1
40E INC SI SI<-SI+1
40F MOV AL, [SI] AL<-[SI]
411 INC SI SI<-SI+1
412 CMP AL, [SI] AL-[SI]
414 JC 41C JUMP TO 41C IF CY=1
416 XCHG AL, [SI] SWAP AL AND [SI]
418 DEC SI SI<-SI-1
419 XCHG AL, [SI] SWAP AL AND [SI]
41B INC SI SI<-SI+1
41C DEC CH CH<-CH-1
41E JNZ 40F JUMP TO 40F IF ZF=0
420 DEC CL CL<-CL-1
422 JNZ 407 JUMP TO 407 IF ZF=0
424 HLT END

Explanation –

  1. MOV SI, 500: set the value of SI to 500.
  2. MOV CL, [SI]: load data from offset SI to register CL.
  3. DEC CL: decrease value of register CL BY 1.
  4. MOV SI, 500: set the value of SI to 500.
  5. MOV CH, [SI]: load data from offset SI to register CH.
  6. DEC CH: decrease value of register CH BY 1.
  7. INC SI: increase value of SI BY 1.
  8. MOV AL, [SI]: load value from offset SI to register AL.
  9. INC SI: increase value of SI BY 1.
  10. CMP AL, [SI]: compares value of register AL and [SI] (AL-[SI]).
  11. JC 41C: jump to address 41C if carry generated.
  12. XCHG AL, [SI]: exchange the contents of register AL and SI.
  13. DEC SI: decrease value of SI by 1.
  14. XCHG AL, [SI]: exchange the contents of register AL and SI.
  15. INC SI: increase value of SI by 1.
  16. DEC CH: decrease value of register CH by 1.
  17. JNZ 40F: jump to address 40F if zero flat reset.
  18. DEC CL: decrease value of register CL by 1.
  19. JNZ 407: jump to address 407 if zero flat reset.
  20. HLT: stop.

Related Solutions

Write an x86 assembly language program that performs equivalently to the C++ source code file shown...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown below.Please note that commented out behavior must be implemented in x86 assembly language. There is no standard, portable way to perform some of these actions in C++. #include void main() { // Use registers for these in your x86 assembly language program // Only use the .data segment for string (character array) variables int eax; int esi; int ecx; int edi; // Loop the...
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code...
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code that transmits a single character and lights the red LED upon receiving that character. The board will "talk" to itself. The green LED should turn on whenever a message is sent and the LCD will display the message being received.
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings...
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings in locations str1 and str2. Initialize str1 to Computer and initialize str2 to Compater. Assume Str1 holds the correct spelling and str2 may have an incorrect spelling. Use string instructions to check if str2 is correct and if not correct the mistake in str2.
Please complete in MASM (x86 assembly language). Use the code below to get started. Use a...
Please complete in MASM (x86 assembly language). Use the code below to get started. Use a loop with indirect or indexed addressing to reverse the elements of an integer array in place. Do not copy the elements to any other array. Use the SIZEOF, TYPE, and LENGTHOF operators to make the program as flexible as possible if the array size and type should be changed in the future. .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD .data    ; define your...
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers....
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers. Record the time. Run Bubble Check time (compute the processing time) do it 100 times (random numbers) Take the average Insertion: Compare] (some explanations please)
Assembly Language for x86 processors You are to write a program which should first ask for...
Assembly Language for x86 processors You are to write a program which should first ask for 4 random numbers from 0-20 (user will inpute these numbers in no preset order). Input these 5 numbers in variables called num1, num2, num3, num4, and num5. When done, your program should sort these numbers (you will use lots of conditions to check order). num1 should contain smallest number while num5 should contain the biggest. display the contents of num1 through num5 on the...
Write an X86-series assembly language program that checks whether input string is palindrome or not. A...
Write an X86-series assembly language program that checks whether input string is palindrome or not. A palindrome is a word, number, phrase or any other sequence which reads the same backward as forward e.g. madam, racecar. Sample Execution: Please enter a String: redivider The string is a palindrome Another Sample Execution: Please enter a String: abracadabra The string is not a palindrome
Need to code this is assembly language. Using the windows32 framework, write a procedure to read...
Need to code this is assembly language. Using the windows32 framework, write a procedure to read a string and shift each character of the string by one. As an example, if your input string is Abcz, your output should be Bcda. Note that you must test your string for non-alphabetic characters (such as numbers and special characters). If there are non-alphabetic characters, you should terminate your program with an appropriate message. You should display your converted string using the output...
Code using assembly language Create a program using the Irvine32 procedures were the user can input...
Code using assembly language Create a program using the Irvine32 procedures were the user can input a list of 32-bit unsigned integers an “x” number of times, then display these integers to the console in reverse order. Hint: Use loops and PUSH & POP instructions. Extra Challenge: Inform the user with a message what to do; also, tell them what they are seeing.
Given the below pseudocode, write the proper code that implements it using MARIE's assembly language:               ...
Given the below pseudocode, write the proper code that implements it using MARIE's assembly language:                    Input a number and store it in X; if X > 1 then    Y := X + X;    X := 0; endif; Y := Y + 1; Output the value of Y; N.B: You should include the MARIE code in your Answer, with an explanation of each instruction in your code beside it. Example:              Subt One         /Subtract 1 from AC Add a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT