Professional Documents
Culture Documents
Further Exercises
Further Exercises
Further Examples
2. Write a program to find the number of elements in the array which are having ‘1’ in their
5th bit position.
Solution: we can use TEST or AND instruction
.MODEL SMALL
.DATA
ARRAY DB 12H, 21H, 34H, 43H, 56H, 89H, 99H, 63H
COUNT DB $-ARRAY ; the number of elements in the ARRAY
.CODE
START: MOV AX, @DATA
MOV DS, AX
MOV CX, COUNT; NUMBER OF ELEMENTS (BYTES) IN THE LIST
LEA SI, ARRAY; SI stores offset address of the first element of in the ARRAY
MOV BL, 00; to store the number of elements having 1 in their 5th position
BACK: MOV AL, [SI]
TEST AL, 00010000B; AND AL, 10H or TEST AL, 10H; testing 5th position.
JNZ NEXT
INC BL
NEXT: INC SI
LOOP BACK
HLT
END START
Before the program is executed, look the value of BL register.
3. Write 8086 ALP to find out the numbers of negative and positive numbers from a given
series of signed 8-bit numbers. Again divide the list into positive and negative lists
NB: in the above program, line 18 and line 19 can be replaced with the following
respective lines below.
18. RCL AL, 01
19. JNC Positive
4. Write 8086 ALP to find out the numbers of even and odd numbers from a given series of
unsigned 8-bit numbers. Again divide the list into odd and even lists
Solution: A number is said to be odd if the right most bit is 0 else it’s even
In the above program, the lines 18 & 19 replaced with their respective lines:
18. RCR AL, 01h
19. JNC EVEN
6. Write a Program to find the largest and smallest number from an array of n 8-bit numbers
The Given Array: 18H, 22H, 15H, 36H, 46H, 63H