Professional Documents
Culture Documents
Mi Lab 4 9
Mi Lab 4 9
LABORATORY 4
OBJECTIVE
PRELAB
Read data transfer instructions and segment registers from textbook in detail.
REG memory,
● Set the value of the CS and IP registers.
immediate ● Copy value of one segment register to
another segment register (should copy
to general register first).
REG, immediate
● Copy immediate value to segment
SREG, memory register (should copy to general register
first).
memory, SREG
Algorithm: operand1 = operand2
REG, SREG
Ex:
SREG, REG
Mov AX,BX ;Copy contents of BX to
● SP = SP - 2
● SS:[SP] (top of the stack) = operand
IU2041050070_NISH MEHTA
SREG memory SP = Sp + 2.
REG, REG
im.byte
AX, DX
OUT Output from AL or AX to port.
AL, ibyte First operand is a port number. If required to access
port number over 255 - DX register should be used.
AL, DX
AX, DX
LEA REG, memory
Load Effective Address.
Algorithm:
EXERCISES
IU2041050070_NISH MEHTA
4.1 An ALP to transfer a given block of data from source memory block to the destination
memory block without overlap.
DATA SEGMENT
S1 DW 2006H,1215H, 4115H,5116H,6241H,4125H,3218H,3215H,3215H,3651H
D1 DW 10 DUP(25H)
COUNT DB 10
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX,DATA
MOV DS,AX
LEA SI,S1
LEA DI,D1
MOV CL,COUNT
L1: MOV AX,[SI]
MOV [DI],AX
INC SI
INC SI
INC DI
INC DI
DEC CL
JNZ L1
INT 21H CODE
ENDS
END START
4.2 An ALP to exchange a block of data located from source to the destination memory
locations.
DATA SEGMENT
S1 DW 2006H,1215H, 4115H,5116H,6241H,4125H,3218H,3215H,3215H,3651H
D1 DW 1001H,1002H,1003H,1004H,1005H,1006H,1007H,1008H,1009H,1010H
COUNT DB 10
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX,DATA
MOV DS,AX
LEA SI,S1
LEA DI,D1
MOV CL,COUNT
IU2041050070_NISH MEHTA
INC DI
INC DI
DEC CL
JNZ L1
LABORATORY 5
OBJECTIVE
To learn to sort the given data into ascending & descending order.
PRELAB
Read instructions related to Branch and Subroutine Call.
JA Label Jump If Above. Short Jump if first operand is Above second operand
(as set by CMP instruction). Unsigned.
JAE Label Jump If Above Or Equal Short Jump if first operand is Above or Equal
to second operand (as set by CMP instruction). Unsigned.
Algorithm: if CF = 0 then jump
JBE Label Jump If Below Or Equal Short Jump if first operand is Below second
operand (as set by CMP instruction). Unsigned.
JE Label Jump If Equal. Short Jump if first operand is Equal to second operand
(as set by CMP instruction). Signed/Unsigned.
JG Label Jump If Greater Short Jump if first operand is Greater then second
operand (as set by CMP instruction). Signed.
JGE Label Jump If Greater Or Equal. Short Jump if first operand is Greater or
Equal to second operand (as set by CMP instruction). Signed.
JL Label Jump If Less than. Short Jump if first operand is Less then second
operand (as set by CMP instruction). Signed.
JLE Label Jump If Less Or Equal. Short Jump if first operand is Less or Equal to
second operand (as set by CMP instruction). Signed.
JNZ Label Jump If Non Zero. Short Jump if Not Zero (not equal). Set by CMP,
SUB, ADD, TEST, AND, OR, XOR instructions.
JZ Label Jump If Zero. Short Jump if Zero (equal). Set by CMP, SUB, ADD, TEST,
AND, OR, XOR instructions.
Algorithm: if ZF = 1 then jump
EXERCISES
5.1 Write an ALP to find the largest number from an array.
IU2041050070_NISH MEHTA
DATA SEGMENT
NUM DB 06H,05H,0FEH,32H,49H,36H
COUNT DB 5
LARGE DB 0 DATA
ENDS
JNZ BACK
MOV SMALL,AL
INT 03H
CODE ENDS
END START
5.3 Write an ALP to sort the given array of numbers in ascending order.
DATA SEGMENT
NUM DB 06H,05H,0FEH,32H,49H,36H,0FDH,0AFH,01H,00H
COUNT DB 9 DATA
ENDS
CODE SEGMENT
ASSUME CS:CODE ,DS:DATA
START: MOV AX,DATA MOV DS,AX
MOV CL,COUNT
MOV AH,CL
RPT: MOV BL,AH LEA SI,NUM
BACK: MOV AL,[SI] CMP
AL,[SI+1]
JC XYZ
XCHG AL,[SI+1]
MOV [SI],AL
XYZ: INC SI
DEC BL JNZ
BACK
DEC CL
JNZ RPT
INT 21H
CODE ENDS
END START
5.4 Write an ALP to sort the given array of numbers in descending order.
DATA SEGMENT
NUM DB 06H,05H,0FEH,32H,49H,36H,0FDH,0AFH,01H,00H
COUNT DB 9 DATA
ENDS
CODE SEGMENT
ASSUME CS:CODE ,DS:DATA
IU2041050070_NISH MEHTA
INT 21H
CODE ENDS
END START
IU2041050070_NISH MEHTA
LABORATORY 6
OBJECTIVE
To familiar with bit manipulation methods.
PRELAB
Read Instructions related to Logical and shift the operands.
● Shift all bits left, the bit that goes off is set to
Algorithm:
● Shift all bits right, the bit that goes off is set to CF.
● Zero bit is inserted to the left-most position.
ROL ▪ memory, immediate Rotate Left.
▪ REG, immediate
▪ Rotate operand1 left. The number of rotates is set by
memory, CL
operand2.
▪ REG, CL
Algorithm:
Shift all bits left, the bit that goes off is set to
CF and the same bit is inserted to the right-
most position.
RCL ▪ memory, immediate Rotate operand1 left through Carry Flag. The number of
▪ rotates is set by operand2.
REG, immediate
▪ memory, CL Algorithm:
▪ REG, CL
Shift all bits left, the bit that goes off is set to
CF and previous value of CF is inserted to the
right- most position.
Example:
STC ; set carry (CF=1).
MOV AL, 1Ch ; AL = 00011100b
RET
OF=0 if first and keeps original sign.
ope
ROR ▪ memory, Rotate Right.
▪ immediate REG,
▪ immediate Rotate operand1 right. The number of rotates is set by
operand2.
▪ memory, CL
REG, CL
Algorithm:
Shift all bits right, the bit that goes off is set to
CF and the same bit is inserted to the left-most
position.
EXERCISES
6.1 Bit manipulation to check if the data is positive or negative.
DATA SEGMENT NUM DB 72H ;
1000 0010
MES1 DB 'DATA IS POSITIVE $'
MES2 DB 'DATA IS NEGATIVE $'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AL,NUM
ROL AL,1 JC
NEGA
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AL,X
TEST AL,01H
JNZ EXIT
LEA DX,MSG1 MOV
AH,09H
INT 21H
JMP LAST
6.3 Bit manipulation to count the number of 1’s and 0’s in given data.
DATA SEGMENT X
DB 0AAH ONE DB
?
ZERO DB ? DATA
ENDS
CODE SEGMENT ASSUME CS:
CODE,DS:DATA
START: MOV
AX,DATA
MOV DS,AX
MOV AH,X
MOV BL,8 ;Initialize BL to
8. MOV CL,1 ;Initialize CL to 1.
UP: ROR AH,CL ;Perform the single bit rotate operation ;with
respect to right.
JNC DOWN ;If no carry go to DOWN label.
INC ONE ;Increment one.
JMP DOWN1 ;Jump to DOWN1.
DOWN: INC ZERO ;Increment ZERO.
IU2041050070_NISH MEHTA
LABORATORY 7
OBJECTIVE
To learn the different operations on the string.
PRELAB
Read Data Transfer and String related instructions.
EXERCISES
7.1 Write an ALP to transfer a string from one location to other.
STR1 DB 'INDUS UNIVERSITY'
LEN EQU $-STR1
FIND EQU 'Z'
MSG1 DB 'CHARACTER FOUND$'
MSG2 DB 'CHARACTER NOT FOUND$' DATA
ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV ES,AX
MOV AL,FIND
MOV CL,LEN
LEA SI,STR1
CLD
UP: SCASB JZ
DOWN
LOOP UP
LEA DX,MSG2 MOV
AH,09H
INT 21H
JMP EXIT
DOWN: LEA DX,MSG1
IU2041050070_NISH MEHTA
MOV AH,09H
INT 21H
EXIT: MOV AH,4CH INT
21H
CODE ENDS END
START
MOV ES,AX
MOV AL,FIND
MOV CL,LEN
LEA SI,STR1
CLD
UP: SCASB JZ
DOWN
LOOP UP
LEA DX,MSG2 MOV
AH,09H
INT 21H
JMP EXIT
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA
START: MOV AX,DATA MOV
DS,AX
MOV ES,AX LEA
SI,STR1
LEA DI,STR2+LEN-1
MOV CX,LEN
UP: CLD
LODSB
IU2041050070_NISH MEHTA
STD
STOSB
LOOP UP LEA
SI,STR1 LEA
DI,STR2
MOV CL,LEN
BACK: MOV AL,
[SI] CMP
AL,[DI]
JNZ
NOT_PAL
INC SI
INC DI
DEC CL
JNZ BACK
PAL: LEA DX, MSG1 ; DISPLAY PALINDROME
MOV AH, 09H
INT 21H
JMP EXIT
LABORATORY 8
OBJECTIVE
To familiar with the use of arithmetic and logical instruction set of 8086
PRELAB
Read the instructions related to arithmetic and logical operations in detail.
● AL = AL + 6 ● AF = 1
● AL = AL + 60h
● CF = 1
● AL = AL - 6
● AF = 1
● AL = AL - 60h
● CF = 1
IU2041050070_NISH MEHTA
● AL = AL + 6
● AH = AH + 1
● AF = 1
● CF = 1
else
● AF = 0
● CF = 0
● AL = AL - 6
● AH = AH - 1
● AF = 1
● CF = 1
else
● AF = 0
● CF = 0
● AH = AL / 10
● AL = remainder
EXERCISES
8.1 An ALP for 32 bit Addition and Subtraction
32 bit addition org
100h MOV
AX,1111H
MOV BX,1111H
MOV CX,9999H
MOV DX,9999H
ADC AX,CX ADC
BX,DX Ret
MOV AX,1010H
MOV BX,1010H
MOV CX,0909H
IU2041050070_NISH MEHTA
MOV DX,0909H
SUB AX,CX SUB
BX,DX
Ret
CODE SEGMENT
ASSUME CS:CODE
START: MOV AX,0901H
SUB AL,09H
AAS ; GIVE AX = 0802H
MOV AH,0
MOV AL,6
ADD AL,5
AAA; AH = 1 and AL = 1 , represents BCD 11
MOV AH,4CH
INT 21H
CODE ENDS END
START
LABORATORY 9
OBJECTIVE
To learn DOS Interrupt commands.
PRELAB
Read Interrupts.
Function 01h - Read character from standard input, result is stored in AL. If there is no character in
the keyboard buffer, the function waits until any key is pressed.
Example:
INT 21h
AH =02h After
execution AL = DL.
Example:
Function 06h – Direct console for input/output. If DL = 0FFH on entry, then this function reads the
console. If DL = ASCII character, then this function displays the ASCII character on the console
video screen.
Example:
Mov AH,
String must be terminated by '$'. The string can be of any length and may contain control characters
such as carriage return (0DH) and line feed (0AH).
AH = 09h
Example:
displayed INT21h
Example:
Example:
INT 10h calls the BIOS functions. This interrupt often called the video services interrupt as it directly
controls the video display in a system.
Example:
MOV BH, 00
MOV DH, 06
MOV DL, 10
cursor position.
AH = 03h
Example:
Mov BH, 0
IU2041050070_NISH MEHTA
INT 10h
Invoked by: AL = number of lines by which to scroll. (00h = clear the entire screen.)
EXERCISES