0% found this document useful (0 votes)
9 views

Problms MP

The document discusses various 8086 assembly language instructions including: - Binary arithmetic instructions - Conditional jump instructions like JA, JB, JE, etc. - Programs illustrating IF-THEN-ELSE logic, loops, and searching/finding maximum/minimum values in arrays - Shift and rotate instructions and examples counting bits and checking parity It provides examples of programs using various instructions like ADD, SUB, CMP, DIV, LOOP, SHR and others.

Uploaded by

sharmaamit6059
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Problms MP

The document discusses various 8086 assembly language instructions including: - Binary arithmetic instructions - Conditional jump instructions like JA, JB, JE, etc. - Programs illustrating IF-THEN-ELSE logic, loops, and searching/finding maximum/minimum values in arrays - Shift and rotate instructions and examples counting bits and checking parity It provides examples of programs using various instructions like ADD, SUB, CMP, DIV, LOOP, SHR and others.

Uploaded by

sharmaamit6059
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

binary arithmetic insrtuctions

Conditional Jump Instructions…


IF THEN ELSE Programs…
Programs illustrating loops…
shift /rotate instructions

2/5/2024 1
8086 programming based on
Instruction Set - 1
Programs based on
data transfer instructions
binary arithmetic instructions
logical instructions
shift and rotate instructions
control transfer instructions

2/5/2024 2
Binary Arithmetic Instructions…

2/5/2024 3
Use of instruction ADC
(ADD WITH CARRY)

2/5/2024 4
data segment
a db 0ABh
b db 0A5h
c dw ?
data ends
code segment
assume cs:code, ds:data
start:
mov ax, data
mov ds, ax
mov al, a
add al, b
mov ah, 00h
adc ah, 00h
mov c, ax
mov ah, 4ch
int 21h
code ends
end start

2/5/2024 5
Finding Avg of 2 Temperature Values…

DATA SEGMENT
HI_TEMP DB 92H
LOW_TEMP DB 52H
AVG_TEMP DB ?
DATA ENDS

2/5/2024 6
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
MOV AL, HI_TEMP
ADD AL, LOW_TEMP
MOV AH, 00H
ADC AH, 00H
MOV BL, 02H
DIV BL
MOV AVG_TEMP , AL ;QUOTIENT
MOV AH, 4CH
INT 21H
CODE ENDS
END START

2/5/2024 7
Conditional Jump
Instructions…

2/5/2024 8
MNEMONIC CONDITION TESTED

JA/JNBE (CF OR ZF) =0

JAE/JNB CF=0

JB/JNAE CF=1

JBE/JNA (CF OR ZF)=1

JC CF = 1

JE/JZ ZF = 1

JG/JNLE ((SF XOR OF) OR ZF ) =0

2/5/2024 9
MNEMONIC CONDITION TESTED

JGE/JNL (SF XOR OF)=0

JL/JNGE (SF XOR OF)=1

JLE/JNG ((SF XOR OF) OR ZF )=1

JNC CF=0 (not carry)

JNE/JNZ ZF=0

JNO OF=0 (not overflow)

JNP/JPO PF=0 (not parity/parity


odd)
JNS SF=0 (not sign)
2/5/2024 10
MNEMONIC CONDITION TESTED

JO OF=1 (overflow)

JP/JPE PF (Parity / parity equal)

JS SF=1 (Sign)

2/5/2024 11
IF THEN ELSE Programs…

2/5/2024 12
Finding larger of 2 Nos…

Data segment
a db 12h
b db 34h
msg1 db 10, 13, ‘a is greater than b$’
msg2 db 10, 13, ‘b is greater than a$’
msg3 db 10, 13, ‘a is equal to b$’
Data ends

2/5/2024 13
CODE SEGMENT L1:
ASSUME CS:CODE, DS:DATA LEA DX, msg1
START: MOV AH, 09H
INT 21H
MOV AX, data JMP EXIT
MOV DS, AX
L2:
MOV AL, a LEA DX, msg2
CMP AL, b MOV AH, 09H
INT 21H
JA L1
JB L2 EXIT:
MOV AH, 4CH
LEA DX, msg3 INT 21H
MOV AH, 09H
CODE ENDS
INT 21H END START
JMP EXIT

2/5/2024 14
Assignment…
Check if given number is odd or even
(using DIV instruction)…

2/5/2024 15
Programs illustrating loops…

2/5/2024 16
1. Move n bytes of data from one location
to another (using While loop)…
data segment
array1 db 10h,20h,30h,40h,50h
len db $-array1
array2 db 5 dup(?)
data ends

2/5/2024 17
CODE SEGMENT MOV AL, [SI]
ASSUME MOV [DI], AL
CS:CODE,DS:DATA
START: INC SI
MOV AX,DATA
INC DI
MOV DS,AX
INC CL
JMP L1
MOV CL,00
LEA SI, array1
LEA DI, array2 EXIT: MOV AH, 4CH
INT 21H
L1:
CMP CL, len CODE ENDS
JZ EXIT END START

2/5/2024 18
1. Move n bytes of data from one location
to another (using Do-While loop)…
data segment
array1 db 10h,20h,30h,40h,50h
len db $-array1
array2 db 5 dup(?)
data ends

2/5/2024 19
CODE SEGMENT INC SI
ASSUME CS:CODE,DS:DATA INC DI
START: INC CL
MOV AX,DATA CMP CL, len
MOV DS,AX JB L1

MOV CL,00
EXIT: MOV AH, 4CH
LEA SI, array1
INT 21H
LEA DI, array2

L1: CODE ENDS


MOV AL, [SI] END START
MOV [DI], AL

2/5/2024 20
2. Move n words of data from one location
to another…
data segment
array1 dw
1234h,2056h,3134h,4178h,5089h
len db $-array1
array2 dw 5 dup(?)
data ends

2/5/2024 21
CODE SEGMENT
MOV AX, [SI]
ASSUME
CS:CODE,DS:DATA MOV [DI], AX
START:
MOV AX,DATA ADD SI, 02
MOV DS,AX ADD DI, 02
INC CL
SHR len, 01 JMP L1
MOV CL,00
LEA SI, array1
EXIT: MOV AH, 4CH
LEA DI, array2
INT 21H
L1:
CMP CL, len CODE ENDS
JZ EXIT END START

2/5/2024 22
3. Linear Search (searching a byte (8bit)
value)…
data segment
arr db 10h,34h,35h,22h,45h
len db $-arr
key db 38h
succ db 10,13, "successful$"
notsucc db 10,13,"Unsuccessful$"
data ends
code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax

2/5/2024 23
MOV CL,0 FOUND: EXIT:
LEA SI, ARR LEA DX, SUCC MOV AH,4CH
MOV AH,09 INT 21H
L1: INT 21H
CMP CL, LEN JMP EXIT CODE ENDS
JZ NOTFOUND END START

MOV AL,[SI] NOTFOUND:


CMP KEY,AL LEA DX, NOTSUCC
JZ FOUND MOV AH,09
INC SI INT 21H
INC CL
JMP L1

2/5/2024 24
3. Finding maximum element in an array
data segment
arr db 10h,34h,35h,22h,45h
len db $-arr
max db ?
data ends
code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax

2/5/2024 25
MOV CL,len
Mov ch,00h EXIT:
LEA SI, ARR MOV AH,4CH
INT 21H
MOV AL,[SI]
L2: INC SI CODE ENDS
CMP AL,[SI] END START
JNC L1
MOV AL,[SI]
L1: LOOP L2
MOV MAX,AL

2/5/2024 26
1.MOV SI, 500 MOV CL, [SI]
2.MOV CH, 00 : set value of register CH to 00
3.INC SI MOV AL, [SI]
4.DEC CL : INC SI CMP AL, [SI]
5.JNC 413
6.MOV AL, [SI]
7.INC SI : increase value of SI by 1
8.LOOP
9.MOV [600], AL
2/5/2024 27
Assignment…
1. Linear Search (searching a word )…

2. Find max / min value in a byte array…

3. Add 2 arrays and store the result in the 3rd


array…

2/5/2024 28
LOOP Instruction…

• The LOOP instructions are basically conditional jump


instructions which have the format

LOOP LABEL

2/5/2024 29
• LOOP instruction combines 2 operations in each
instruction

• The first operation is to decrement the CX register by


1

• The second operation is to check the CX register and,


in some cases, also the zero flag to decide whether
to do a jump to the specified label

2/5/2024 30
LOOP Loop Until CX=0

LOOPE / LOOPZ Loop if zero flag is set


and CX !=0

LOOPNE / LOOPNZ Loop if zero flag not set


and CX !=0

JCXZ Jump if CX = 0

2/5/2024 31
Example (Linear Search)…
data segment
arr db 10h,34h,35h,22h,45h
len db $-arr
key db 38h
succ db 10,13, "successful$"
notsucc db 10,13,"Unsuccessful$"
data ends

code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
2/5/2024 32
MOV CL, len SUCC1:
MOV CH,0
MOV DX, OFFSET succ
LEA SI, arr
; SAME AS LEA DX, succ
UP:
MOV AL,[SI] MOV AH,09H
CMP key, AL INT 21H
JZ SUCC1
INC SI EXIT:
LOOP UP MOV AH,4CH
INT 21H
LEA DX, notsucc CODE ENDS
MOV AH,09H END START
INT 21H
JMP EXIT

2/5/2024 33
Shift/Rotate Instructions…

2/5/2024 34
Examples (Counting number of 1’s and check
parity)…

DATA SEGMENT
A DB 0A2H
emsg db 10, 13, 'EVEN PARITY$'
omsg db 10, 13, 'ODD PARITY$'
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX

2/5/2024 35
MOV CH, 00H CHECKP:
; COUNTER FOR NO OF 1S SHR CH, 01H
JNC EVENP
MOV CL, 00H LEA DX, omsg
; COUNTER FOR LOOP MOV AH, 09H
INT 21H
UP: JMP EXIT
CMP CL, 08H EVENP:
JZ CHECKP LEA DX, emsg
ROL A, 01H MOV AH, 09H
JNC L1 INT 21H
INC CH EXIT:
L1: MOV AH, 4CH
INC CL INT 21H
JMP UP CODE ENDS
END START

2/5/2024 36
Assignment…
Check if given number is odd or even
(using SHR/SAR instruction)…

2/5/2024 37
Logical Instructions…

2/5/2024 38
Thank You…

2/5/2024 39

You might also like