Advertisement
Farhana_Zaman

Untitled

Jun 7th, 2023
1,702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .model small
  2. .data
  3. m1 db 0ah,0dh,'type a character :','$'
  4. m2 db 0ah,0dh,'the ascii code of '
  5. c1 db ?,' in hexa is ','$'
  6. .code
  7. main proc
  8. mov ax,@data
  9. ;intialize ds
  10. mov ds,ax
  11. ;------------
  12. begin: mov ah,9
  13. ;prompt user
  14. lea dx,m1
  15. int 21h
  16. mov ah,1
  17. ;read char.
  18. int 21h
  19. cmp al,0dh
  20. ;if cr exit
  21.  
  22. je out_
  23. mov c1,al
  24. ;store char
  25. .
  26. mov bl,al
  27. ;take a copy of char
  28. mov ah,9
  29. ;display 2
  30.  
  31. lea dx,m2
  32.  
  33.  
  34. int 21h
  35.  
  36. mov cl,4
  37. shr c1,cl
  38. ;prapare for display 1
  39.  
  40.  
  41. ;* note below
  42. add c1,30h
  43. ;convert to char.
  44.  
  45. mov dl,c1
  46. jmp exe1
  47. continue: and bl,0fh
  48. ;convert 2
  49.  
  50.  
  51. cmp bl,9
  52. ;if >9 mean a,b,cā€¦..hex ch.
  53. jg error_
  54. add bl,30h
  55. ;convert to char
  56. .
  57. mov dl,bl
  58. jmp exe2
  59. exe1: mov ah,2
  60. ;1
  61.  
  62.  
  63. int 21h
  64. jmp continue
  65. exe2: mov ah,2
  66. int 21h
  67.  
  68.  
  69. jmp begin
  70. ;ask if you want to do it again
  71.  
  72. ;------------
  73. error_: add bl,37h
  74. ;convert to a,b,cā€¦. hexa ch
  75. .
  76. mov dl,bl
  77. mov ah,2
  78. ;display it
  79.  
  80. int 21h
  81.  
  82. jmp begin
  83. ;ask if you want to do it again
  84.  
  85. out_: mov ah,4ch
  86. ;return to dos
  87. int 21h
  88. main endp
  89. end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement