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

Explain scripts and libraries introduction, Scripts A script within Rati...

Scripts A script within Rational Robot is a file that haves a sequence of SQABasic code. The extension of the file is always ".REC". Typically the script have an automated testc

Define the don''t care states - simplifying k maps, Define the Don't Care S...

Define the Don't Care States - Simplifying K Maps? The Truth table specifications for a logic function may not to include all possible combinations of the input binary digits for

Explain the boolean equations for logic circuits, Explain The Boolean Equat...

Explain The Boolean Equations for Logic Circuits? A Boolean equation is the mathematical representation of a logic circuit using standard Boolean terms. All the logic gates (AND,

How to set cell properties in dreamweaver, Q. How to Set Cell Properties in...

Q. How to Set Cell Properties in dreamweaver? Cell height determines the height of space within a cell row. Notice the space around Compass logo. You want to remove the extra s

Classified the vlsi technology, The VLSI technology is still developing. Mo...

The VLSI technology is still developing. More and more powerful microprocessors and more storage space now are being put in single chip. One question that we have still not conside

Why we need to construct state transition diagram, Why we need to construct...

Why we need to construct state transition diagram Basically you need to construct a state transition diagram for each object with important behaviour. You need not construct on

How are interrupt handled by the operating system, How are interrupt hand...

How are interrupt handled by the operating system? The fundamental interrupt mechanism works as follows: The CPU hardware has wire called the interrupt-request line which

What is the basic workflow order for color match, Question: (a) What is...

Question: (a) What is the difference between the Color Pass and the Color Replace effects? (b) What is the basic workflow order for Color Match? (c) Explain clearly the

What is mqseries cluster, Cluster is said to be collection of queue manager...

Cluster is said to be collection of queue manager's logically linked together to balance the load on the remote machine (i.e if it is remote queue managers which processes your mes

Formal analysis of visual elements, Formal Analysis: The second step o...

Formal Analysis: The second step of the art critiquing process often begins with an analysis of the artworks formal elements and how they are the organised. The formal elem

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