8086 Lab Programs
8086 Lab Programs
2.1 Write an assembly Language program to count Even/Odd numbers from a given List.
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))
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA (MOV AX, DATA loads the address of the DATA segment into AX.)
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))
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).
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.)
JNZ BACK (JNZ BACK continues the loop until all numbers are processed.)
CODE ENDS
END START
Program Execution::
Output:
ASSUME DS:DATA,CS:CODE
DATA SEGMENT
LIST DB 03H, 82H, 04H, 87H, 06H ; Define an array with positive & negative numbers
DATA ENDS
CODE SEGMENT
START:
CHECK_LOOP:
MOV AL, [SI] ; Load the current number from LIST into AL
NEGATIVE:
CODE ENDS
END START
Program Execution
OUTPUT:
• POSCOUNT = 3
• NEGCOUNT = 2