You are on page 1of 37

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:

1 SVBIT 5 SEM CE [AP]


th

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:

2 SVBIT 5 SEM CE [AP]


th

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 21H end

Output:

3 SVBIT 5 SEM CE [AP]


th

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, 4cH int 21H end

Output:

4 SVBIT 5 SEM CE [AP]


th

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, 4cH int 21H end

Output:

5 SVBIT 5 SEM CE [AP]


th

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:

6 SVBIT 5 SEM CE [AP]


th

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, 4cH int 21H end Output:

7 SVBIT 5 SEM CE [AP]


th

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, 4cH int 21H end Output:

8 SVBIT 5 SEM CE [AP]


th

AIM: Write a program to print HELLO!. Program:


ORG MOV MOV INT MOV INT MOV INT MOV INT MOV INT MOV INT RET 100h AH, 0Eh AL, 'H' 10h AL, 'e' 10h AL, 'l' 10h AL, 'l' 10h AL, 'o' 10h AL, '!' 10h

Output:

9 SVBIT 5 SEM CE [AP]


th

AIM: Write a Program to Display String using procedure. Program:


.MODEL SMALL .DATA STRING db 'Study of Microprocessor is Interesting $' .CODE MOV AX,@DATA MOV DS,AX CALL DISP MOV AH,4CH INT 21H DISP PROC NEAR MOV AH,09H LEA DX,STRING INT 21H ENDP RET END

Output:

10 SVBIT 5 SEM CE [AP]


th

AIM: Write a Program to accept input from keyboard and display it. Program:
.MODEL SMALL .STACK 100H .DATA .CODE MOV AX,@DATA MOV DS,AX UP: MOV AH,01H INT 21H CMP AL,30H JE ENDD JMP UP ENDD: MOV AH,4CH INT 21H END ; Get input from keyboard

; If 0 is entered End program

; Terminate Program

Output:

`
11 SVBIT 5 SEM CE [AP]
th

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 mov bx,word ptr op1+2 mov cx,word ptr op2 mov dx,word ptr op2+2 add ax,cx adc bx,dx mov word ptr ans,ax mov word ptr ans+2,bx mov bx,word ptr ans+2 mov dh,2 l1: mov ch,04h mov cl,04h l2: rol bx,cl mov dl,bl and dl,0fH cmp dl,09 jbe l4 add dl,07 l4: add dl,30H mov ah,02 int 21H

; lsb of number1 in ax ; msb of number1 in bx ; lsb of number2 in cx ; msb of number1 in dx ; add lsb + lsb ; add msb + msb + carry ; lsb answer ; msb answer ; Result in reg bx ; Count of digits to be displayed ; Count to roll by 4 bits ; roll bl so that msb comes to lsb ; load dl with data to be displayed ; get only lsb ; check if digit is 0-9 or letter A-F ; if letter add 37H else only add 30H ; INT 21H (Display character)

12 SVBIT 5 SEM CE [AP]


th

dec ch jnz l2 dec dh cmp dh,0 mov bx,word ptr ans jnz l1 mov ah,4ch int 21h end

; Decrement Count

; display lsb of answer

; Terminate Program

OR
.model small .data op1 dd 12345678h op2 dd 11111111h .code mov ax,@data mov ds,ax mov ax,word ptr op1 mov bx,word ptr op1+2 mov cx,word ptr op2 mov dx,word ptr op2+2 add ax,cx mov cx,ax adc bx,dx

; lsb of number1 in ax ; msb of number1 in bx ; lsb of number2 in cx ; msb of number1 in dx ; add lsb + lsb ; add msb + msb + carry

mov ah,4ch int 21h end

; Terminate Program

13 SVBIT 5 SEM CE [AP]


th

Output:

OR
Output:

14 SVBIT 5 SEM CE [AP]


th

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 mov bx,word ptr op1+2 mov cx,word ptr op2 mov dx,word ptr op2+2 sub ax,cx sbb bx,dx mov word ptr ans,ax mov word ptr ans+2,bx

; lsb of number1 in ax ; msb of number1 in bx ; lsb of number2 in cx ; msb of number1 in dx ; add lsb + lsb ; add msb + msb + carry ; lsb answer ; 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 mov dl,bl and dl,0fH cmp dl,09 jbe l4 ; roll bl so that msb comes to lsb ; load dl with data to be displayed ; get only lsb ; check if digit is 0-9 or letter A-F

15 SVBIT 5 SEM CE [AP]


th

add dl,07 l4: add dl,30H mov ah,02 int 21H dec ch jnz l2 dec dh cmp dh,0 mov bx,word ptr ans jnz l1 mov ah,4ch int 21h end .model small .data op1 dd 12345678h op2 dd 11111111h .code mov ax,@data mov ds,ax mov ax,word ptr op1 mov bx,word ptr op1+2 mov cx,word ptr op2 mov dx,word ptr op2+2 sub ax,cx mov cx,ax sbb bx,dx
SVBIT

; if letter add 37H else only add 30H ; INT 21H (Display character) ; Decrement Count

; display lsb of answer

; Terminate Program

OR

; lsb of number1 in ax ; msb of number1 in bx ; lsb of number2 in cx ; msb of number1 in dx ; add lsb + lsb ; add msb + msb + carry
16 5 SEM CE [AP]
th

mov ah,4ch int 21h end Output:

; Terminate Program

OR
Output:

17 SVBIT 5 SEM CE [AP]


th

AIM: Write a Program for counting the number of 1's in a number. Program: .model small .data a dw 5267H .code mov ax,@data mov ds,ax mov ax,a mov bx,0 mov cx,16 back: rcr ax,1 jnc l1 inc bl l1: dec cx jnz back mov ah,4cH int 21H end Output:

; Initialize data section ; Load number in ax ; clear bx for counting number of 1in a given number. ; load count in cx register ; rotate by 1 bit to the right ; if bit is 0 goto next bit ; if bit=1 increment count ; decrement counter ; Terminate Program

18 SVBIT 5 SEM CE [AP]


th

AIM: Write a Program to find the factorial of a number. Program: .model small .data num dw 05h .code mov ax, @data mov ds, ax mov ax, 01 mov bx, num call fact mov dx,ax mov ah, 4ch int 21h fact proc near cmp bx, 01 jz l11 l12: mul bx dec bx cmp bx, 01 jne l12 ret l11: ret fact endp end Output: ; result save in dx

19 SVBIT 5 SEM CE [AP]


th

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 LOOP2: MOV CX,DX DEC CX MOV SI,CX add SI,si MOV AX,NUM[SI] LOOP1:CMP NUM[SI-2],AX JBE NEXT MOV DI,NUM[SI-2] MOV NUM[SI],DI DEC SI DEC SI DEC CX JNZ LOOP1 NEXT:MOV NUM[SI],AX INC DX CMP DX,4 JBE LOOP2 mov si,offset num mov dh,4 l1: mov ch,04h mov cl,04h mov bx,[si]
SVBIT

; DX has location where n0 is to be placed ; CX number of comparisons required ; si*2 as word ptr ; Get the number ; Compare it with previous number ; if prev num <= this num goto next ; else ; insert in new posn ; decrement si ; Decrement comparison counter ; If not zero, repeat ; Insert the number in proper position ; Next number to be inserted ; Check if all numbers are inserted ; If not continue

; Count of digits to be displayed ; Count to roll by 4 bits ; Result in reg bx


20 5 SEM CE [AP]
th

l2: rol bx,cl mov dl,bl and dl,0fH cmp dl,09 jbe l4 add dl,07 l4: add dl,30H mov ah,02 int 21H dec ch jnz l2 mov ah,02 mov dl,' ' int 21h inc si inc si dec dh cmp dh,0 jnz l1 mov ah,4cH int 21H END

; roll bl so that msb comes to lsb ; load dl with data to be displayed ; get only lsb ; check if digit is 0-9 or letter A-F ; if letter add 37H else only add 30H ; Function 2 under INT 21H (Display character) ; Decrement Count

; Display space between 2 numbers ; incr si twice as word ptr

; Terminate Program

OR
.MODEL SMALL .STACK 100 .DATA NUM DW 0102H,0154H,0070H,0005H .CODE MOV AX,@DATA ; Initialise data segment MOV DS,AX
21 SVBIT 5 SEM CE [AP]
th

MOV DX,2 LOOP2: MOV CX,DX DEC CX MOV SI,CX add SI,si MOV AX,NUM[SI] LOOP1: CMP NUM[SI-2],AX JBE NEXT MOV DI,NUM[SI-2] MOV NUM[SI],DI DEC SI DEC SI DEC CX JNZ LOOP1 NEXT: MOV NUM[SI],AX INC DX CMP DX,4 JBE LOOP2

; DX has location where n0 is to be placed ; CX number of comparisons required ; si*2 as word ptr ; Get the number ; Compare it with previous number ; if prev num <= this num goto next ; else ; insert in new posn ; decrement si ; Decrement comparison counter ; If not zero, repeat ; Insert the number in proper position ; Next number to be inserted ; Check if all numbers are inserted ; If not continue

mov ah,4cH int 21H END

; Terminate Program

Output:

22 SVBIT 5 SEM CE [AP]


th

OR
Output:

23 SVBIT 5 SEM CE [AP]


th

AIM: Write a Program to sorting the numbers in descending 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 LOOP2:MOV CX,DX DEC CX MOV SI,CX add SI,si MOV AX,NUM[SI] LOOP1: CMP NUM[SI-2],AX JAE NEXT MOV DI,NUM[SI-2] MOV NUM[SI],DI DEC SI DEC SI DEC CX JNZ LOOP1 NEXT: MOV NUM[SI],AX INC DX CMP DX,4 JBE LOOP2 ; DX has location where n0 is to be placed ; CX number of comparisons required ; si*2 as word ptr ; Get the number ; Compare it with previous number ; if prev num >= this num goto next ; else ; insert in new posn ; decrement si ; Decrement comparison counter ; If not zero, repeat ; Insert the number in proper position ; Next number to be inserted ; Check if all numbers are inserted ; If not continue

mov ah,4cH int 21H END

; Terminate Program

OR
.MODEL SMALL .STACK 100
24 SVBIT 5 SEM CE [AP]
th

.DATA NUM DW 0102H,0154H,0070H,0005H .CODE MOV AX,@DATA ; Initialise data segment MOV DS,AX MOV DX,2 LOOP2: MOV CX,DX DEC CX MOV SI,CX add SI,si MOV AX,NUM[SI] LOOP1:CMP NUM[SI-2],AX JAE NEXT MOV DI,NUM[SI-2] MOV NUM[SI],DI DEC SI DEC SI DEC CX JNZ LOOP1 NEXT: MOV NUM[SI],AX INC DX CMP DX,4 JBE LOOP2 mov si,offset num mov dh,4 l1: mov ch,04h mov cl,04h mov bx,[si] l2: rol bx,cl mov dl,bl and dl,0fH cmp dl,09 jbe l4 add dl,07 l4: add dl,30H mov ah,02 int 21H
SVBIT

; DX has location where num is to be inserted ; CX number of comparisons required ; si*2 as word ptr ; Get the number ; Compare it with previous number ; if prev num >= this num goto next ; else ; insert in new posn ; decrement si ; Decrement comparison counter ; If not zero, repeat ; Insert the number in proper position ; Next number to be inserted ; Check if all numbers are inserted ; If not continue

; Count of digits to be displayed ; Count to roll by 4 bits ; Result in reg bx ; roll bl so that msb comes to lsb ; load dl with data to be displayed ; get only lsb ; check if digit is 0-9 or letter A-F ; if letter add 37H else only add 30H ; Function 2 under INT 21H (Display character)
25 5 SEM CE [AP]
th

dec ch jnz l2 mov ah,02 mov dl,' ' int 21h inc si inc si dec dh cmp dh,0 jnz l1 mov ah,4cH int 21H END Output:

; Decrement Count

; Display space between 2 numbers ; incr si twice as word ptr

; Terminate Program

OR

26 SVBIT 5 SEM CE [AP]


th

Output:

27 SVBIT 5 SEM CE [AP]


th

AIM: Write a program for finding average. Program:


.model small .data blk1 db 01,02,03,04,05,06,07,08,09,0AH count dw 000AH .code mov ax,@data ;initialise data segment mov ds,ax mov ax,0 ;initialise ax=0 mov si,offset blk1 ;initialise pointer mov cx,count ;initialise counter cld ;df=0 l1: add al,[si] ;add numbers inc si ;increment pointer dec count ;decrement counter jnz l1 ;check if all nos are added mov ah,00 mov bl,0AH div bl mov dx,ax mov ah,4cH int 21H end ;ah=0 ;initialise bl with count ;average=sum/count

; Terminate Program

Output:

28 SVBIT 5 SEM CE [AP]


th

AIM: Write a Program for finding 1's complement of a number Program: .model small .data a dw 1234H .code mov ax,@data mov ds,ax mov ax,a neg ax sub ax,1 mov ch,04h mov cl,04h mov bx,ax l2: rol bx,cl mov dl,bl and dl,0fH cmp dl,09 jbe l4 add dl,07 l4: add dl,30H mov ah,02 int 21H dec ch jnz l2

; Initialize data section ; Load number in ax ; find 2's compement. Result in ax ; 1's complement=2's comp-1 ; Count of digits to be displayed ; Count to roll by 4 bits ; Result in reg bx ; roll bl so that msb comes to lsb ; load dl with data to be displayed ; get only lsb ; check if digit is 0-9 or letter A-F ; if letter add 37H else only add 30H ; Function 2 under INT 21H (Display character) ; Decrement Count

29 SVBIT 5 SEM CE [AP]


th

mov ah,4cH int 21H end

; Terminate Program

OR
.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 bx,ax mov ah,4cH int 21H end ; Terminate Program

OR
.model small .data a dw 1234H .code mov ax,@data ; Initialize data section mov ds,ax mov ax,a ; Load number 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
30 SVBIT 5 SEM CE [AP]
th

mov ch,04h mov cl,04h mov bx,ax l2: rol bx,cl mov dl,bl and dl,0fH cmp dl,09 jbe l4 add dl,07 l4: add dl,30H mov ah,02 int 21H dec ch jnz l2 mov ah,4cH int 21H end

; Count of digits to be displayed ; Count to roll by 4 bits ; Result in reg bx ; roll bl so that msb comes to lsb ; load dl with data to be displayed ; get only lsb ; check if digit is 0-9 or letter A-F ; if letter add 37H else only add 30H ; Function 2 under INT 21H (Display character) ; Decrement Count

; Terminate Program

OR
.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
31 SVBIT 5 SEM CE [AP]
th

rcl ax,1 mov bx,ax

; return carry back to original position

mov ah,4cH int 21H end

; Terminate Program

Output:

Output:

Output:

Output:

32 SVBIT 5 SEM CE [AP]


th

AIM: Write a Program for finding 2's complement of a number Program: .model small .data a dw 1234H .code mov ax,@data mov ds,ax mov ax,a mov cx,16 up: rcl ax,1 cmc loop up rcl ax,1 add ax,1 mov bx,ax mov ah,4cH int 21H end

; Initialize data section ; Load number1 in ax ; Load CX with count ; Rotate ax by 1bit to left with carry ; find 1's complement of bit ; check if all bits complemented,if not goto up ; return carry back to original position ; 2's complement=1's complement+1

; Terminate Program

OR
.model small .data a dw 1234H .code mov ax,@data mov ds,ax mov ax,a

; Initialize data section ; Load number1 in ax


33
th

SVBIT

5 SEM CE [AP]

neg ax mov bx,ax mov ah,4cH int 21H end

; find 2's compement. Result in ax ; Terminate Program

Output:

Output:

34 SVBIT 5 SEM CE [AP]


th

AIM: Write a Program for 16 bit multiplication. Program: .model small .data a dw 1234H b dw 0100H .code mov ax,@data mov ds,ax mov ax,a mov bx,b mul bx mov si,ax mov bx,dx mov dh,2 l1: mov ch,04h mov cl,04h l2: rol bx,cl mov dl,bl and dl,0fH cmp dl,09 jbe l4 add dl,07 l4: add dl,30H mov ah,02 int 21H dec ch jnz l2 dec dh cmp dh,0
35 SVBIT 5 SEM CE [AP]
th

; Initialize data section ; Load number1 in ax ; Load number2 in bl ; multiply numbers. Result in dx and ax

; Result in reg bx ; Count of digits to be displayed ; Count to roll by 4 bits ; roll bl so that msb comes to lsb ; load dl with data to be displayed ; get only lsb ; check if digit is 0-9 or letter A-F ; if letter add 37H else only add 30H ; Function 2 under INT 21H (Display character) ; Decrement Count

mov bx,si jnz l1 mov ah,4cH int 21H end Output: ; Terminate Program

36 SVBIT 5 SEM CE [AP]


th

AIM: Write a Program to find maximum number in the array. Program: .model small .stack 100 .data array db 61h,05h,42h,05H,12H,15h,09h,14h,56h,38h ; Arrayof10nos max db 0 .code MOV AX,@data ; Initialize DS MOV DS,AX XOR DI,DI ; Initialise pointer MOV CL,10 ; Initialise counter LEA BX,ARRAY ; Initialise base pointer for array MOV AL,MAX ; Get maximum number BACK: CMP AL,[BX+DI] ; Compare number with maximum JNC SKIP MOV DL,[BX+DI] ; If no > this no swap MOV AL,DL SKIP: INC DI ; Increment pointer DEC CL ; Decrement counter JNZ BACK ; check whether all the nos have been scanned MOV CL,AL ; Store maximum number mov ah,4cH int 21H end Output: ; Terminate Program

37 SVBIT 5 SEM CE [AP]


th

You might also like