In: Computer Science
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
Assuming that the numbers are stored from memory address 2000 : 501 and the size of the array n is stored in 2000:500.
Algorithm -
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 –