0% found this document useful (0 votes)
346 views35 pages

Vtu Microprocessor Lab Programs

This program reads a string, reverses it, and compares it to the original string to check if it is a palindrome. It performs the following steps in 3 sentences or less: 1. It reads a string from memory, stores it in another variable to reverse it, and finds the length of the string. 2. It uses a loop to reverse the characters in the second string and compare it to the original. 3. It stores a result in memory to indicate if the strings are equal, and therefore the original is a palindrome.

Uploaded by

Priya Ravi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
346 views35 pages

Vtu Microprocessor Lab Programs

This program reads a string, reverses it, and compares it to the original string to check if it is a palindrome. It performs the following steps in 3 sentences or less: 1. It reads a string from memory, stores it in another variable to reverse it, and finds the length of the string. 2. It uses a loop to reverse the characters in the second string and compare it to the original. 3. It stores a result in memory to indicate if the strings are equal, and therefore the original is a palindrome.

Uploaded by

Priya Ravi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 35

vtu microprocessor lab programs

67
rate or flag this pageTweet this
By techno geek
PGM TO READ A CHAR FROM THE KEYBOARD IN THE MODULE1 DISPLAY A
CHAR IN MODULE2
?
1 stack segment
2   dw 64 dup(0)
3 stack ends
4  
5 data segment
6   str db 100 dup(0)
7   msg db 0Ah, 0Dh, '$'
8 data ends
9  
10 code segment
11     assume cs:code,ds:data,ss:stack
12 start:mov ax,data
13       mov ds,ax
14       extrn scan:far
15       extrn display:far
16       lea si,str
17       mov cl,00h
18  
19 again:call scan                                                  
20       cmp al,0Dh
21       je exit
22       mov [si],al
23       inc si
24       inc cl
25       jmp again
26  
27 exit:lea dx,msg
28      mov ah,09h
29      int 21h
30      lea si,str
31  
32 repeat:cmp cl,00h
33        je t1
34       
35        mov al,[si]
36        call display
37        inc si
38        dec cl
39        jmp repeat
40  
41 t1:mov ah,4ch
42    int 21h
43  
44   code ends
45 end start
46 _
2 (a1) ;READ A CHARACTR FROM THE KEYBOARD
?
1 rdkb macro
2   mov ah,01h
3   int 21h
4 endm
5 code segment
6     assume cs:code
7 start:public scan
8       scan proc far
9       rdkb
10       ret
11       scan endp
12    code ends
13 end start
2 (a2) ;TO DISPLAY A CHARACTER IN MODULE[2]
?
1 echo macro
2   mov dl,al
3   mov ah,02h
4   int 21h
5 endm
6 stack segment
7   dw 64 dup(0)
8 stack ends
9 code segment
10    assume cs:code, ss:stack
11 start:public display
12       display proc far
13       echo
14       ret
15      display endp
16   code ends
17 end start
PROGRAMME TO IMPLEMENT THE BCD UPCOUNTER
?
1 data segment
2     porta equ 0280h
3     cwr equ 0283h
4 data ends
5  
6 code segment
7    assume cs:code,ds:data
8 start:    mov ax,data
9           mov ds,ax
10        
11            mov dx,cwr
12            mov al,82h
13            out dx,al
14  
15            mov ah,01h
16            int 21h
17        
18            cmp al,31h
19            je up
20            jmp down
21          
22       up:  mov al,00h
23            mov dx,porta
24  
25    again:  out dx,al
26            inc al
27        cmp al,0ah
28        je stop
29        call delay
30        jmp again
31  
32     down:  mov al,09h
33            mov dx,porta
34    
35     next:   out dx,al
36             dec al
37         cmp al,0ffh
38             je stop
39             call delay
40         jmp next
41  
42 stop:  mov ah,4ch
43             int 21h
44         
45     delay proc
46          mov si,0ffffh
47          t2: mov di,200h
48          t1: dec di
49          jnz t1
50          dec si
51          jnz t2
52          ret
53     delay endp
54  code ends
55 end start
PROGRAMME TO PERFORM THE RING COUNTER
?
1 data segment
2     porta equ 0280h
3     cwr equ 0283h
4 data ends
5  
6 code segment
7    assume cs:code,ds:data
8 start:      mov ax,data
9             mov ds,ax
10       
11             mov dx,cwr
12             mov al,82h
13             out dx,al
14  
15        
16             mov al,01h
17       
18             mov cl,08h
19             mov dx,porta
20  
21     again:  out dx,al
22             call delay
23             rol al,1
24             dec cl
25             jnz again
26  
27  
28            int 3h
29  
30      delay proc
31              mov si,0ffffh
32         t2:  mov di,200h
33         t1:  dec di
34              jnz t1
35              dec si
36              jnz t2
37            ret
38      delay endp
39  
40   code ends
41 end start
TO SORT A GIVEN NO IN ASCENDING AND DESCENDING ORDER
?
1 data segment
2    num1 db 12h,21h,17h,19h
3    num2 db 4 dup(0)
4    num3 db 4 dup(0)
5    l1 dw 0004
6 data ends
7 code segment
8    assume cs:code,ds:data,ss:stack
9 start:mov ax,data
10       mov ds,ax
11       lea si,num1
12       lea di,num2
13       lea bx,num3
14       mov cx,l1
15 repeat1:mov al,[si]
16        mov [di],al
17        mov [bx],al
18        inc si
19        inc di
20        inc bx
21        dec cx
22        jnz repeat1
23        mov bx,l1
24        dec bx
25 outlp1:mov cx,bx
26        lea si,num2
27 inlp1:mov al,[si]
28      inc si
29      cmp al,[si]
30      jb next1
31      xchg al,[si]
32      mov [si-1],al
33 next1:dec cx
34      jnz inlp1
35      dec bx
36      jnz outlp1
37      mov bx,l1
38      dec bx
39 outlp2:mov cx,bx
40        lea si,num3
41 inlp2:mov al,[si]
42       inc si
43       cmp al,[si]
44       ja next2
45       xchg al,[si]
46       mov [si-1],al
47 next2:dec cx
48       jnz inlp2
49       dec bx
50       jnz outlp2
51       int 3h
52 code ends
53 end start
READ A STATUS OF TWO 8 BITS INPUTS FROM THE LOGIC CONTROLLER X
AND Y. DISPLAY X*Y.
?
1 data segment
2     porta equ 0280h
3     portb equ 0281h
4     cwr equ 0283h
5 data ends
6  
7 code segment
8   assume cs:code, ds:data
9 start:    mov ax,data
10           mov ds,ax
11  
12           mov dx,cwr
13           mov al,82h
14           out dx,al
15  
16           mov dx,portb
17           in al,dx
18  
19           mov bl,al
20        
21           mov ah,01h
22           int 21h
23  
24           in al,dx
25           mul bl
26           mov cx,ax
27        
28           mov dx,porta
29           out dx,al
30  
31           mov ah,01h
32           int 21h
33  
34           mov al,ch
35           out dx,al
36  
37           mov ah,4ch
38           int 21h
39  
40     code ends
41 end start
READ AN ALPHANUMERIC CHARACTERS AND DISPLAY ITS EQUIVALENT
ASCII CODE AT THE CENTRE OF THE SCREEN
?
1 stack segment
2   dw 64 dup(0)
3 stack ends
4  
5 data segment
6   str db 'enter the character:$'
7 data ends
8  
9 code segment
10     assume cs:code,ds:data,ss:stack
11 start:mov ax,data
12       mov ds,ax
13       lea dx,str
14       mov ah,09h
15       int 21h
16       mov ah,01h
17       int 21h
18       mov bl,al
19       call clrscr
20       call curset
21       call display
22       mov ah,4ch
23       int 21h
24  
25  
26 clrscr proc
27   mov cx,0000h
28   mov dx,184fh
29   mov bh,01h
30   mov al,00h
31   mov ah,06h
32   int 10h
33 ret
34 clrscr endp
35  
36 curset proc
37   push ax
38   push bx
39   push dx
40   mov bh,00h
41   mov bh,02h
42 mov dl,38
43   mov dh,12
44   int 10h
45   pop dx
46   pop bx
47   pop ax
48 ret
49 curset endp
50  
51  
52 display proc
53   mov al,bl
54   mov cl,04h
55   shr al,cl
56   cmp al,09h
57   jb t1
58   add al,07h
59  
60 t1:add al,30h
61    mov dl,al
62    mov ah,02h
63    int 21h
64    mov al,bl
65    and al,0fh
66    cmp al,09h
67    jb t2
68    add al,07h
69  
70 t2:add al,30h
71    mov dl,al
72    mov ah,02h
73    int 21h
74 ret
75 display endp
76  
77  code ends
78 end start
DISPLAY MESSAGES FIRE AND HELP ALTERNATELY WITH FLICKERING
EFFECTS ON A 7-SEGMENT DISPLAY INTERFACE FOR A SUITABLE PERIOD
OF TIME.
?
1 data segment
2      portb equ 281h
3      portc equ 282h
4      cwr equ 283h
5      num1 db 086h,0ceh,0f9h,8eh
6      num2 db 8ch,0c7h,86h,89h
7      n dw 04h
8 data ends
9  
10 code segment
11    assume cs:code,ds:data
12 start:    mov ax,data
13           mov ds,ax
14  
15           mov al,80h
16           mov dx,cwr
17           out dx,al
18  
19        
20  
21      ne:  lea si,num1
22           call display
23            
24           call delay
25            
26           lea si,num2
27           call display
28            
29            
30           call delay
31            
32           dec n
33           jnz ne        
34          
35  
36           mov ah,4ch
37           int 21h
38  
39         
40           display proc
41                mov di,0004
42          
43         again: mov al,[si]
44                mov bh,08h
45  
46          next: rol al,01h
47                mov bl,al
48                 
49                mov dx,portb
50                out dx,al
51                 
52                mov al,00h
53                mov dx,portc
54                out dx,al
55                mov al,0ffh
56                mov dx,portc
57                out dx,al
58                
59                mov al,bl
60                dec bh
61                jnz next
62  
63                inc si
64                dec di
65                jnz again
66                 
67                ret
68         display endp
69       delay proc
70                mov si,0ffffh
71            t2: mov di,134h
72            t1: dec di
73               jnz t1
74               dec si
75               jnz t2
76               ret
77           delay endp
78  
79   code ends
80 end start
PGM TO REVERSE A GIVEN STRING A CHECK WHEATHER IT IS A
PALINDROME OR NOT
?
1 stack segment
2   dw 64 dup(0)
3 stack ends
4  
5 data segment
6    str1 db "abcd"
7    str2 db 4 dup(0)
8    len dw 0004h
9    res dw ?
10 data ends
11  
12 code segment
13        assume cs:code,ss:stack,ds:data
14 start:mov ax,data
15       mov ds,ax
16       lea si,str1
17       lea di,str2
18       add di,len
19       dec di
20       mov cx,len
21  
22 again:mov al,[si]
23       mov [di],al
24       inc si
25       dec di
26       dec cx
27        
28 jnz again
29   
30 lea si,str1
31 mov di,si
32 add di,len
33 dec di
34 mov cx,len
35 shr cx,1
36  
37 repeat:mov al,[si]
38        cmp al,[di]
39        jne no
40        inc si
41        dec di
42        dec cx
43 jnz repeat
44  
45 mov res,1111h
46 jmp stop
47  
48 no:mov res,0000h
49  
50 stop:int 3h
51   code ends
52 end start
ASSUME ANY SUITABLE MESSAGE OF 12 CHARACTERS LENGHT AND
DISPLAY IT IN THE ROLLING FASHION ON A 7-SEGMENT DISPLAY
INTERFACE.
?
1 data segment
2     portb equ 281h
3     portc equ 282h
4     cwr equ 283h
5     num db 0ffh,0ffh,0ffh,0ffh,8ch,0c7h,86h,89h,0f9h,0c0h,0f9h,0c0h
6     n dw 04
7 data ends
8  
9 code segment
10      assume cs:code,ds:data
11 start:     mov ax,data
12        mov ds,ax
13  
14        mov al,80h
15        mov dx,cwr
16        out dx,al
17  
18        
19  
20    again1: lea si,num
21        call display
22            dec n
23        jnz again1
24     
25  
26         mov ah,4ch
27         int 21h
28  
29         
30        display proc
31           mov di,0012
32      
33        again: mov al,[si]
34           mov bh,08h
35  
36        next:  rol al,01h
37           mov bl,al
38            
39           mov dx,portb
40           out dx,al
41  
42           mov al,00h
43           mov dx,portc
44           out dx,al
45           mov al,0ffh
46           mov dx,portc    
47           out dx,al
48        
49           mov al,bl
50           dec bh
51           jnz next
52           call delay
53  
54           inc si
55           dec di
56           jnz again
57      
58             ret
59     display endp
60  
61  
62  
63     delay proc 
64           push si
65           push di
66    
67           mov si,0ffffh
68       t2: mov di,123h
69       t1: dec di
70           jnz t1
71           
72           dec si
73           jnz t2
74          
75          pop di
76          pop si
77  
78         ret
79     delay endp
80  
81  
82     code ends
83 end start
PGM TO READ TWO STRINGS,STORED THEM IN LOCATION
STR1,STR2.DISPLAY THEIR LENGHTS AND CHECK THEY ARE EQUAL OR
NOT
?
1 stack segment
2   dw 64 dup(0)
3 stack ends
4  
5 data segment
6   dms1 db 'enter the string1:$'
7   msg1 db 20
8   len1 db 00
9   str1 db 20 dup(0)
10   dms2 db 'enter the string2:$'
11   msg2 db 20
12   len2 db 00
13   str2 db 20 dup(0)
14   dis1 db 'strings are equal $'
15   dis2 db 'strings are not equal $'
16   dsl1 db 'length1:$'
17   dsl2 db 'length2:$'
18   nexl db 0ah,0dh,'$'
19 data ends
20  
21 code segment
22      assume cs:code,ds:data,ss:stack
23 start:mov ax,data
24       mov ds,ax
25       lea dx,dms1
26       mov ah,09h
27       int 21h
28       lea dx,msg1
29       mov ah,0ah
30       int 21h
31       lea dx,nexl
32       mov ah,09h
33       int 21h
34  
35       lea dx,dms2 
36       mov ah,09h
37       int 21h
38       lea dx,msg2
39       mov ah,0ah
40       int 21h
41       lea dx,nexl
42       mov ah,09h
43       int 21h
44       lea dx,dsl1
45       mov ah,09h
46       int 21h 
47  
48  
49       mov al,len1
50       call display
51       lea dx,dsl2
52       mov ah,09h
53       int 21h
54       mov al,len2
55     call display
56      mov al,len1
57      cmp al,len2
58      jne exit
59      lea si,str1
60      lea di,str2
61      mov cl,len1
62  
63 again:mov al,[si]
64       cmp al,[di]
65       jne exit
66       inc si
67       inc di
68       dec cl
69       jnz again
70       lea dx,dis1
71       mov ah,09h
72       int 21h
73       jmp stop
74  
75 exit:lea dx,dis2
76      mov ah,09h
77      int 21h
78  
79 stop:mov ah,4ch
80      int 21h
81  
82 display proc
83     aam
84     mov cx,ax
85     mov dx,cx
86     add dh,30h
87     mov dl,dh
88     mov ah,02h
89     int 21h
90     mov dx,cx
91     add dl,30h
92     mov ah,02h
93     int 21h
94 ret
95 display endp
96  
97   code ends
98 end start
READ YOUR NAME FROM THE KEYBOARD AND DISPLAY IT AT A SPECIFIED
LOCATION ON SCREEN
?
1 data segment
2    msg1 db 20
3    len1 db 00
4    str1 db 20 dup('$')
5    str2 db 0ah,0dh,'$'
6    msg2 db 'what is your name?$'
7 data ends
8  
9 code segment
10    assume cs:code,ds:data
11 start:      mov ax,data
12             mov ds,ax
13           
14             lea dx,msg1
15             mov ah,0ah
16             int 21h
17  
18             call clrscr
19             call curset
20  
21             lea dx,msg2
22             mov ah,09h
23             int 21h
24   
25             lea dx,str1
26             mov ah,09h
27             int 21h
28  
29             mov ah,01h
30             int 21h
31  
32             mov ah,4ch
33             int 21h
34  
35  
36 clrscr proc
37       mov cx,0000
38       mov dx,184fh
39              
40       mov al,00
41       mov bh,01
42       mov ah,06h
43       int 10h
44 ret
45 clrscr endp
46  
47  
48 curset proc
49     mov ah,02h
50     mov bh,00h
51     mov dh,10h
52     mov dl,10h
53     int 10h
54 ret
55 curset endp
56  
57   code ends
58 end start
A STEPPER MOTOR INTERFACE TO ROTATE THE MOTOR IN CLOCKWISE
DIRECTION BY N STEPS.
?
1 data segment
2    portc equ 282h
3    cwr equ 283h
4    n equ 10
5 data ends
6  
7 code segment
8  assume cs:code,ds:data
9 start:    mov ax,data
10           mov ds,ax
11        
12           mov al,80h
13           mov dx,cwr
14           out dx,al
15  
16           mov dx,portc
17           mov al,77h
18           mov cx,n
19  
20    again: out dx,al
21           call delay
22           ror al,1
23           dec cx
24           jnz again
25   
26           int 3h
27  
28          delay proc
29                 mov si,0ffffh
30            t2:  mov di,123h
31            t1:  dec di
32                 jnz t1
33                 dec si
34                 jnz t2
35                 ret
36          delay endp
37  
38    code ends
39 end start
PGM TO COMPUTE THE FACTORIAL OF A POSITIVE INTEGER N USING
RECURSIVE PROCEDURE
?
1 stack segment
2   dw 64 dup(0)
3 stack ends
4  
5 data segment
6   n dw 0004
7   res dw 1 dup(0)
8 data ends
9  
10 code segment
11         assume cs:code,ds:data,ss:stack
12 start:mov ax,data
13       mov ds,ax
14       mov bx,n
15       call fact
16       mov res,ax
17       int 3h
18        
19 fact proc
20      cmp bx,0000
21      je exit
22      push bx
23      dec bx
24      call fact
25      pop bx
26      mul bx
27      ret
28  exit:mov ax,0001
29      ret
30 fact endp
31    
32      
33  code ends
34 end start
DRIVE A STEPPER MOTOR INTERFACE TO ROTATE THE MOTOR IN
ANTICLOCKWISE DIRECTION BY N STEPS.
?
1 data segment
2    portc equ 282h
3    cwr equ 283h
4    n equ 10
5 data ends
6  
7 code segment
8  assume cs:code,ds:data
9 start:    mov ax,data
10           mov ds,ax
11        
12           mov al,80h
13           mov dx,cwr
14           out dx,al
15  
16           mov dx,portc
17           mov al,77h
18           mov cx,n
19  
20    again: out dx,al
21           call delay
22           rol al,1
23           dec cx
24           jnz again
25   
26           int 3h
27  
28          delay proc
29                 mov si,0ffffh
30            t2:  mov di,123h
31            t1:  dec di
32                 jnz t1
33                 dec si
34                 jnz t2
35                  ret
36          delay endp
37  
38    
39   code ends end start
40 ;PROGRAMME TO COMPUTE NCR USING RECURSIVE PROCEDURE
41  
42 stack segment
43   dw 64 dup(0)
44 stack ends
45  
46 data segment
47   n dw 0007
48   r dw 0004
49  ncr dw ?
50 data ends
51  
52 code segment
53   assume cs:code,ds:data,ss:stack
54 start:
55       mov ax,data
56       mov ds,ax
57       mov ax,n
58       mov bx,r
59       call ncrp
60    int 3h
61  
62 ncrp proc
63    cmp ax,bx
64    je t1
65    cmp bx,0000
66    je t1
67    cmp bx,0001
68    je t2
69    dec ax
70    cmp ax,bx
71    je t3
72    push ax
73    push bx
74    call ncrp
75    pop bx
76    pop ax
77    dec bx
78    push ax
79    push bx
80    call ncrp
81    pop bx
82    pop ax
83  ret
84   t1:add ncr,0001
85     ret
86 t3:add ncr,0001
87 t2:add ncr,ax
88 ret
89 ncrp endp
90  
91 code ends
92   end start
DRIVE A STEPPER MOTOR INTERFACE TO ROTATE THE MOTOR IN
CLOCKWISE AND ANTICLOCKWISE DIRECTION BY N STEPS.
?
1 data segment
2    portc equ 282h
3    cwr equ 283h
4    n equ 10
5 data ends
6  
7 code segment
8  assume cs:code,ds:data
9 start:    mov ax,data
10           mov ds,ax
11        
12           mov al,80h
13           mov dx,cwr
14           out dx,al
15  
16           mov dx,portc
17           mov al,77h
18           mov cx,n
19  
20    again: out dx,al
21           call delay
22           ror al,1
23           dec cx
24           jnz again
25     
26            mov cx,n
27  
28    again1: out dx,al
29            call delay
30            rol al,1
31            dec cx
32            jnz again1
33   
34           int 3h
35  
36          delay proc
37                 mov si,0ffffh
38            t2:  mov di,123h
39            t1:  dec di
40                 jnz t1
41                 dec si
42                 jnz t2
43                 ret
44          delay endp
45    
46   code ends
47 end start
SCAN A 8*3 KEYPAD FOR KEY CLOSURE AND STORE THE CODE OF THE
KEY PRESSED ;IN A MEMORY LOCATION OR DISPLAY ON SCREEN.ALSO
DISPLAY ROW AND COLUMN ;NUMBERS POF TH
?
1 data segment
2      cwr equ 283h
3      porta equ 280h
4      portc equ 282h
5      cod db ?
6      rowcol db ?
7 table db
8 00h,01h,02h,03h,04h,05h,06h,07h,10h,11h,12h,13h,14h,15h,16h,17h,
9       db 20h,21h,22h,23h,24h,25h,26h,27h                             
10 data ends
11  
12 code segment
13     assume ds:data,cs:code
14 start:   mov ax,data
15          mov ds,ax
16          
17          mov al,90h
18          mov dx,cwr
19          out dx,al
20  
21 again:   mov ch,00h
22          mov al,01h
23          mov dx,portc
24          out dx,al
25          call scan
26          cmp al,00h
27          jne exit
28           
29          mov ch,08h
30          mov al,02h
31          mov dx,portc
         out dx,al
32
         call scan
33
         cmp al,00h
34
         jne exit
35
 
36
         mov ch,10h
37
         mov al,04h
38
         mov dx,portc
39
         out dx,al
40
         call scan
41
         cmp al,00
42
         jne exit
43
         jmp again
44
 
45
   exit: mov cod,ch
46
         mov al,ch
47
         lea bx,table
48
         xlat
49
         mov rowcol,al
50
         int 3h
51
 
52
     
53
   scan proc
54
           mov dx,porta
55
           in al,dx
56
           mov bh,08h
57
    
58
   repeat: ror al,1
59
           jc yes
60
           inc ch
61
           dec bh
62
           jnz repeat
63
      
64
       yes: ret
65
    scan endp
66
 
67
 
68
   code ends
69
end start
PGM TO FIND OUT WHETHER A GIVEN SUB-STRING IS PRESENT OR NOT IN
S MAIN STRING OF CHARACTERS
?
1 stack segment
2   dw 64 dup(0)
3 stack ends
4  
5 data segment
6    char db 'yz'
7    result dw ?
8    l1 dw 0004
9 data ends
10  
11 extra segment
12   string db 'xyzp'
13 extra ends
14  
15 code segment
16        assume cs:code,ds:data,ss:stack,es:extra
17 start:mov ax,data
18       mov ds,ax
19       mov ax,extra
20       mov es,ax
21       lea di,string
22       mov cx,l1
23       mov al,char
24       dec cx
25 repeat:scasw
26       je yes
27       inc di
28       dec cx
29    jnz repeat
30  
31 mov result,0000h
32 jmp stop
33  
34 yes:mov result,1111h
35  
36 stop:int 3h
37   code ends
38 end start
PGM TO GENERATE THE FIRST N FIBONACCI NUMBERS
?
1 stack segment
2    dw 64 dup(0)
3 stack ends
4  
5 data segment
6    fib dw 50 dup(0)
7    n dw 0010
8 data ends
9  
10 code segment
11        assume cs:code,ds:data,ss:stack
12 start:mov ax,data
13       mov ds,ax
14        
15       lea si,fib
16       mov cx,n
17        
18       mov ax,0000h
19       mov bx,0001h
20        
21       mov[si],ax
22        
23       add si,2
24        
25       mov [si],bx
26        
27       add si,2
28        
29       sub cx,2
30        
31        
32      
33 again:cmp cx,0000
34        je exit
35        mov bx,[si-4]
36        add bx,[si-2]
37        mov [si],bx
38        add si,2
39        dec cx
40        jnz again
41  
42 exit:int 3h
43    code ends
44   end start
45 stack segment
46    dw 64 dup(0)
47 stack ends
48  
49 data segment
50    fib dw 50 dup(0)
51    n dw 0010
52 data ends
53  
54 code segment
55        assume cs:code,ds:data,ss:stack
56 start:mov ax,data
57       mov ds,ax
58        
59       lea si,fib
60       mov cx,n
61        
62       mov ax,0000h
63       mov bx,0001h
64        
65       mov[si],ax
66        
67       add si,2
68        
69       mov [si],bx
70        
71       add si,2
72        
73       sub cx,2
74        
75        
76      
77 again:cmp cx,0000
78        je exit
79        mov bx,[si-4]
80        add bx,[si-2]
81        mov [si],bx
82        add si,2
83        dec cx
84        jnz again
85  
86 exit:int 3h
87    code ends
88   end start
SCAN A 8*3 KEYPAD FOR KEY CLOSURE AND SIMULATE ADD AND
SUBTRACT ;OPERATIONS AS IN A CALCULATOR.
?
1 data segment
2      cwr equ 283h
3      porta equ 280h
4      portc equ 282h
5      sum db 0
6      key db 20 dup(0)
7 data ends
8  
9 code segment
10   assume ds:data,cs:code
11 start:   mov ax,data
12          mov ds,ax
13          mov al,90h
14          mov dx,cwr
15          out dx,al
16  
17          lea si,key
18           
19 again:   cmp  ch,0ah
20          je calc
21          mov ch,00h
22          mov al,01h
23          mov dx,portc
24          out dx,al
25           
26          call scan
27          cmp al,00h
28          jne exit
29          mov ch,08h
30          mov al,02h
31          mov dx,portc
32          out dx,al
33           
34          call scan
35          cmp al,00h
36          jne exit
37  
38          mov ch,10h
39          mov al,04h
40          mov dx,portc
41          out dx,al
42           
43          call scan
44           
45          cmp al,00
46          jne exit
47           
48          jmp again
49  
50     exit: cmp ch,[si-1]
51           je t3
52           mov [si],ch
53           inc si
54  
55      t3:  jmp again
56    calc:  mov [si],ch
57           lea si,key
58           mov bl,00h
59  
60           add bl,[si]
61           inc si
62  
63    next:  mov al,[si]
64           cmp al,0ah
65           je stop
66            
67           cmp al,0bh
68           je addition
69            
70           inc si
71           sub bl,[si]
72           inc si
73           jmp next
74  
75 addition:inc si
76          add bl,[si]
77          inc si
78          jmp next
79   
80   stop:  mov sum,bl
81          int 3h
82  
83          scan proc
84                mov dx,porta
85                in al,dx
86                mov bh,08h
87           repeat:ror al,1
88                  jc yes
89                  inc ch
90                  dec bh
91                  jnz repeat
92             yes:ret
93           scan endp     
94  
95         
96  
97    code ends
98 end start
PGM TO READ A CURRENT TIME FROM THE SYSTEM
?
1 stack segment
2   dw 64 dup(0)
3 stack ends
4  
5 code segment
6   assume ss:stack,cs:code
7 start:mov ah,2ch
8       int 21h
9       push cx
10       mov al,ch
11       call display
12       mov dl,':'
13       mov ah,02h
14       int 21h
15       pop cx
16       mov al,cl
17       call display
18 mov ah,4ch
19 int 21h
20  
21  
22 display proc
23    aam
24    mov cx,ax
25    mov dx,cx
26    add dh,30h
27    mov dl,dh
28    mov ah,02h
29    int 21h
30    mov dx,cx
31    add dl,30h
32    mov ah,02h
33  int 21h
34 ret
35 display endp
36  
37 code ends
38 end start
PGM TO STIMULATE A DECIMAL UP-COUNTER TO DISPLAY 00-99
?
1 stack segment
2   dw 64 dup(0)
3 stack ends
4  
5 data segment
6   x db 00
7   count db 100
8 data ends
9  
10 code segment
11   assume cs:code,ds:data,ss:stack
12 start:mov ax,data
13       mov ds,ax
14 again:mov ch,x
15       call curset
16       mov al,ch
17       call display
18       call delay
19       inc x
20       dec count
21       jnz again
22        
23    mov ah,4ch
24    int 21h
25     
26  
27 display proc
28   aam
29   mov cx,ax
30   mov dx,cx
31   add dh,30h
32   mov dl,dh
33   mov ah,02h
34   int 21h
35   mov dx,cx
36   add dl,30h
37   mov ah,02h
38   int 21h
39 ret
40 display endp
41  
42  
43 delay proc
44      mov si,0100h
45   t1:mov di,0ffffh
46   t2:dec di
47      jnz t2
48      dec si
49      jnz t1
50 ret
51 delay endp
52  
53  
54 curset proc
55    mov ah,02h
56    mov bh,00h
57    mov dh,15h
58    mov dl,20h
59    int 10h
60 ret
61 curset endp
62  
63    
64    code ends
65 end start
PGM TO CREATE A FILE(INPUT FILE)AND TO DELETE AN EXISTING FILE
?
1 data segment
2    ftbc db 'ac.asm',0
3    ftbd db 'eg.asm',0
4 data ends
5  
6 code segment
7   assume cs:code,ds:data,ss:stack
8 start:mov ax,data
9       mov ds,ax
10       mov cx,0020h
11       lea dx,ftbc
12       mov ah,3ch
13       int 21h
14       lea dx,ftbd
15       mov ah,41h
16       int 21h
17       int 3h
18   code ends
19 end start
DRIVE AN ELEVATOR INTERFACE IN THE WAY TO MOVE AN ELEVATOR
FROM GROUND ;TO TOP FLOOR AND TOP TO GROUND FLOOR.
?
1 data segment
2    pa equ 280h
3    cwr equ 283h
4 data ends
5 code segment
6 assume cs:code,ds:data
7  start:   mov ax,data
8           mov ds,ax
9            
10           mov al,80h
11       mov dx,cwr
12       out dx,al
13       mov bl,00
14   top:  mov al,bl
15       mov dx,pa
16       out dx,al
17       call delay
18       inc bl
19       cmp bl,0ah
20       jb top
21  top1:  dec bl
22      mov al,bl
23      out dx,al
24      call delay
25      cmp bl,00h
26      jne top1
27     int 3h
28  delay proc
29        push bx
30            mov cx,0ffffh
31     loop1: mov bx,123h
32       t1:  dec bx
33        jnz t1
34        loop loop1
35            pop bx
36        ret
37        delay endp
38  
39   exit: mov ah,4ch
40         int 21h
41  
42   code ends end start
PGM TO READ A PAIR OF I/P CO-ORDINATES IN BCD
?
1 stack segment
2   dw 64 dup(0)
3 stack ends
4  
5 data segment
6   row db ?
7   col db ?
8 data ends
9  
10 code segment
11    assume cs:code,ds:data,ss:stack
12 start:mov ax,data
13       mov ds,ax
14        
15       call readdigit
16       mov row,bl
17        
18       call readdigit
19       mov col,bl
20        
21       call clearscreen
22        
23       mov dl,row
24       mov dh,col
25        
26       call curset
27        
28       mov ah,01h
29       int 21h
30        
31       mov ah,4ch
32       int 21h
33  
34  
35 readdigit proc
36   mov ah,01h
37 int 21h
38 mov cl,04h
39 shl al,cl
40 mov bl,al
41 mov ah,01h
42 int 21h
43 sub al,30h
44 add bl,al
45 ret
46 readdigit endp
47  
48 clearscreen proc
49 mov cx,0000
50 mov dx,184fh
51 mov al,00
52 mov bh,01
53 mov ah,06h
54 int 10h
55 ret
56 clearscreen endp
57  
58 curset proc
59 mov ah,02h
60 mov bh,0h
61 int 10h
62 ret
63 curset endp
64  
65  code ends
66 end start

You might also like