Advertisement
Farhana_Zaman

Untitled

Jun 7th, 2023
689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. .model small
  2. .data
  3. m1 db 'type a character :','$'
  4. m2 db 0ah,0dh,'the ascii code of '
  5. c1 db ?,' in binary is :','$'
  6. m3 db 0ah,0dh,'the number of 1 bit is '
  7. c2 db ?,'$'
  8. .code
  9. main proc
  10. mov ax,@data
  11. ;initialize ds
  12.  
  13. mov ds,ax
  14. mov ah,9
  15. ;prompt the user
  16. lea dx,m1
  17. int 21h
  18. ;-------------
  19. mov ah,1
  20. ;read character
  21. int 21h
  22. mov bl,al
  23. mov c1,al
  24. ;store character
  25.  
  26. mov ah,9
  27.  
  28. lea dx,m2
  29. int 21h
  30.  
  31. mov bh,0
  32. ;counter for one’s
  33. mov cx,8
  34. mov ah,2
  35. l1: shl bl,1
  36. ;display content of bl
  37.  
  38. jc l2
  39. mov dl,'0'
  40. int 21h
  41. jmp l4
  42. l2: mov dl,'1'
  43. int 21h
  44. inc bh
  45. ;count number of one’s
  46. l4: loop l1
  47. add bh,30h
  48. ;convert to char.
  49. mov c2,bh
  50. mov ah,9
  51. ;display number of one’s
  52.  
  53. lea dx,m3
  54. int 21h
  55.  
  56. mov ah,4ch
  57. ;return to dos
  58. int 21h
  59. main endp
  60. end main  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement