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...
Hi this is Assembly Language MASM x86 program. Please write it in the language and please...
Hi this is Assembly Language MASM x86 program. Please write it in the language and please explain it with comments thank you Please answer it I really need help this question was refunded before so please answer. Thank you so much also these are two separate programs thank you. 1) Write a procedure to read in decimal or hex number (byte-sized) Then write a procedure using shifts and ANDS to convert the string to a binary number (if is backward,...
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.
in assembly language x86 Masm, Write a program that calculate the first seven values of the...
in assembly language x86 Masm, Write a program that calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(0) = 0, Fib(1) = 1, Fib(2) = Fib(0)+ Fib(1), Fib(n) = Fib(n-1) + Fib(n-2). You NEED to calculate each value in the series "using registers and the ADD operation" You can also use variables, Have your program print out "The first seven numbers is" Use WriteInt for the printing, Place each value in the EAX...
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 write in x86 Assembly language on Visual Studio. IRVINE32 Write a program to copy one...
Please write in x86 Assembly language on Visual Studio. IRVINE32 Write a program to copy one array of size 24 to another array of size 24 using string instructions. Write 3 versions of this code. One code must copy byte at a time. One code must copy word at a time and one code must copy double word at a time. Cut and paste the array in memory to show your code is working.
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...
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
(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)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT