0% found this document useful (0 votes)
17 views4 pages

8086 Lab Programs

The document contains two assembly language programs that count specific types of numbers from a given list. The first program counts even and odd numbers from a list of hexadecimal values, while the second program counts positive and negative numbers from a list that includes both types. Each program includes detailed code, execution steps, and output results for verification.

Uploaded by

K S Rajasekhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

8086 Lab Programs

The document contains two assembly language programs that count specific types of numbers from a given list. The first program counts even and odd numbers from a list of hexadecimal values, while the second program counts positive and negative numbers from a list that includes both types. Each program includes detailed code, execution steps, and output results for verification.

Uploaded by

K S Rajasekhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

2.

Programs on Logical Operations:

2.1 Write an assembly Language program to count Even/Odd numbers from a given List.

ASSUME DS:DATA,CS: CODE

LIST DB 03H,2H,04H,07H,06H ; Define an array (LIST) of 5 bytes (numbers). LIST contains five hexadecimal values)

COUNT EQU 05H (Define COUNT as a constant (5 elements). COUNT is defined as 5 (the number of elements in LIST))

EVENCOUNT DB ? (Variable to store even count)

ODDCOUNT DB ? (Variable to store odd count)

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA (MOV AX, DATA loads the address of the DATA segment into AX.)

MOV DS,AX (MOV DS, AX sets DS to point to the DATA segment.)

MOV SI, OFFSET LIST (sets SI to point to the first byte of the LIST.)

MOV CL, COUNT (loads CL with 5 (the number of elements in the list))

XOR BL,BL (initializes BL (odd counter) to 0.)

XOR DL, DL (initializes DL (even counter) to 0)

BACK:MOV AX, [SI] (Load the current number from LIST into AX)

ROR AX, 01 (rotates the bits of AX right by 1.The rightmost bit (LSB) moves into the Carry Flag (CF).

JC ODD (If CF = 1, the number is odd (jump to ODD))

INC DL (If CF = 0, the number is even (continue to INC DL).)

JMP NEXT (JMP NEXT skips the odd number counting step.)

ODD: INC BL (If the number is odd (CF = 1), INC BL increases the odd count.)

NEXT: INC SI (Move SI to the next element in LIST)

DEC CL (DEC CL decreases the counter CL (number of remaining numbers).)

JNZ BACK (JNZ BACK continues the loop until all numbers are processed.)

MOV EVENCOUNT, DL (MOV EVENCOUNT, DL stores the even count in EVENCOUNT.)


MOV ODDCOUNT,BL (MOV ODDCOUNT, BL stores the odd count in ODDCOUNT)

INT 03H (INT 03H triggers a breakpoint interrupt (for debugging))

CODE ENDS

END START

Program Execution::

SI Points Value Binary LSB Even Count Odd Count


Step Even/Odd
to (Hex) Representation (CF) (DL) (BL)

1 LIST[0] 03H 00000011 1 Odd 0 1

2 LIST[1] 02H 00000010 0 Even 1 1

3 LIST[2] 04H 00000100 0 Even 2 1

4 LIST[3] 07H 00000111 1 Odd 2 2

5 LIST[4] 06H 00000110 0 Even 3 2

Output:

EVENCOUNT = 3 (Numbers: 02H, 04H, 06H)

ODDCOUNT = 2 (Numbers: 03H, 07H)


2.2 Write an assembly Language program to count positive/negative numbers from a given
List.

ASSUME DS:DATA,CS:CODE

DATA SEGMENT

LIST DB 03H, 82H, 04H, 87H, 06H ; Define an array with positive & negative numbers

COUNT EQU 05H ; Number of elements in LIST

POSCOUNT DB ? ; Variable to store positive count

NEGCOUNT DB ? ; Variable to store negative count

DATA ENDS

CODE SEGMENT

START:

MOV AX, DATA ; Load segment address of DATA into AX

MOV DS, AX ; Initialize DS with AX

MOV SI, OFFSET LIST ; SI points to the first element in LIST

MOV CL, COUNT ; CL = 5 (Number of elements in LIST)

XOR BL, BL ; Initialize negative counter BL = 0

XOR DL, DL ; Initialize positive counter DL = 0

CHECK_LOOP:

MOV AL, [SI] ; Load the current number from LIST into AL

BT AL, 7 ; Test bit 7 (MSB) to check sign

JC NEGATIVE ; If MSB = 1, jump to NEGATIVE (number is negative)

INC DL ; If MSB = 0, it's positive; increment POSITIVE count

JMP NEXT ; Skip negative increment

NEGATIVE:

INC BL ; Increment NEGATIVE count


NEXT:

INC SI ; Move SI to the next element in LIST

DEC CL ; Decrement count

JNZ CHECK_LOOP ; If CL is not zero, repeat loop

MOV POSCOUNT, DL ; Store positive count in POSCOUNT

MOV NEGCOUNT, BL ; Store negative count in NEGCOUNT

INT 03H ; Breakpoint interrupt for debugging

CODE ENDS

END START

Program Execution

SI Points Value Binary (8- Bit 7 Positive Count Negative Count


Step Positive/Negative
to (Hex) bit) (MSB) (DL) (BL)

1 LIST[0] 03H 00000011 0 Positive 1 0

2 LIST[1] 82H 10000010 1 Negative 1 1

3 LIST[2] 04H 00000100 0 Positive 2 1

4 LIST[3] 87H 10000111 1 Negative 2 2

5 LIST[4] 06H 00000110 0 Positive 3 2

OUTPUT:

• POSCOUNT = 3

• NEGCOUNT = 2

You might also like