Find the largest and the smallest array values, Computer Engineering

Assignment Help:

Q. Find the Largest and the Smallest Array Values?

Write down a program to find the largest as well as the smallest numbers from a given array. This program uses JGE (jump greater than or equal to) instruction since we have presumed the array values as signed. We haven't used JAE instruction that works correctly for unsigned numbers. 

; Program: Initialise the smallest as well as the largest variables as first number in array. They are then compared with the other array values one by one. If valuecomes about to be smaller than assumed smallest number or larger than presumed largest value, the smallest and the largest variables are altered with the new values correspondingly. Let's use register DI to point the current array value and LOOP instruction for looping.

DATA                         SEGMENT

                                    ARRAY DW -1, 2000, -4000, 32767, 500, 0

                                    LARGE DW?

                                    SMALL DW?

DATA                         ENDS

END.

CODE SEGMENT

MOV AX, DATA

MOV DS, AX   ; Initialize DS

MOV DI, OFFSET ARRAY; DI points to the array

MOV AX, [DI]; AX contains the first element

MOV DX, AX; initialize large in DX register

MOV BX, AX; initialize small in BX register

MOV CX, 6   ; initialize loop counter 

A1:                  MOV AX, [DI]; get next array value

CMP AX, BX;is the new value smaller?

JGE A2   ; if greater then (not smaller) jump to 

; A2, to check larger than large in DX

MOV BX, AX; Otherwise it is smaller so move it to

                                    ; The smallest value (BX register)

JMP A3   ; as it is small, thus no need 

            ; To compare it with the large so jump 

; To A3 to continue or terminate loop.

A2:                  CMP AX, DX; [DI] = large

                        JLE A3   ; if less than it implies not large so 

; Jump to A3 

; To continue or terminate

                         MOV DX, AX; otherwise it is larger value, so move 

; It to DX that store the large value

A3:                  ADD DI, 2   ; DI now points to next number

                        LOOP A1   ; repeat the loop until CX = 0

                        MOV LARGE, DX  

                        MOV SMALL, BX; move the large and small in the 

; Memory locations

                        MOV AX, 4C00h

                        INT 21h   ; halt, return to DOS

CODE ENDS


Related Discussions:- Find the largest and the smallest array values

Genetic algorithms - artificial intelligence, Genetic Algorithms: In s...

Genetic Algorithms: In such a scenario the evolutionary approach to "Artificial Intelligence" is one of the neatest ideas of all. Whether we have tried to mimic the functionin

Enumerate about the trackball device, Enumerate about the trackball A t...

Enumerate about the trackball A trackball is a two-dimensional positioning device, a spaceball provides six degrees of freedom. Unlike the trackball, a spaceball does not actua

What is the use of isolated i/o configuration, What is the use of isolated ...

What is the use of isolated I/O configuration.  In isolated I/O configuration the CPU has distinct input and output instructions and each of these instructions is associated wi

Write a program for comparing two strings, Q. Write a program for comparing...

Q. Write a program for comparing two strings? Let's write a program for comparing two strings. Determine the following piece of code that has been written in C to compare two s

Experiment with neural network, Assignment 3.b: Experiment with Neural Netw...

Assignment 3.b: Experiment with Neural Network Background: In this assignment, you will experiment with neural network for solving different types of practical problems. Y

Explain about different types of mice, Q. Explain about different types of ...

Q. Explain about different types of Mice? Mice can be classified on the foundation of numbers of buttons, position sensing technology or type of Interface:  Sensing Technol

Explain about the prepurchase interaction activity, Explain about the Prepu...

Explain about the Prepurchase Interaction activity. Prepurchase Interaction: This interaction for consumers comprises three activities: • Product or service search and di

display the contents of the file grade, a) Input names of students from th...

a) Input names of students from the user, terminated by "ZZZ", 0, 0, 0 and create a data file grades with records of the following form: Student (string), test1 (integer), test2 (i

Recursion, Ask qurecurrion for short noteestion

Ask qurecurrion for short noteestion

Define various classes of interrupts, Q. Define Various classes of Interrup...

Q. Define Various classes of Interrupts? Figure below gives list of some common interrupts and events which causes occurrence of those interrupts. Figure: Various clas

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd