Advertisement
salmancreation

counting

Dec 7th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1.  
  2. ; o counting
  3. .MODEL SMALL
  4. .DATA
  5. M1 DB 'TYPE A CHARACTER :','$'
  6. M2 DB 0AH,0DH,'THE ASCII CODE OF '
  7. C1 DB ?,' IN BINARY IS :','$'
  8. M3 DB 0AH,0DH,'THE NUMBER OF 1 BIT IS '
  9. C2 DB ?,'$'
  10. .CODE
  11. MAIN PROC
  12. MOV AX,@DATA
  13. ;Initialize DS
  14. MOV DS,AX
  15. MOV AH,9
  16. ;prompt the user
  17. LEA DX,M1
  18. INT 21H
  19. ;-------------
  20. MOV AH,1
  21. ;read character
  22. INT 21H
  23. MOV BL,AL
  24. MOV C1,AL
  25. ;store character
  26. MOV AH,9
  27. ;display results
  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. JC L2
  38. MOV DL,'0'
  39. INT 21H
  40. INC BH
  41. JMP L4
  42. L2: MOV DL,'1'
  43. INT 21H
  44.  
  45. ;count number of one’s
  46. L4:
  47. LOOP L1
  48. ADD BH,30H
  49. ;convert to char.
  50. MOV C2,BH
  51. ;display number of one’s
  52. MOV AH,9
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement