Experiment No. -2.1: Write an ALP to move block of data without overlap.
Aim: To Write an ALP to Move a Block of Data without Overlap
Software Required: Masm 16 Bit
Algorithm:
1. Define block of data
2. Save memory for block transfer as block2
3. Load block1 into SI
4. Load block2 into DI
5. Initialize counter
6. Move first data into DI
7. Repeat step 6 until counter is zero
8. End
Program:
.model small
.stack 100h
.data
source db 10, 20, 30, 40, 50, 60,70,80,90,100 ; Source data
destination db 10 dup(?) ; Destination data, initialized with 10 bytes
.code
main proc
mov ax, @data ; Load data segment address
mov ds, ax
mov si, offset source ; Source index
mov di, offset destination ; Destination index
mov cx, 10 ; Number of bytes to copy
copy_loop:
mov al, [si] ; Load byte from source
mov [di], al ; Store byte to destination
inc si ; Move to next byte in source
inc di ; Move to next byte in destination
loop copy_loop ; Repeat until cx becomes zero
mov ax, 4C00h ; Exit program
int 21h
main endp
end main
Description:
In this code:
• We define two arrays, source and destination, with 5 bytes each.
• We load the address of the data segment into ds.
• We use si and di registers to point to the source and destination data respectively.
• We use cx register to keep track of the number of bytes to copy.
• The copy_loop copies bytes from the source to the destination until cx becomes zero.
• Finally, we exit the program.
Compile and run this code in emu8086, and you should see that the destination array now
contains the same data as the source array.
Input and Output:
Pre Viva Questions:
1. List all the modern microprocessor
2. Name some 16 bit Processor (8086, 80286, 80386L, EX)
3. Name some 32 bit processors (80386DX, 80486, PENTIUM OVERDRIVE)
4. Name some 64 bit processor (Pentium, Pentium pro, Pentium II, Xeon, Pentium III, and
Pentium IV)
5. List the address bus width and the memory size of all the processor
Experiment No. -2.2: Write an ALP to move block of data with overlap
Aim: To Write an ALP To Move Block Of Data With Overlap.
Software Required: Masm 16 Bit
Algorithm:
1. Define block of data
2. Reserve memory for block transfer as block2
3. Move block1 address to SI
4. Move block2 address to DI
5. Initialize counter
6. Point DI to block+ n
7. Move block1 data to block2
8. Repeat step 7 until counter is zero
9. End
Program:
.MODEL SMALL
.DATA
BLK1 DB 01,02,03,04,05,06,07,08,09,0AH
BLK2 DB 10 DUP (?)
.CODE
MOV AX, @DATA ; MOV THE STARTING ADDRESS
MOV DS, AX
MOV ES, AX
MOV SI, OFFSET BLK1 ; SET POINTER REG TO BLK1
MOV DI, OFFSET BLK2 ; SET POINTER REG TO BLK2
MOV CX, 0AH ; SET COUNTER
ADD SI, 0009H
ADD DI, 0004H
AGAIN:
MOV AL, [SI]
MOV [DI], AL
DEC SI
DEC DI
DEC CL ; DECREMENT COUNTER
JNZ AGAIN ; TO END PROGRAM
MOV AH, 4CH
INT 21H
END
Description:
1. .MODEL SMALL: This directive specifies the memory model for the program,
indicating that it will be using a small memory model, which means the program code,
data, and stack will all fit within a single 64 KB segment.
2. .DATA: This section declares the data used in the program.
• BLK1 DB 01,02,03,04,05,06,07,08,09,0AH: This declares an array named BLK1
containing ten bytes with the hexadecimal values 01, 02, 03, ..., 09, 0A.
• BLK2 DB 10 DUP (?): This declares an array named BLK2 containing ten bytes
initialized with unknown values (denoted by '?').
3. .CODE: This section contains the actual executable code of the program.
• MOV AX, @DATA: Loads the offset address of the DATA segment into the AX
register.
• MOV DS, AX: Moves the content of AX into the Data Segment (DS) register,
setting DS to point to the beginning of the data segment.
• MOV ES, AX: Moves the content of AX into the Extra Segment (ES) register,
setting ES to point to the beginning of the data segment. This is often done when
data will be copied between segments.
• MOV SI, OFFSET BLK1: Loads the offset address of the BLK1 array into the
Source Index (SI) register.
• MOV DI, OFFSET BLK2: Loads the offset address of the BLK2 array into the
Destination Index (DI) register.
• MOV CX, 0AH: Initializes the CX register (the counter register) with the value
0A (10 in decimal), representing the length of the arrays.
• ADD SI, 0009H: Adjusts the source index SI to point to the last element of BLK1
(since arrays are 0-indexed, we add 9 to offset).
• ADD DI, 0004H: Adjusts the destination index DI to point to the fifth element of
BLK2 (similarly, 4 for 0-indexing).
• AGAIN: This is a label indicating the start of a loop.
• MOV AL, [SI]: Moves the byte pointed to by SI into the AL register.
• MOV [DI], AL: Moves the content of AL into the memory location pointed to by
DI.
• DEC SI: Decrements SI to move to the previous element in BLK1.
• DEC DI: Decrements DI to move to the previous element in BLK2.
• DEC CL: Decrements the CX register (the loop counter).
• JNZ AGAIN: Jumps back to the label AGAIN if the zero flag is not set (i.e., if
the loop counter CX is not zero).
• MOV AH, 4CH: Sets the AH register to 4C, which is the DOS function number
for "terminate with return code".
• INT 21H: Generates a software interrupt to call DOS function 21H, which
terminates the program.
• END: Marks the end of the program.
Input & Output:
Pre Viva-Questions:
1. Name the registers in EU.( AX, BX, CX, DX, SP, BP, SI, DI)
2. Name the flag registers in 8086. (O, D, I, T, S, Z, A, P, C)
3. How is the real memory segmented?
4. What is the advantage of segmentation?
5. Name the default segment and offset register combinations.
6. What is the relocatable program.
7. Name the three main addressing modes in 8086.
8. Name the data addressing modes. And the program addressing modes. Give examples
9. Explain MOV AL, „A‟, MOV AX, NUMBER, MOV [BP], DL, MOV CH,[1000],
MOV[BX+SI],SP, MOV ARRAY[SI],BL, MOV DH,[BX+DI+10H]
Experiment No. -2.3: Program to interchange a block of data
Aim: To Program to Interchange a Block of Data.
Software Required: Masm 16 Bit
Algorithm:
1. Define two sets of data.
2. Load address of src to SI
3. Load address of dst to DI
4. Initialize counter
5. Interchange data in src and dst
6. Repeat step 5 until counter = 0.
7. End
Program:
.MODEL SMALL
.DATA
SRC DB 10H,20H,30H,40H,50h
DST DB 06,07,08,09,0AH
COUNT EQU 05H
.CODE
MOV AX, @DATA ; INITIALIZE THE DATA REGISTER
MOV DS, AX
LEA SI, SRC
LEA DI, DST
MOV CL, COUNT ; INITIALIZE THE COUNTER
BACK:
MOV AL, [SI]
MOV BL, [DI]
MOV [SI], BL ; INTERCHANGE THE DATA
MOV [DI], AL
INC SI
INC DI
DEC CL
JNZ BACK ; REPEAT UNTIL COUNTER BECOMES ZERO
MOV AH, 4CH
INT 21H
END
Description:
1. .MODEL SMALL: This directive specifies the memory model for the program as small.
2. .DATA: This section declares the data used in the program.
• SRC DB 10H,20H,30H,40H,50h: Declares an array named SRC containing five
bytes with the hexadecimal values 10H, 20H, 30H, 40H, and 50H.
• DST DB 06,07,08,09,0AH: Declares an array named DST containing five bytes
with the hexadecimal values 06, 07, 08, 09, and 0A.
• COUNT EQU 05H: Defines a constant named COUNT with the value 05H,
representing the number of elements in the arrays.
3. .CODE: This section contains the actual executable code of the program.
• MOV AX, @DATA: Loads the offset address of the DATA segment into the AX
register.
• MOV DS, AX: Moves the content of AX into the Data Segment (DS) register,
setting DS to point to the beginning of the data segment.
• LEA SI, SRC: Loads the effective address (offset) of the SRC array into the
Source Index (SI) register.
• LEA DI, DST: Loads the effective address (offset) of the DST array into the
Destination Index (DI) register.
• MOV CL, COUNT: Initializes the CL register (the loop counter) with the value
of COUNT, which represents the number of elements in the arrays.
• BACK: This is a label indicating the start of a loop.
• MOV AL, [SI]: Moves the byte pointed to by SI (from the SRC array) into the
AL register.
• MOV BL, [DI]: Moves the byte pointed to by DI (from the DST array) into the
BL register.
• MOV [SI], BL: Moves the content of BL (from the DST array) into the memory
location pointed to by SI (in the SRC array), effectively swapping the values.
• MOV [DI], AL: Moves the content of AL (from the SRC array) into the memory
location pointed to by DI (in the DST array), completing the swap operation.
• INC SI: Increments SI to move to the next element in the SRC array.
• INC DI: Increments DI to move to the next element in the DST array.
• DEC CL: Decrements the CL register (the loop counter) to keep track of the
number of swaps performed.
• JNZ BACK: Jumps back to the label BACK if the zero flag is not set (i.e., if the
loop counter CL is not zero), continuing the swap operation until all elements
have been swapped.
• MOV AH, 4CH: Sets the AH register to 4C, which is the DOS function number
for "terminate with return code".
• INT 21H: Generates a software interrupt to call DOS function 21H, which
terminates the program.
• END: Marks the end of the program.
Input & Output:
Pre Viva-Questions:
1. Name the programme memory addressing modes. (Direct, relative, indirect)
2. What is an intersegment and intrasegment jump?
3. Differentiate near and short jumps (+_32k and +127to_128 bytes)
4. Differentiate near and far jumps.
5. Differentiate push and pop instructions.
6. Explain PUSH word ptr [BX], POP F.
7. JMP TABLE[BX]
0 Comments