Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .model small
- .data
- m1 db 'type a character :','$'
- m2 db 0ah,0dh,'the ascii code of '
- c1 db ?,' in binary is :','$'
- m3 db 0ah,0dh,'the number of 1 bit is '
- c2 db ?,'$'
- .code
- main proc
- mov ax,@data
- ;initialize ds
- mov ds,ax
- mov ah,9
- ;prompt the user
- lea dx,m1
- int 21h
- ;-------------
- mov ah,1
- ;read character
- int 21h
- mov bl,al
- mov c1,al
- ;store character
- mov ah,9
- lea dx,m2
- int 21h
- mov bh,0
- ;counter for one’s
- mov cx,8
- mov ah,2
- l1: shl bl,1
- ;display content of bl
- jc l2
- mov dl,'0'
- int 21h
- jmp l4
- l2: mov dl,'1'
- int 21h
- inc bh
- ;count number of one’s
- l4: loop l1
- add bh,30h
- ;convert to char.
- mov c2,bh
- mov ah,9
- ;display number of one’s
- lea dx,m3
- int 21h
- mov ah,4ch
- ;return to dos
- int 21h
- main endp
- end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement