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

A full binary tree with ''n'' non-leaf nodes, A full binary tree with 'n' n...

A full binary tree with 'n' non-leaf nodes have  2n+l nodes.

When the divide overflow is generated, Divide overflow is generated when ...

Divide overflow is generated when  (A) Sign of the dividend is dissimilar from that of divisor.  (B) Sign of the dividend is same as that of divisor.  (C) The first part

Define alphabet and string, Define Alphabet and String? A finite set of...

Define Alphabet and String? A finite set of symbols is termed as alphabet. An alphabet is frequently signified by sigma, yet can be specified any name. B = {0, 1} here B is

Implement the concept of true and radix minus one complement, Q. Develop a...

Q. Develop a program to implement the concept of true and radix minus one complement. Program should ask for radix and two numbers from that radix. For that two numbers program

Write decoder functionality in only one statement in verilog, Write decoder...

Write decoder functionality in only one statement in verilog module decoder( // Outputs dout, // Inputs din ); input [3:0] din; output [15:0] dout;

Discuss briefly subscriber loop system, Discuss briefly subscriber loop sys...

Discuss briefly subscriber loop system. Subscriber Loop System: Every subscriber in a telephone network is connected usually to the nearest switching office using a dedicated

Classification of systems, Classification of Systems Systems may be cat...

Classification of Systems Systems may be categorized as follows: a)  Formal or Informal b)  Abstract or Physical c)  Closed or Open d)  Automated orManual.

What are the four necessary condition of deadlock prevention, What are the ...

What are the four necessary conditions of deadlock prevention? Four essential conditions for deadlock prevention are: 1.  Removing  the  mutual  exclusion  condition  implie

Explain complex instruction set computer, CISC (Complex Instruction Set Com...

CISC (Complex Instruction Set Computer) CISC stands for Complex Instruction Set Computer. If the control unit having a number of micro-electronic circuitry to make a set of con

Computer graphics, source code for IMPLEMENTATION FOR ELECTROMAGNETIC INDUC...

source code for IMPLEMENTATION FOR ELECTROMAGNETIC INDUCTION

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