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

Define the term- encryption, Define the term- encryption The user would ...

Define the term- encryption The user would then type in O P E and card purchase will be authorised. This extra protection is used as well as encryption. Some of the new syste

Workday versus oracle, Workday has set the stage to revolutionize the way c...

Workday has set the stage to revolutionize the way companies manage and facilitatevarious aspects of their business operationsby utilizing cutting-edge cloud-based technologies in

What is file scope, Explain File scope File scope: The variables and ...

Explain File scope File scope: The variables and functions with file scope appear outside any block or list of parameters and are accessible from any place in the translation

Indian standard code for information interchange, The ISCII is an 8-bit cod...

The ISCII is an 8-bit code which contains standard ASCII values till 127 from 128-225 it contains characters necessary in ten Brahmi-based Indian scripts. It is defined in IS 13194

What is the main function of the memory-management unit, What is the main f...

What is the main function of the memory-management unit? The runtime mapping from virtual to physical addresses is done by a hardware device known as a memory management unit

What is an compiled languages, What is an compiled languages In compile...

What is an compiled languages In compiled languages the instructions into machine code and kept them  in a separate file for later implementation. Many modern compilers can com

What do you mean by parallel virtual machine, Q.What do you mean by Paralle...

Q.What do you mean by Parallel virtual machine? PVM is essentially a simulation of a computer machine running parallel programs. It is a software package which allows a heterog

CRTscreen as a two-dimensional matrix, Explain the statement- CRT screen as...

Explain the statement- CRT screen as a two-dimensional matrix One can imagine the CRT screen as a two-dimensional matrix which has m rows and n  columns and this is usually ref

Uml, what is uml ?

what is uml ?

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