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 applications of parallel processing, APPLICATIONS OF PARALLEL PROCE...

APPLICATIONS OF PARALLEL PROCESSING Parallel computing is an development of sequential computing which tries to emulate what has always been the condition of affairs in natural

The advantage of using a database management system, The advantage of using...

The advantage of using a Database Management System The advantage of using a Database Management System for a data store is that databases have mechanisms for describing data,

Should validation occur server- side or client - side, Should validation (d...

Should validation (did the user enter a real date) occur server-side or client-side? Why? Validation will be completed in both sides i.e., at the server side and client side. S

Explain turing reducibility, Explain Turing reducibility?  Exponential ...

Explain Turing reducibility?  Exponential time algorithms typically happens when we solve by searching by a space of solutions known as brute -force search

Write a small program using floating-point operations, Question: a) Wri...

Question: a) Write a small program using floating-point operations in Reverse Polish Notation to evaluate the following: Volume of Sphere = (4/3)πr 3 Consider that the u

Show the classification of networks, There are various approaches to the cl...

There are various approaches to the classification of Computer Networks. One such classification is based on distance approach. Networks can be classified into LAN, WAN and MAN net

Definition of lists, Q. Definition of Lists? Another type of list is a ...

Q. Definition of Lists? Another type of list is a definition list. Definition lists have a heading and text appears below that. EXPERTSMI

What a header script can specify in cgi, A header in CGI script can specify...

A header in CGI script can specify? A header into CGI script can give format of document and New location of perticular the document.

Handling multiple devices - computer architecture, Handling Multiple Device...

Handling Multiple Devices Interrupt Priority   Continue to accept interrupt requests from higher priority components   Disable interrupts from component at the sa

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