AP Lab Manual Sem 5
Transcript of AP Lab Manual Sem 5
-
8/2/2019 AP Lab Manual Sem 5
1/37
1
SVBIT 5th
SEM CE [AP]
AIM: Write a program to add two 8-bit numbers.
Program:
.model small
.data
a db 09H
b db 02H
.code
mov ax, @data
mov ds, ax
mov al, a
mov bl, b
add al, bl
mov ah, 4CH
int 21H
end
Output:
-
8/2/2019 AP Lab Manual Sem 5
2/37
2
SVBIT 5th
SEM CE [AP]
AIM: Write a program to subtract two 8-bit numbers.
Program:
.model small
.data
a db 0AH
b db 04H
.code
mov ax, @data
mov ds, ax
mov al, a
mov bl, b
sub al, bl
mov ah, 4CH
int 21H
end
Output:
-
8/2/2019 AP Lab Manual Sem 5
3/37
3
SVBIT 5th
SEM CE [AP]
AIM: Write a program to multiply two 8-bit numbers.
Program:
.model small
.data
a db 09H
b db 02H
.code
mov ax, @data
mov ds, ax
mov ah, 0
mov al, a
mov bl, b
mul bl
mov ah, 4CH
int 21Hend
Output:
-
8/2/2019 AP Lab Manual Sem 5
4/37
4
SVBIT 5th
SEM CE [AP]
AIM: Write a program to Add 8-bit BCD numbers.
Program:
.model small
.data
a db 09H
b db 02H
.code
mov ax, @data
mov ds, ax
mov al, a
mov bl, b
add al, bl
daa
mov ah, 4cHint 21H
end
Output:
-
8/2/2019 AP Lab Manual Sem 5
5/37
5
SVBIT 5th
SEM CE [AP]
AIM: Write a program to subtract 8-bit BCD numbers.
Program:
.model small
.data
a db 32H
b db 17H
.code
mov ax, @data
mov ds, ax
mov al, a
mov bl, b
sub al, bl
das
mov ah, 4cHint 21H
end
Output:
-
8/2/2019 AP Lab Manual Sem 5
6/37
6
SVBIT 5th
SEM CE [AP]
AIM: Write a program to divide 16 bit numbers by an 8 bit
numbers.
Program:
.model small
.data
a dw 000FH
b db 08H
.code
mov ax, @data
mov ds, ax
mov ax, a
mov bl, b
div bl
mov ah, 4cH
int 21H
end
Output:
-
8/2/2019 AP Lab Manual Sem 5
7/37
7
SVBIT 5th
SEM CE [AP]
AIM: Write a program to Add two 16-bit numbers.
Program:
.model small
.data
a dw 1234H
b dw 0100H
.code
mov ax, @data
mov ds, ax
mov ax, a
mov bx, b
add ax, bx
mov dx, ax
mov ah, 4cHint 21H
end
Output:
-
8/2/2019 AP Lab Manual Sem 5
8/37
8
SVBIT 5th
SEM CE [AP]
AIM: Write a program to subtract two 16-bit numbers.
Program:
.model small
.data
a dw 1234H
b dw 0100H
.code
mov ax, @data
mov ds, ax
mov ax, a
mov bx, b
sub ax, bx
mov dx, ax
mov ah, 4cHint 21H
end
Output:
-
8/2/2019 AP Lab Manual Sem 5
9/37
9
SVBIT 5th
SEM CE [AP]
AIM: Write a program to print HELLO!.
Program:
ORG 100h
MOV AH, 0EhMOV AL, 'H'INT 10hMOV AL, 'e'INT 10hMOV AL, 'l'INT 10hMOV AL, 'l'INT 10h
MOV AL, 'o'INT 10hMOV AL, '!'INT 10hRETOutput:
-
8/2/2019 AP Lab Manual Sem 5
10/37
10
SVBIT 5th
SEM CE [AP]
AIM: Write a Program to Display String using procedure.
Program:
.MODEL SMALL
.DATASTRING db 'Study of Microprocessor is Interesting $'
.CODEMOV AX,@DATAMOV DS,AX
CALL DISP
MOV AH,4CH
INT 21H
DISP PROC NEARMOV AH,09HLEA DX,STRINGINT 21H
ENDPRET
END
Output:
-
8/2/2019 AP Lab Manual Sem 5
11/37
11
SVBIT 5th
SEM CE [AP]
AIM: Write a Program to accept input from keyboard and display
it.
Program:
.MODEL SMALL
.STACK 100H
.DATA
.CODEMOV AX,@DATAMOV DS,AX
UP: MOV AH,01H ; Get input from keyboardINT 21H
CMP AL,30H ; If 0 is entered End programJE ENDDJMP UP
ENDD:MOV AH,4CH ; Terminate ProgramINT 21HEND
Output:
`
-
8/2/2019 AP Lab Manual Sem 5
12/37
12
SVBIT 5th
SEM CE [AP]
AIM: Write a Program for 32bit addition
Program:
.model small
.data
op1 dd 12345678h
op2 dd 11111111h
ans dd ?
.code
mov ax,@data
mov ds,ax
mov ax,word ptr op1 ; lsb of number1 in ax
mov bx,word ptr op1+2 ; msb of number1 in bxmov cx,word ptr op2 ; lsb of number2 in cx
mov dx,word ptr op2+2 ; msb of number1 in dx
add ax,cx ; add lsb + lsb
adc bx,dx ; add msb + msb + carry
mov word ptr ans,ax ; lsb answer
mov word ptr ans+2,bx ; msb answer
mov bx,word ptr ans+2 ; Result in reg bxmov dh,2
l1: mov ch,04h ; Count of digits to be displayed
mov cl,04h ; Count to roll by 4 bits
l2: rol bx,cl ; roll bl so that msb comes to lsb
mov dl,bl ; load dl with data to be displayed
and dl,0fH ; get only lsb
cmp dl,09 ; check if digit is 0-9 or letter A-Fjbe l4
add dl,07 ; if letter add 37H else only add 30H
l4: add dl,30H
mov ah,02 ; INT 21H (Display character)
int 21H
-
8/2/2019 AP Lab Manual Sem 5
13/37
13
SVBIT 5th
SEM CE [AP]
dec ch ; Decrement Count
jnz l2
dec dh
cmp dh,0mov bx,word ptr ans ; display lsb of answer
jnz l1
mov ah,4ch ; Terminate Program
int 21h
end
OR.model small
.data
op1 dd 12345678h
op2 dd 11111111h
.code
mov ax,@data
mov ds,ax
mov ax,word ptr op1 ; lsb of number1 in axmov bx,word ptr op1+2 ; msb of number1 in bx
mov cx,word ptr op2 ; lsb of number2 in cx
mov dx,word ptr op2+2 ; msb of number1 in dx
add ax,cx ; add lsb + lsb
mov cx,ax
adc bx,dx ; add msb + msb + carry
mov ah,4ch ; Terminate Program
int 21h
end
-
8/2/2019 AP Lab Manual Sem 5
14/37
14
SVBIT 5th
SEM CE [AP]
Output:
OR
Output:
-
8/2/2019 AP Lab Manual Sem 5
15/37
15
SVBIT 5th
SEM CE [AP]
AIM: Write a Program for 32bit subtraction
Program:
.model small
.data
op1 dd 12345678h
op2 dd 11111111h
ans dd ?
.code
mov ax,@data
mov ds,ax
mov ax,word ptr op1 ; lsb of number1 in ax
mov bx,word ptr op1+2 ; msb of number1 in bx
mov cx,word ptr op2 ; lsb of number2 in cx
mov dx,word ptr op2+2 ; msb of number1 in dx
sub ax,cx ; add lsb + lsb
sbb bx,dx ; add msb + msb + carry
mov word ptr ans,ax ; lsb answer
mov word ptr ans+2,bx ; msb answer
mov bx,word ptr ans+2 ; Result in reg bx
mov dh,2
l1: mov ch,04h ; Count of digits to be displayed
mov cl,04h ; Count to roll by 4 bits
l2: rol bx,cl ; roll bl so that msb comes to lsbmov dl,bl ; load dl with data to be displayed
and dl,0fH ; get only lsb
cmp dl,09 ; check if digit is 0-9 or letter A-F
jbe l4
-
8/2/2019 AP Lab Manual Sem 5
16/37
16
SVBIT 5th
SEM CE [AP]
add dl,07 ; if letter add 37H else only add 30H
l4: add dl,30H
mov ah,02 ; INT 21H (Display character)
int 21Hdec ch ; Decrement Count
jnz l2
dec dh
cmp dh,0
mov bx,word ptr ans ; display lsb of answer
jnz l1
mov ah,4ch ; Terminate Program
int 21h
end
OR.model small
.data
op1 dd 12345678h
op2 dd 11111111h
.code
mov ax,@data
mov ds,ax
mov ax,word ptr op1 ; lsb of number1 in ax
mov bx,word ptr op1+2 ; msb of number1 in bx
mov cx,word ptr op2 ; lsb of number2 in cx
mov dx,word ptr op2+2 ; msb of number1 in dx
sub ax,cx ; add lsb + lsb
mov cx,ax
sbb bx,dx ; add msb + msb + carry
-
8/2/2019 AP Lab Manual Sem 5
17/37
17
SVBIT 5th
SEM CE [AP]
mov ah,4ch ; Terminate Program
int 21h
end
Output:
OR
Output:
-
8/2/2019 AP Lab Manual Sem 5
18/37
18
SVBIT 5th
SEM CE [AP]
AIM: Write a Program for counting the number of 1's in a number.
Program:
.model small
.dataa dw 5267H
.code
mov ax,@data ; Initialize data section
mov ds,ax
mov ax,a ; Load number in ax
mov bx,0 ; clear bx for counting number of 1in a given number.
mov cx,16 ; load count in cx registerback: rcr ax,1 ; rotate by 1 bit to the right
jnc l1 ; if bit is 0 goto next bit
inc bl ; if bit=1 increment count
l1: dec cx ; decrement counter
jnz back
mov ah,4cH ; Terminate Program
int 21Hend
Output:
-
8/2/2019 AP Lab Manual Sem 5
19/37
19
SVBIT 5th
SEM CE [AP]
AIM: Write a Program to find the factorial of a number.
Program:
.model small
.datanum dw 05h
.code
mov ax, @data
mov ds, ax
mov ax, 01
mov bx, num
call fact
mov dx,ax ; result save in dx
mov ah, 4ch
int 21h
fact proc near
cmp bx, 01
jz l11l12: mul bx
dec bx
cmp bx, 01
jne l12
ret
l11: ret
fact endp
end
Output:
-
8/2/2019 AP Lab Manual Sem 5
20/37
20
SVBIT 5th
SEM CE [AP]
AIM: Write a Program to sorting the numbers in ascending order.
Program:
.MODEL SMALL
.STACK 100
.DATA
NUM DW 0102H,0154H,0070H,0005H
.CODE
MOV AX,@DATA ; Initialise data segment
MOV DS,AX
MOV DX,2 ; DX has location where n0 is to be placed
LOOP2: MOV CX,DXDEC CX ; CX number of comparisons required
MOV SI,CX
add SI,si ; si*2 as word ptr
MOV AX,NUM[SI] ; Get the number
LOOP1:CMP NUM[SI-2],AX ; Compare it with previous number
JBE NEXT ; if prev num
-
8/2/2019 AP Lab Manual Sem 5
21/37
21
SVBIT 5th
SEM CE [AP]
l2: rol bx,cl ; roll bl so that msb comes to lsb
mov dl,bl ; load dl with data to be displayed
and dl,0fH ; get only lsb
cmp dl,09 ; check if digit is 0-9 or letter A-Fjbe l4
add dl,07 ; if letter add 37H else only add 30H
l4: add dl,30H
mov ah,02 ; Function 2 under INT 21H (Display character)
int 21H
dec ch ; Decrement Count
jnz l2
mov ah,02
mov dl,' ' ; Display space between 2 numbers
int 21h
inc si ; incr si twice as word ptr
inc si
dec dh
cmp dh,0
jnz l1
mov ah,4cH ; Terminate Program
int 21H
END
OR.MODEL SMALL
.STACK 100
.DATA
NUM DW 0102H,0154H,0070H,0005H
.CODE
MOV AX,@DATA ; Initialise data segment
MOV DS,AX
-
8/2/2019 AP Lab Manual Sem 5
22/37
22
SVBIT 5th
SEM CE [AP]
MOV DX,2 ; DX has location where n0 is to be placed
LOOP2: MOV CX,DX
DEC CX ; CX number of comparisons required
MOV SI,CXadd SI,si ; si*2 as word ptr
MOV AX,NUM[SI] ; Get the number
LOOP1: CMP NUM[SI-2],AX ; Compare it with previous number
JBE NEXT ; if prev num
-
8/2/2019 AP Lab Manual Sem 5
23/37
23
SVBIT 5th
SEM CE [AP]
OR
Output:
-
8/2/2019 AP Lab Manual Sem 5
24/37
24
SVBIT 5th
SEM CE [AP]
AIM: Write a Program to sorting the numbers in descending order.
Program:
.MODEL SMALL
.STACK 100.DATANUM DW 0102H,0154H,0070H,0005H
.CODEMOV AX,@DATA ; Initialise data segmentMOV DS,AX
MOV DX,2 ; DX has location where n0 is to be placedLOOP2:MOV CX,DX
DEC CX ; CX number of comparisons required
MOV SI,CXadd SI,si ; si*2 as word ptrMOV AX,NUM[SI] ; Get the number
LOOP1: CMP NUM[SI-2],AX ; Compare it with previous numberJAE NEXT ; if prev num >= this num goto nextMOV DI,NUM[SI-2] ; elseMOV NUM[SI],DI ; insert in new posnDEC SI ; decrement siDEC SI
DEC CX ; Decrement comparison counterJNZ LOOP1 ; If not zero, repeatNEXT: MOV NUM[SI],AX ; Insert the number in proper position
INC DX ; Next number to be insertedCMP DX,4 ; Check if all numbers are insertedJBE LOOP2 ; If not continue
mov ah,4cH ; Terminate Program
int 21HEND
OR
.MODEL SMALL
.STACK 100
-
8/2/2019 AP Lab Manual Sem 5
25/37
25
SVBIT 5th
SEM CE [AP]
.DATANUM DW 0102H,0154H,0070H,0005H
.CODEMOV AX,@DATA ; Initialise data segmentMOV DS,AX
MOV DX,2 ; DX has location where num is to be insertedLOOP2: MOV CX,DX
DEC CX ; CX number of comparisons requiredMOV SI,CXadd SI,si ; si*2 as word ptrMOV AX,NUM[SI] ; Get the number
LOOP1:CMP NUM[SI-2],AX ; Compare it with previous numberJAE NEXT ; if prev num >= this num goto next
MOV DI,NUM[SI-2] ; elseMOV NUM[SI],DI ; insert in new posnDEC SI ; decrement siDEC SIDEC CX ; Decrement comparison counterJNZ LOOP1 ; If not zero, repeat
NEXT: MOV NUM[SI],AX ; Insert the number in proper positionINC DX ; Next number to be insertedCMP DX,4 ; Check if all numbers are insertedJBE LOOP2 ; If not continue
mov si,offset nummov dh,4
l1: mov ch,04h ; Count of digits to be displayedmov cl,04h ; Count to roll by 4 bitsmov bx,[si] ; Result in reg bx
l2: rol bx,cl ; roll bl so that msb comes to lsbmov dl,bl ; load dl with data to be displayed
and dl,0fH ; get only lsbcmp dl,09 ; check if digit is 0-9 or letter A-F
jbe l4add dl,07 ; if letter add 37H else only add 30H
l4: add dl,30Hmov ah,02 ; Function 2 under INT 21H (Display character)int 21H
-
8/2/2019 AP Lab Manual Sem 5
26/37
26
SVBIT 5th
SEM CE [AP]
dec ch ; Decrement Countjnz l2
mov ah,02mov dl,' ' ; Display space between 2 numbersint 21hinc si ; incr si twice as word ptrinc sidec dhcmp dh,0
jnz l1
mov ah,4cH ; Terminate Programint 21H
ENDOutput:
OR
-
8/2/2019 AP Lab Manual Sem 5
27/37
27
SVBIT 5th
SEM CE [AP]
Output:
-
8/2/2019 AP Lab Manual Sem 5
28/37
28
SVBIT 5th
SEM CE [AP]
AIM: Write a program for finding average.
Program:
.model small
.datablk1 db 01,02,03,04,05,06,07,08,09,0AHcount dw 000AH
.codemov ax,@data ;initialise data segmentmov ds,axmov ax,0 ;initialise ax=0mov si,offset blk1 ;initialise pointermov cx,count ;initialise countercld ;df=0
l1: add al,[si] ;add numbersinc si ;increment pointerdec count ;decrement counter
jnz l1 ;check if all nos are added
mov ah,00 ;ah=0mov bl,0AH ;initialise bl with countdiv bl ;average=sum/countmov dx,ax
mov ah,4cH ; Terminate Programint 21Hend
Output:
-
8/2/2019 AP Lab Manual Sem 5
29/37
29
SVBIT 5th
SEM CE [AP]
AIM: Write a Program for finding 1's complement of a number
Program:
.model small
.data
a dw 1234H
.code
mov ax,@data ; Initialize data section
mov ds,ax
mov ax,a ; Load number in ax
neg ax ; find 2's compement. Result in ax
sub ax,1 ; 1's complement=2's comp-1
mov ch,04h ; Count of digits to be displayed
mov cl,04h ; Count to roll by 4 bits
mov bx,ax ; Result in reg bx
l2: rol bx,cl ; roll bl so that msb comes to lsbmov dl,bl ; load dl with data to be displayed
and dl,0fH ; get only lsb
cmp dl,09 ; check if digit is 0-9 or letter A-F
jbe l4
add dl,07 ; if letter add 37H else only add 30H
l4: add dl,30H
mov ah,02 ; Function 2 under INT 21H (Display character)int 21H
dec ch ; Decrement Count
jnz l2
-
8/2/2019 AP Lab Manual Sem 5
30/37
30
SVBIT 5th
SEM CE [AP]
mov ah,4cH ; Terminate Program
int 21H
end
OR.model small
.data
a dw 1234H
.code
mov ax,@data ; Initialize data section
mov ds,ax
mov ax,a ; Load number in axneg ax ; find 2's compement. Result in ax
sub ax,1 ; 1's complement=2's comp-1
mov bx,ax
mov ah,4cH ; Terminate Program
int 21H
end
OR
.model small
.data
a dw 1234H
.code
mov ax,@data ; Initialize data section
mov ds,ax
mov ax,a ; Load number in axmov cx,16 ; Load CX with count
up: rcl ax,1 ; Rotate ax by 1bit to left with carry
cmc ; find 1's complement of bit
loop up ; check if all bits complemented,if not goto up
rcl ax,1 ; return carry back to original position
-
8/2/2019 AP Lab Manual Sem 5
31/37
31
SVBIT 5th
SEM CE [AP]
mov ch,04h ; Count of digits to be displayed
mov cl,04h ; Count to roll by 4 bits
mov bx,ax ; Result in reg bx
l2: rol bx,cl ; roll bl so that msb comes to lsbmov dl,bl ; load dl with data to be displayed
and dl,0fH ; get only lsb
cmp dl,09 ; check if digit is 0-9 or letter A-F
jbe l4
add dl,07 ; if letter add 37H else only add 30H
l4: add dl,30H
mov ah,02 ; Function 2 under INT 21H (Display character)
int 21Hdec ch ; Decrement Count
jnz l2
mov ah,4cH ; Terminate Program
int 21H
end
OR
.model small
.data
a dw 1234H
.code
mov ax,@data ; Initialize data section
mov ds,axmov ax,a ; Load number1 in ax
mov cx,16 ; Load CX with count
up: rcl ax,1 ; Rotate ax by 1bit to left with carry
cmc ; find 1's complement of bit
loop up ; check if all bits complemented,if not goto up
-
8/2/2019 AP Lab Manual Sem 5
32/37
32
SVBIT 5th
SEM CE [AP]
rcl ax,1 ; return carry back to original position
mov bx,ax
mov ah,4cH ; Terminate Programint 21H
end
Output:
Output:
Output:
Output:
-
8/2/2019 AP Lab Manual Sem 5
33/37
33
SVBIT 5th
SEM CE [AP]
AIM: Write a Program for finding 2's complement of a number
Program:
.model small
.data
a dw 1234H
.code
mov ax,@data ; Initialize data section
mov ds,ax
mov ax,a ; Load number1 in ax
mov cx,16 ; Load CX with count
up: rcl ax,1 ; Rotate ax by 1bit to left with carry
cmc ; find 1's complement of bit
loop up ; check if all bits complemented,if not goto up
rcl ax,1 ; return carry back to original position
add ax,1 ; 2's complement=1's complement+1
mov bx,ax
mov ah,4cH ; Terminate Programint 21H
end
OR
.model small
.dataa dw 1234H
.code
mov ax,@data ; Initialize data section
mov ds,ax
mov ax,a ; Load number1 in ax
-
8/2/2019 AP Lab Manual Sem 5
34/37
34
SVBIT 5th
SEM CE [AP]
neg ax ; find 2's compement. Result in ax
mov bx,ax
mov ah,4cH ; Terminate Program
int 21H
end
Output:
Output:
-
8/2/2019 AP Lab Manual Sem 5
35/37
35
SVBIT 5th
SEM CE [AP]
AIM: Write a Program for 16 bit multiplication.
Program:
.model small
.dataa dw 1234Hb dw 0100H
.codemov ax,@data ; Initialize data sectionmov ds,axmov ax,a ; Load number1 in axmov bx,b ; Load number2 in bl
mul bx ; multiply numbers. Result in dx and ax
mov si,axmov bx,dx ; Result in reg bxmov dh,2
l1: mov ch,04h ; Count of digits to be displayedmov cl,04h ; Count to roll by 4 bits
l2: rol bx,cl ; roll bl so that msb comes to lsbmov dl,bl ; load dl with data to be displayedand dl,0fH ; get only lsbcmp dl,09 ; check if digit is 0-9 or letter A-F
jbe l4add dl,07 ; if letter add 37H else only add 30H
l4: add dl,30Hmov ah,02 ; Function 2 under INT 21H (Display character)
int 21Hdec ch ; Decrement Countjnz l2
dec dhcmp dh,0
-
8/2/2019 AP Lab Manual Sem 5
36/37
36
SVBIT 5th
SEM CE [AP]
mov bx,sijnz l1
mov ah,4cH ; Terminate Program
int 21Hend
Output:
-
8/2/2019 AP Lab Manual Sem 5
37/37
AIM: Write a Program to find maximum number in the array.
Program:
.model small
.stack 100
.dataarray db 61h,05h,42h,05H,12H,15h,09h,14h,56h,38h ; Arrayof10nosmax db 0
.codeMOV AX,@data ; Initialize DSMOV DS,AXXOR DI,DI ; Initialise pointer
MOV CL,10 ; Initialise counterLEA BX,ARRAY ; Initialise base pointer for arrayMOV AL,MAX ; Get maximum number
BACK: CMP AL,[BX+DI] ; Compare number with maximumJNC SKIPMOV DL,[BX+DI] ; If no > this no swapMOV AL,DL
SKIP: INC DI ; Increment pointer
DEC CL ; Decrement counterJNZ BACK ; check whether all the nos have beenscannedMOV CL,AL ; Store maximum number
mov ah,4cH ; Terminate Programint 21Hend
Output: