You are on page 1of 15

1a: Search a key element in a list of n 16-bit numbers using the Binary search algorithm. .model small .

data array dw 1003h,1995h,8294h,4456h,6262h,8345h,6966h,64 99h leng dw ($-array)/2 srchkey equ 4456h msg1 db 'Element is found at' res db ' position',13,10,'$' msg2 db 'Element not found',13,10,'$' .code mov ax,@data mov ds,ax mov dx,ax mov dx,leng mov cx,srchkey again: cmp bx,dx ja failure mov ax,bx add ax,dx shr ax,01 mov si,ax dec si add si, si cmp cx,array[si] jae bigger dec ax mov dx,ax jmp again bigger: je success inc ax mov bx,ax jmp again success: add al, '0' mov res,al lea dx,msg1 jmp disp failure: lea dx,msg2 disp: mov ah,09h int 21h mov ah,4ch int 21h end 1b: Read the status of eight input bits from the Logic Controller Interface and display FF if it is even parity bits otherwise display 00. Also display number of 1s in the input data. .model small .stack .data porta equ 0b0c0h portb equ 0b0c1h portc equ 0b0c2h cw equ 0b0c3h no db ?

.code

msg db 'number of ones=$' mov ax,@data mov ds,ax mov dx,cw mov al,82h out dx,al

mov dx,portb in al,dx or al,al push ax jpe peven mov dx,porta mov al,00h out dx,al jmp findones peven: mov dx,porta mov al,0ffh out dx,al findones: mov cx,8 pop ax mov dl,00h rpt1: ror al,01h jnc next inc dl next: loop rpt1 mov no,dl mov ah,09h lea dx,msg int 21h mov ah,02h mov dl,no add dl,30h int 21h exit: mov ah,4ch int 21h end 2a: Write ALP macros: i. To read a character from the keyboard in the module (1) (in a different file) ii. To display a character in module(2) (from different file) iii. Use the above two modules to read a string of characters from the keyboard terminated by the carriage return and print the string on the display in the next line. DISP MACRO MOV AH,02H INT 21H ENDM INPUT MACRO MOV AH,01H INT 21H ENDM .model small .data msg1 db 0ah, 0dh, 'Enter string = $'

rpt2:

.code

msg2 db 0ah, 0dh, 'String is = $' char db 50 dup (00) mov ax,@data mov ds,ax INCLUDE DISP.MAC INCLUDE INPUT.MAC lea dx,msg1 mov ah,09h int 21h INPUT cmp al,0dh je next mov char[si],al inc si jmp cont1 mov cx,si mov si,00 lea dx,msg2 mov ah,09h int 21h mov dl,char[si] DISP inc si loop cont2 mov ah,4ch int 21h

l2: l1:

int 21h delay proc push cx push bx mov cx,0ffffh mov bx,0ffffh dec bx jnz l1 loop l2 pop bx pop cx ret delay endp

cont1:

end

next:

cont2:

end

2b1: Perform the following functions using the Logic Controller Interface: BCD up-down Counter .model small .stack 50 .data porta equ 0b0c0h portb equ 0b0c1h portc equ 0b0c2h cw equ 0b0c3h .code mov ax,@data mov ds,ax mov dx,cw mov al,80h out dx,al mov al,00h mov dx,porta out dx,al rpt1: add al,01h out dx,al call delay cmp al,09h jb rpt1 rpt2: sub al,01h out dx,al call delay cmp al,00h ja rpt2 mov ah,4ch

2b2: Perform the following functions using the Logic Controller Interface: Ring Counter .model small .stack 50 .data porta equ 0b0c0h portb equ 0b0c1h portc equ 0b0c2h cw equ 0b0c3h .code mov ax,@data mov ds,ax mov dx,cw mov al,01h mov dx,porta out dx,al rpt: rol al,01h out dx,al call delay push ax mov ah,0bh int 21h or al,al pop ax jz rpt mov ah,4ch int 21h delay proc push cx push bx mov cx,0ffffh l2: mov bx,0ffffh l1: dec bx jnz l1 loop l2 pop bx pop cx ret delay endp end 3a: Sort a given set of n numbers in ascending and descending orders using the Bubble Sort algorithm.

data segment arr db 15h,45h,24h,43h,61h,67h len db ($-arr) data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov bl,len dec bl up2: mov cx,bx mov si,00 up1: mov al,arr[si] inc si cmp al,arr[si] jb next xchg al,arr[si] mov arr[si-1],al next: loop up1 dec bl jnz up2 mov ah,4ch int 21h code ends end start 3b: Read the status of two 8-bit inputs (X & Y) from the Logic Controller Interface and display X*Y. .model small .stack 50 .data porta equ 0b0c0h portb equ 0b0c1h portc equ 0b0c2h cw equ 0b0c3h msg1 db 13,10,'enter the value of x on portb and press any key $' msg2 db 13,10,'enter the value of y on portb and press any key $' .code mov ax,@data mov ds,ax mov dx,cw mov al,8ah out dx,al lea dx,msg1 mov ah,09h int 21h mov ah,01h int 21h mov dx,portb in al,dx mov cl,al lea dx,msg2 mov ah,09h int 21h mov ah,01h int 21h mov dx,portb

end

in al,dx mul cl mov dx,porta out dx,al mov ah,4ch int 21h

4a: Read an alphanumeric character and display its equivalent ASCII code at the center of the screen. display macro msg mov dx,offset msg mov ah,09h int 21h mov ah,02h mov dh,12 mov dl,40 int 10h endm data segment result db 9 dup('$') msg1 db 'press any key $' msg2 db 0dh,0ah,'$' data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax display msg1 mov ah,01h int 21h mov dl,al xor ax,ax mov al,dl lea si,result mov bx,0ah xor cx,cx back: mov dx,0 div bx add dl,'0' push dx inc cx cmp al,0ah jge back add al,'0' mov [si],al again: inc si pop ax mov [si],al loop again mov ah,00h mov al,03h int 10h display msg2 display result mov ah,4ch int 21h code ends end start

4b: Display messages FIRE and HELP alternately with flickering effects on a 7-segment display interface for a suitable period of time. .model small .stack 50 .data porta equ 0b0c0h portb equ 0b0c1h portc equ 0b0c2h cw equ 0b0c3h fire db 0h,0h,71h,06h,77h,79h help db 76h,79h,38h,73h,0h,0h blank db 0h,0h,0h,0h,0h,0h count dw 150 addr dw ? .code mov ax,@data mov ds,ax mov dx,cw mov al,80h out dx,al rpt1: lea dx,fire mov addr,dx call display lea dx,blank mov addr,dx call display lea dx,help mov addr,dx call display lea dx,blank mov addr,dx call display mov ah,0bh int 21h or al,al jz rpt1 mov ah,4ch int 21h display proc push bx push cx mov di,count rptl2: mov si,addr mov bl,6 rptl1: mov al,bl mov dx,portc dec al out dx,al mov dx,porta lodsb out dx,al mov cx,0fff0h here: loop here dec bl jnz rptl1 dec di jnz rptl2 pop cx

end

pop bx ret display endp

5a: Reverse a given string and check whether it is a palindrome or not. data segment x db 'madam' z dw $-x m1 db 'the given string is pal $' m2 db 'the given string is not pal $' data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov es,ax mov si,0h mov bx,z dec bx mov di,bx mov cx,bx loc1: mov al,x[si] cmp x[di],al jne notpal inc si dec di dec cx jnz loc1 mov dx,offset m1 jmp loc2 notpal: mov dx,offset m2 loc2: mov ah,09h int 21h mov ah,4ch int 21h code ends end start 5b: Assume any suitable message of 12 characters length and display it in the rolling fashion on a 7-segment display interface for a suitable period of time. Ensure a flashing rate that makes it easy to read both the messages. .model small delay3 macro local b1 local b2 push ax push bx push cx push dx mov bx,05ffh b2: mov cx,0ffh b1: loop b1 dec bx jnz b2 pop dx pop cx

endm .data

pop bx pop ax CODELIST1 DB 0,0,0,0,0,0,06H,76H,0H DB 3FH,38H,38H,79H,76H,0H DB 38H,3FH,3FH,39H DB 0,0,0,0,0,0 port_a equ 0b0c0h port_b equ 0b0c1h port_c equ 0b0c2h cowd equ 0b0c3h mov ax,@data mov ds,ax mov dx,cowd mov al,082h out dx,al xor cx,cx xor ax,ax mov si,17 mov BX,offset codelist1 mov ch,50 xor cl,cl con1: mov dx,port_c mov al,cl out dx,ax XLAT mov dx,port_a out dx,ax delay3 inc cl cmp cl,06h jne con1 dec ch jnz step inc bx dec si jnz nxt PUSH AX MOV AH,0BH INT 21H OR AL,AL POP AX JZ AGAIN mov ah,04ch int 21h

.code

AGAIN: nxt: step:

end

6a: Read two strings, store them in locations STR1 and STR2. Check whether they are equal or not and display appropriated messages. Also display the length of the stored strings. dispmsg macro p1 mov ah,09h lea dx,p1 int 21h endm read_string macro p2 mov ah,0ah

endm convert macro local next1 cmp dl,0ah jl next1 add dl,07h next1: add dl,30h mov ah,02h int 21h endm display macro p1 mov dl,p1 and dl,0f0h shr dl,cl convert mov dl,p1 and dl,0fh convert endm assume cs:code, ds:data, es:stack stack segment data segment m1 db 'enter the 1st string= $' m2 db 'enter the 2nd string= $' m3 db 'length of 1st string= $' m4 db 'length of 2nd string= $' m5 db 'str1 is equal to str2',10,13,'$' m6 db 'str1 is not equal to str2',10,13,'$' m7 db ' ',10,13,'$' str1 db 50 db 00 db 10 dup (0) str2 db 50 db 00 db 10 dup (0) data ends stack ends code segment start: mov ax,data mov ds,ax mov cl,04h dispmsg m1 read_string str1 dispmsg m7 dispmsg m3 display str1+1 dispmsg m7 dispmsg m2 read_string str2 dispmsg m7 dispmsg m4 display str2+1 dispmsg m7 mov ch,00h mov cl,str2+1 lea si,str1 lea di,str2 next2: mov ax,[si]

lea dx,p2 int 21h

term: stop:

cmp ax,[di] jnz term inc si inc di loop next2 dispmsg m5 jmp stop dispmsg m6 endm .data

dec cl jnz bck mov cx,06h bck2: mov al,00h mov [si],al inc si dec cx jnz bck2 codelist1 db 03fh,06h,05bh,04fh,066h,06dh,07dh,07h,07fh,06f h buffer db 10 dup(?) port_a equ 0b0c0h port_b equ 0b0c1h port_c equ 0b0c2h cowd equ 0b0c3h count equ 2 mov ax,@data mov ds,ax convert 0001h mov dx,cowd mov al,082h out dx,al mov bp,count xor cx,cx xor ax,ax mov si,10d mov bx,offset buffer mov ch,050d xor cl,cl mov dx,port_c mov al,cl out dx,ax xlat mov dx,port_a out dx,ax delay3 inc cl cmp cl,06h jne con3 dec ch jnz step1 inc bx dec si jnz nxt1 xor cx,cx xor ax,ax mov si,010d mov bx,offset buffer ADD BX,9D mov ch,050d MOV CL,00D MOV DI,00D

mov ah,4ch int 21h code ends end start 6b: Convert a 16-bit binary value (assumed to be an unsigned integer) to BCD and display it from left to right and right to left for specified number of times on a 7segment display interface. .model small delay3 macro local b1 local b2 push ax push bx push cx push dx mov bx,05ffh b2: mov cx,0ffh b1: loop b1 dec bx jnz b2 pop dx pop cx pop bx pop ax endm convert macro num local bck local bck1 local bck2 mov ax,num xor dx,dx mov cx,05h mov si,offset buffer bck1: mov bl,00h mov [si],bl inc si dec cx jnz bck1 mov cx,05h mov bx,offset codelist1 bck: xor dx,dx push bx mov bx,0ah div bx pop bx push ax mov al,dl xlat mov [si],al inc si pop ax

.code

check:

nxt1: step1: con3:

nxt: step: con1:

stp: end

mov dx,port_c mov al,cl out dx,ax MOV AX,DI xlat mov dx,port_a out dx,ax delay3 INC cl INC DI cmp cl,06h jne con1 dec ch jnz step DEC bx dec si jnz nxt MOV DX,0b0C3H MOV AX,082H OUT DX,AX dec bp jz stp call check mov ah,04ch int 21h

place 010h,00h mov ah,4ch int 21h code ends end start 7b: Drive a Stepper Motor interface to rotate the motor in clockwise direction by N steps (N is specified by the examiner). Introduce suitable delay between successive steps. .model small .stack 50 .data porta equ 0b0c0h portb equ 0b0c1h portc equ 0b0c2h cw equ 0b0c3h n dw 200 .code mov ax,@data mov ds,ax mov dx,cw mov al,80h out dx,al mov cx,n mov al,0eeh rpt: mov dx,portc out dx,al call delay ror al,01h loop rpt mov ah,4ch int 21h delay proc push cx push bx mov cx,0fffh l2: mov bx,0fffh l1: dec bx jnz l1 loop l2 pop bx pop cx ret delay endp end 8a: Compute the factorial of a positive integer n using recursive procedure. data segment n db 06h res dw ? data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov ax,01h mov bl,n

7a: Read your name from the keyboard and display it at a specified location on the screen in front of the message What is your name? You must clear the entire screen before display. place macro x,y mov ah,02h mov dh,x mov dl,y int 10h endm disp_msg macro p1 mov ah,09h lea dx,p1 int 21h endm read_string macro p2 mov ah,0ah lea dx,p2 int 21h endm assume cs:code,ds:data data segment m2 db 'what is your name?','$' str1 db 50 data ends code segment start: mov ax,data mov ds,ax mov ah,00h mov al,02h int 10h place 010h,018h disp_msg m2 read_string str1

store1:

cmp bl,00h je store1 call fact mov res,ax mov ah,4ch int 21h fact proc cmp bx,01h je next push bx dec bx call fact pop bx mul bx ret

end

ret delay endp

mov ax,01h ret fact endp code ends end start 8b: Drive a stepper motor interface to rotate the motor in anticlockwise direction by N steps (N is specified by the examiner). Introduce suitable delay between successive steps. .model small .stack 50 .data porta equ 0b0c0h portb equ 0b0c1h portc equ 0b0c2h cw equ 0b0c3h n dw 200 .code mov ax,@data mov ds,ax mov dx,cw mov al,80h out dx,al mov cx,n mov al,0eeh rpt: mov dx,portc out dx,al call delay rol al,01h loop rpt mov ah,4ch int 21h delay proc push cx push bx mov cx,0fffh l2: mov bx,0fffh l1: dec bx jnz l1 loop l2 pop bx pop cx

next:

9a: Compute nCr using recursive procedure. Assume that n and r are non-negative integers. data segment n dw 4 r dw 2 res1 dw (?) data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov bx,n mov cx,r mov ax,01h call ncr mov res1,ax mov ah,4ch int 21h ncr proc cmp cx,00h jle l1 push cx push bx dec cx dec bx call ncr pop bx mul bx pop cx div cx l1: ret ncr endp code ends end start 9b: Drive a stepper motor interface to rotate the motor by N steps left direction and N steps right direction (N is specified by the examiner). Introduce suitable delay between successive steps. .model small .stack 50 .data porta equ 0b0c0h portb equ 0b0c1h portc equ 0b0c2h cw equ 0b0c3h n dw 200 .code mov ax,@data mov ds,ax mov dx,cw mov al,80h out dx,al mov cx,n mov al,0eeh rpt1: mov dx,portc

rpt2:

out dx,al call delay rol al,01h loop rpt1 mov cx,n mov dx,portc out dx,al call delay ror al,01h loop rpt2 mov ah,4ch int 21h delay proc push cx push bx mov cx,0fffh mov bx,0fffh dec bx jnz l1 loop l2 pop bx pop cx ret delay endp

exit:

lea dx,m1 mov ah,09h int 21h mov ah,4ch int 21h

end

l2: l1:

end

10a: Find out whether a given sub-string is present or not in a main string of characters. .model small .stack 50 .data s1 db 'abcdef' l1 dw ($-s1) s2 db 'xde' l2 dw ($-s2) m1 db 13,10,'search successful $' m2 db 13,10,'search unsuccessful $' .code mov ax,@data mov ds,ax mov es,ax mov bx,l1 sub bx,l2 inc bx lea si,s1 lea di,s2 rpt: push si push di mov cx,l2 repe cmpsb pop di pop si je succ inc si dec bx jnz rpt lea dx,m2 jmp exit succ:

10b: Scan a 8 x 3 keypad for key closure and to store the code of the key pressed in a memory location or display on screen. Also display row and column numbers of the key pressed. dm macro msg lea dx,msg mov ah,09h int 21h endm .model small .stack .data pa equ 0b0c0h pb equ 0b0c1h pc equ 0b0c2h cr equ 0b0c3h m1 db 10,13,10,13, 'entered key is =$' m2 db 10,13,10,13, 'row number is =$' m3 db 10,13,10,13, 'column number is =$' m4 db 10,13, 'press any key from interface $' row db ? col db ? cw db 90h .code mov ax,@data mov ds,ax mov dx,cr mov al,cw out dx,al dm m4 start: mov al,80h mov row,1 mov col,1 mov ch,0 mov bl,3 nr: rol al,1 mov bh,al mov dx,pc out dx,al mov cl,8 mov dx,pa in al,dx nc: ror al,1 jc display inc ch inc col dec cl jnz nc mov col,1 inc row mov al,bh dec bl

start2:

jnz nr jmp start display: dm m1 mov dl,ch cmp dl,0ah jc digit add dl,07h add dl,30h call dc add row,30h add col,30h dm m2 mov dl,row call dc dm m3 mov dl,col call dc mov ah,4ch int 21h dc proc mov ah,02h int 21h ret dc endp

digit:

end

11a: Generate the first n Fibonacci numbers. data segment fib dw 100 dup(0) data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov cx,0bh mov ax,00h mov bx,01h lea si,fib mov [si],ax dec cx jz last inc si mov [si],bx dec cx jz last inc si up: add ax,bx mov [si],ax mov ax,bx mov bx,[si] inc si dec cx jnz up last: mov ah,4ch int 21h code ends end start

11b: Scan a 8 x 3 keypad for key closure and simulate ADD and SUBTRACT operations as in a calculator. outpc macro mov dx,pc out dx,al endm inps macro mov dx,pa in al,dx endm dispmsg macro msg mov ah,09h lea dx,msg int 21h endm exit macro mov ah,4ch int 21h endm .model small .stack .data pa equ 0b0c0h pb equ 0b0c1h pc equ 0b0c2h cr equ 0b0c3h a db 4 dup (?) keyno db ? errmsg db 10,13,'ERROR $' msg db 10,13,'Enter expression',10,13,'$' flag db 0 cw db 90h .code mov ax,@data mov ds,ax mov al,cw mov dx,cr out dx,al dispmsg msg mov di,4 lea si,a back: call read call delay mov al,keyno mov [si],al inc si dec di jnz back cmp a[1],0ah jz addn cmp a[1],0bh jz subn jmp err exit addn: mov al,a add al,a[2] cmp a[3],0eh jnz err call disp exit err:

subn:

dispmsg errmsg exit mov al,a sub al,a[2] jne positive neg al mov flag,1

skip:

jnz skip push ax mov dl,'-' mov ah,02h int 21h pop ax aam add ax,3030h mov bx,ax mov ah,02h mov dl,bh int 21h mov dl,bl int 21h ret disp endp delay proc near mov bx,01ffh mov cx,0ffffh loop b1 dec bx jnz b2 ret delay endp

positive:

cmp a[3],0eh jnz err call disp exit read proc mov al,80h mov keyno,0 mov bl,3 nextrow: rol al,1 mov bh,al outpc mov cl,8 inps nextcol: ror al,1 jc other3 inc keyno dec cl jnz nextcol mov al,bh dec bl jnz nextrow jmp read other3: mov dl,keyno cmp dl,0ah jnz next mov dl,'+' mov ah,02h int 21h ret next: cmp dl,0bh jnz next1 mov dl,'-' mov ah,02h int 21h ret next1: cmp dl,0eh jnz next2 mov dl,'=' mov ah,02h int 21h ret next2: add dl,30h mov ah,02h int 21h ret read endp disp proc near cmp flag,1

b2: b1:

end

12a: Read the current time from the system and display it in the standard format on the screen. .model small disp macro mov ah,02h mov dl,bh int 21h mov dl,bl int 21h endm .code mov ax,@data mov ds,ax mov ah,2ch int 21h mov al,ch aam mov bx,ax add bx,3030h disp mov dl,':' mov ah,02h int 21h mov al,cl aam mov bx,ax add bx,3030h disp mov dl,':' mov ah,02h int 21h mov al,dh aam mov bx,ax

end

add bx,3030h disp mov ah,4ch int 21h

12b: Generate the Sine Wave using DAC interface (The output of the DAC is to be displayed on the CRO). .model small .stack .data table db 80h,96h,0abh,0c0h,0d2h,0e2h,0eeh,0f8h,0feh,0ffh db 0feh,0f8h,0eeh,0e2h,0d2h,0c0h,0abh,96h,80h db 80h,69h,54h,40h,2dh,1dh,11h,07h,01h,00h db 00h,01h,07h,11h,1dh,2dh,40h,54h,69h,80h base equ 0b0c0h pa equ 0b0c0h pb equ 0b0c1h cw equ 0b0c3h msg db 0ah ,0dh,'press any key $',0ah,0dh .code mov ax,@data mov ds,ax mov al,80h mov dx,cw out dx,al lea dx,msg mov ah,09h int 21h again: mov cx,38 lea si,table back: mov al,[si] mov dx,pa out dx,al call delay inc si loop back mov ah,0bh int 21h or al,al jz again mov ah,4ch int 21h delay proc near mov bx,0fffh m1: dec bx jnz m1 ret delay endp end 13a: Program to simulate a Decimal Up-counter to display 00-99. .model small cls macro local rpt1 mov cx,125*180 mov ah,02h mov dl,' '

endm setcursor macro r,c mov ah,02h mov dh,r mov dl,c int 10h endm .data msg db 'decimal upcounter $' .code mov ax,@data mov ds,ax cls mov cx,3030h rpt1: setcursor 9,20 lea dx,msg mov ah,09h int 21h mov ah,02h setcursor 9,40 mov dl,ch int 21h mov dl,cl int 21h call delay inc cl cmp cl,3ah jb rpt1 mov cl,30h inc ch cmp ch,3ah jb rpt1 mov ah,4ch int 21h delay proc push cx push bx mov cx,0fffh l2: mov dx,0fffh l1: dec bx jnz l1 loop l2 pop bx pop cx ret delay endp end 13b: Generate a Half Rectified Sine wave form using the DAC interface. (The output of the DAC is to be displayed on the CRO). .model small .stack 50 .data porta equ 0b0c0h portb equ 0b0c1h portc equ 0b0c2h cw equ 0b0c3h

rpt1:int 21h loop rpt1

.code

x db 80h,90h,0a1h,0b1h,0c0h,0cdh db 0dah,0e5h,0eeh,0f6h,0fbh,0feh,0ffh db 0feh,0fbh,0f6h,0eeh,0e5h,0dah db 0cdh,0c0h,0b1h,0a1h,90h,80h db 80h,80h,80h,80h,80h,80h,80h,80h,80h db 80h,80h,80h,80h,80h len dw $-x mov ax,@data mov ds,ax mov al,80h mov dx,cw out dx,al mov bp,07h mov bx,0ffffh mov cx,len lea si,x mov dx,porta mov al,[si] out dx,al inc si loop l1 dec bx jnz l2 dec bp jnz again mov ah,4ch int 21h end

again: l2:

int 21h mov ah,4ch int 21h read proc mov ah,01h int 21h and al,0fh mov bl,al mov ah,01h int 21h and al,0fh mov ah,bl aad ret read endp

l1:

end

14a: Read a pair of input co-ordinates in BCD and move the cursor to the specified location on the screen. disp macro msg lea dx,msg mov ah,09h int 21h endm .model small .stack .data msg1 db 10,13,"enter row no: $" msg2 db 10,13,"enter col no: $" msg3 db 10,13,"press any key to quit $" row db ? col db ? .code mov ax,@data mov ds,ax disp msg1 call read mov row,al disp msg2 call read mov col,al disp msg3 mov ah,02h mov dh,row mov dl,col int 10h mov ah,8

14b: Generate a Fully Rectified Sine waveform using the DAC interface. (The output of the DAC is to be displayed on the CRO). .model small .stack 50 .data porta equ 0b0c0h portb equ 0b0c1h portc equ 0b0c2h cw equ 0b0c3h x db 80h,90h,0a1h,0b1h,0c0h,0cdh db 0dah,0e5h,0eeh,0f6h,0fbh,0feh,0ffh db 0feh,0fbh,0f6h,0eeh,0e5h,0dah db 0cdh,0c0h,0b1h,0a1h,90h,80h len dw $-x .code mov ax,@data mov ds,ax mov al,80h mov dx,cw out dx,al mov bp,07h again: mov bx,0ffffh l2: mov cx,len lea si,x mov dx,porta l1: mov al,[si] out dx,al inc si loop l1 dec bx jnz l2 dec bp jnz again mov ah,4ch int 21h end 15a: Program to create a file (input file) and to delete an existing file. display macro msg mov dx,offset msg mov ah,09h

int 21h endm data segment file1 db 25 dup(0) file2 db 25 dup(0) msg1 db 0dh,0ah,'enter file to be created $' msg2 db 0dh,0ah,'enter the file to delete $' msg3 db 0dh,0ah,'file created successfully $' msg4 db 0dh,0ah,'unable tocreate a file, already exist $' msg5 db 0dh,0ah,'file deleted successfull y $' msg6 db 0dh,0ah,'file does not exist $' data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax display msg1 lea si,file1 mov ah,01h input1: int 21h cmp al,0dh je e0i1 mov [si],al inc si jmp input1 e0i1: mov ah,5bh mov cx,00h mov dx,offset file1 int 21h jnc succ1 display msg4 jmp next1 succ1: display msg3 next1: display msg2 lea si,file2 mov ah,01h input2: int 21h cmp al,0dh je e0i2 mov [si],al inc si jmp input2 e0i2: mov ah,41h mov dx,offset file2 int 21h jne succ2 display msg6 jmp next2 succ2: display msg5 next2: mov ah,4ch mov al,00h int 21h code ends end start

15b: Drive an elevator interface in the following way: i. Initially the elevator should be in the ground floor, with all requests in OFF state. ii. When a request is made from a floor, the elevator should move to that floor, wait there for a couple of seconds, and then come down to ground floor and stop. If some requests occur during going up or coming down they should be ignored. .model small .data pa equ 0d800h pb equ 0d801h pc equ 0d802h ctrl equ 0d803h tf db 0 cf db 0 .code mov ax, @data mov ds, ax mov al, 82h mov dx, ctrl out dx, al mov cf, 0h mov al, cf or al, 0f0h mov dx, pa out dx, al start: call chk cmp al,'q' jz exit cmp al, 0feh je gfr cmp al, 0fdh je ffr cmp al, 0fbh je sfr cmp al, 0f7h je tfr jmp start exit: int 3 gfr: mov tf,0 call floor next: mov al, 0e0h mov dx, pa out dx, al jmp start ffr: mov tf, 1 call floor next1: mov al, 0d3h mov dx, pa out dx, al jmp start sfr:

next2:

mov tf,2 call floor mov al, 0b6h mov dx, pa out dx, al jmp start mov tf,3 call floor mov al, 79h mov dx, pa out dx, al jmp start mov ah, 06h mov dl, 0ffh int 21h cmp al, 'q' jnz next4 ret

tfr: next3:

chk proc

call delay ret updown endp delay proc push bx push cx mov cx,0fffh b2: mov bx, 0ffffh b1: dec bx jnz b1 loop b2 pop cx pop bx ret delay endp end

mov dx, pb in al,dx or al, 0f0h cmp al,0ffh jz chk mov tf, al ret chk endp floor proc mov al, 3 mul tf mov cl,al mov al, 03 mul cf mov ch, al cmp cl,ch je ext1 ja up back: call updown dec ch cmp cl,ch jle back jmp ext up: call updown inc ch cmp cl,ch jge up ext: mov cl, tf mov cf, cl ext1: ret floor endp updown proc mov al,ch or al, 0f0h mov dx, pa out dx, al

next4:

You might also like