You are on page 1of 4

Digital Assignment – 5

CAT 1 Examination
CSE2006 – Microprocessor and Interfacing Lab
Name: Shankha Shubhra Sarkar
ID: 18BCE2453

Question: 1(a). Emulate a counter on emu8086, to count the no. of 1’s


(binary) in the given input value.
Code:
;program to count number of binary 1s
data segment
    data1 db ? 
    msg1 db 10,13,"enter the number: $"
    msg3 db 10,13,"number of 1s are: $"
data ends   
 
assume cs:code,ds:data
code segment
start: mov ax,data
       mov ds,ax
       sub bl,bl
       
       lea dx,msg1         ;load address of msg1 into dx
       mov ah,9h           ;interrupt to display contents of dx
       int 21h
       
       mov ah,1h           ;read a character from console
       int 21h
       sub al,30h          ;converting from ascii into bcd form
       
       mov dl,8h           ;set up count register
again: rol al,1
       jnc next            ;conditional jump if carry flag is 0
       inc bl              ;number of 1s
 next: dec dl
       jnz again           ;short jump if del is not zero
       
       lea dx,msg3         ;print msg3
       mov ah,9h
       int 21h
           
       mov ah,2h           ;print number of 1s
       add bl,30h
       mov dl,bl                                
       int 21h
       
exit: mov ah,04ch
      mov al,0
      int 21h 
      
code ends
end start

Output:

Question: 1(b). Emulate water level controller on emu8086 for the


following Specifications:
a. No. of water levels in the overhead tank is 8
b. Display the current level of water with a buzzer
c. Switch on the motor if the water level is 1
d. Switch off the motor if the water level is 8
e. Switch on the buzzer on water overflow
Code:
DATA SEGMENT
    msg1 db 10,13,"The water level is: $"
    msg2 db 10,13,"Switch ON motor. $"
    msg3 db 10,13,"Switch OFF motor. $"
    msg4 db 10,13,"Water overflow! $"
DATA ENDS

CODE SEGMENT
    ASSUME DS:DATA,CS:CODE

START: mov AX,@data ;intialize data segment
       mov DS,AX
       
       mov CL,1H

L1:    lea DX,msg1  ;displaying water level message
       mov AH,9H
       int 21H
       
       add CL,30H   ;ASCII adjust before displaying
       mov DL,CL
       mov AH,2H    ;display
       int 21H
       sub CL,30H   ;ASCII adjust after displaying

       cmp CL,8H    ;switch off motor
       je off       ;jump to off if = 8
       
       cmp CL,1H    ;switch on motor
       je on        ;jump to on if = 1
       
back:  inc CL       ;increase water level by 1
       cmp CL,8H    ;check if water level is overflowing
       jle l1
       
       jmp exit
       
on:    lea DX,msg2
       mov AH,9h
       int 21H
       jmp back
       
off:   lea DX,msg3
       mov AH,9h
       int 21H
       lea DX,msg4  ;displaying overflow 
       mov AH,9H
       int 21H
       jmp back

exit:  mov AH,4CH
       int 21H              
       
CODE ENDS
END START

Output:

You might also like