Google

Dec 21, 2007

Assembly Language Programs on array of Hexadecimal numbers

AIM: To write 8086 Assembly Language Program to sorting n-hexadecimal number in ascending order.

Answer:

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

LIST DW 53H, 25H, 02H, 19H ; Array (list) containing 4 elements is initialized.

COUNT EQU 04 ; Count is initialized to 4

.CODE ; Code segment starts

START:

MOV AX,@DATA ;Initialize the data segment

MOV DS,AX

MOV DX,COUNT-1 ;Move 03(count-1) to DX register

LOOP0: MOV CX,DX ;Move the contents of DX to CX register

MOV SI,OFFSET LIST ;Move the pointer variable of array(list) to SI

LOOP1: MOV AX,[SI] ;Move the contents of array pointed by SI to AX register

CMP AX,[SI+2] ;Compare the contents of array pointed by SI and SI+2

JL PR1 ; Transfers the control to PR1 if OF & SF are SET i.e. if 1st no<2nd style="font-size:130%;">

AIM: To write 8086 Assembly Language Program to sorting n-hexadecimal number in descending order.


Answer:

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

LIST DW 53H, 25H, 02H, 19H ; Array (list) containing 4 elements is initialized.

COUNT EQU 04 ; Count is initialized to 4

.CODE ; Code segment starts

START:

MOV AX,@DATA ;Initialize the data segment

MOV DS,AX

MOV DX,COUNT-1 ;Move 03(count-1) to DX register

LOOP0: MOV CX,DX ;Move the contents of DX to CX register

MOV SI,OFFSET LIST ;Move the pointer variable of array(list) to SI

LOOP1: MOV AX,[SI] ;Move the contents of array pointed by SI to AX register

CMP AX,[SI+2] ;Compare the contents of array pointed by SI and SI+2

JG PR1 ; Transfers the control to pr1 if OF & SF

; are RESET i.e. if 1st no>2nd no.

XCHG [SI+2],AX ;Exchanges the contents of AX with [SI+2]

XCHG [SI],AX ;Exchanges the contents of AX with [SI]

PR1: ADD SI,02 ;Increments SI by 2

LOOP LOOP1 ; Control passes to LOOP1

DEC DX ; Decrement DX register

JNZ LOOP0 ; Jump to LOOP0 if CX! = 0

INT 03H

END START

INPUT:

LIST 53H, 25H, 02H, 19H

OUTPUT:

SORTED ARRAY OF THE INPUT

53H, 25H, 19H, 02H


AIM: To write 8086 Assembly Language Program to find Number of Positive & Negative hexadecimal numbers in an array.


Answer:

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

LIST DW 2345H, 4567H, 8125H, 0A120H ; Initialize an array (LIST) of 16bit

COUNT EQU 04 ; Initialize count variable

.CODE ; Code segment starts

START:

XOR BX,BX ; Clear the contents of BX register

XOR DX,DX ; Clear the contents of DX register

MOV AX,@DATA ; Initialize data segment

MOV DS,AX

MOV CL,COUNT ;Move count to CL register

MOV SI,OFFSET LIST ;Offset of array is moved to SI

LOOP1: MOV AX,[SI] ;The contents of array pointed by SI are moved to AX

SHL AX,01 ;After SHL, the MSB will contain the SIGN FLAG

JC NEG1 ; Jump on no carry to NEG1

INC BX ; Increment BX register

JMP NEXT ; Jump to NEXT

NEG1: INC DX ; Increment DX register

NEXT: ADD SI,02 ;Increment SI by 2

DEC CL ; Decrement CL by 1

JNZ LOOP1 ; Jump to loop1 if ZF! = 0

INT 03H

END START

INPUT:

ARRAY OF 16BITS

LIST DW 2345H, 4567H, 8125H, 0A120H

OUTPUT:

BX register gives the no of positive numbers in the given array (LIST)

DX register gives the no of negative numbers in the given array (LIST)

AIM: To write 8086 Assembly Language Program to find Number of Even & Odd hexadecimal numbers in an array.


Answer:

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

LIST DW 2345 H, 4567 H, 8125 H, 0A120 H, 6742 H ; Initialize an array (LIST) of 16bit

COUNT EQU 05 ; Initialize count variable

.CODE ; Code segment starts

START:

XOR BX,BX ;Clear the contents of BX register

XOR DX,DX ;Clear the contents of DX register

MOV AX,@DATA ;Initialize data segment

MOV DS,AX

MOV CL,COUNT ;Move count to CL register

MOV SI,OFFSET LIST ;Offset of array is moved to SI

LOOP1: MOV AX,[SI] ;The contents of array pointed by SI are moved to AX

ROR AX,01 ;After ROR, the LSB specifies if the no is even/odd

JC ODD ;Jump on no carry to ODD

INC BX ; Increment BX register

JMP NEXT ; Jump to next

ODD: INC DX ; Increment DX register

NEXT: ADD SI,02 ;Increment SI by 2

DEC CL ; Decrement CL by 1

JNZ LOOP1 ; Jump to loop1 if ZF! = 0

INT 03H

END START

INPUT: ARRAY OF 16-BITS

LIST DW 2345H, 4567H, 8125H, 0A120H

OUTPUT:

BX register gives the no of odd numbers in the given array (LIST)

DX register gives the no of odd numbers in the given array (LIST)

You might be also interested in:
:: Temperature Control system using 8086
:: Traffic light control system using 8086
:: Assembly Language Program to serve NMI

6 comments:

Maxxx said...

Thnx Bro!!

Melwyn Cardozo said...

cool blog man....
realy helpd alot...

www.melwynsblog.blogspot.com

Raptor said...
This comment has been removed by the author.
AnKiTa MeHtA said...

thank yu those wer of gr8 help..

Pradip Yadav said...

for more microprocessor and microcontroller programming
visit http://www.pradipyadav.com

shantanu mahajan said...

very useful blogs for enginnering students