Advertisement
Guest User

Untitled

a guest
Oct 10th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. .model small
  2. .stack
  3. .code
  4. main proc
  5. ;call read_char
  6. call cr_lf
  7. ;call read_decimal
  8. call read_binary
  9. call write_binary
  10. call cr_lf
  11. call write_hexa
  12. call cr_lf
  13. call write_decimal
  14. mov AH, 4ch
  15. int 21h
  16. main endp
  17.  
  18. read_char proc
  19. push AX
  20. mov AH,1h ;inputkod
  21. int 21h
  22. mov DL, AL
  23. pop AX
  24. ret
  25. read_char endp
  26.  
  27. write_char proc
  28. push AX
  29. mov AH,2
  30. int 21h
  31. pop AX
  32. ret
  33. write_char endp
  34.  
  35. write_binary proc
  36. push BX
  37. push CX
  38. push DX
  39. mov BL, DL ;a DLt fogjuk alakitgatni, igy nem art lementeni a BLbe
  40. mov CX, 8 ;counter regiszter, 8x akarjuk a loopot
  41. binary_digit:
  42. xor DL, DL ;a kizaro vaggyal ki tudjuk nullazni a regisztert, hiszen onmagaval alkalmazva 0z
  43. rcl BL, 1 ;1-el valo rotalas mukodik konstansal, ha tobbet szeretnenk akkor a masodik param is regiszter kene h legyen
  44. adc DL, '0' ;add (carryvel) DL + 48 + carry
  45. call write_char
  46. loop binary_digit
  47. pop DX
  48. pop CX
  49. pop BX
  50. ret
  51. write_binary endp
  52.  
  53. CR equ 13
  54. LF equ 10
  55. cr_lf proc
  56. push dx
  57. mov DL, CR
  58. call write_char
  59. mov DL, LF
  60. call write_char
  61. pop dx
  62. ret
  63. cr_lf endp
  64.  
  65. write_hexa proc
  66. push cx
  67. push dx
  68. mov DH, DL
  69. mov CL, 4
  70. SHR DL, CL
  71. call write_hexa_digit
  72. mov DL, DH
  73. AND DL, 0FH
  74. call write_hexa_digit
  75. pop DX
  76. pop CX
  77. RET
  78. write_hexa endp
  79.  
  80. write_hexa_digit proc
  81. push DX
  82. CMP DL, 10
  83. JB no_hexa_digit
  84. ADD DL, 'A' - '0' - 10
  85. no_hexa_digit:
  86. ADD DL, '0'
  87. call write_char
  88. pop DX
  89. RET
  90. write_hexa_digit endp
  91.  
  92. write_decimal proc
  93. push AX
  94. push CX
  95. push DX
  96. push SI
  97. xor DH, DH
  98. mov AX, DX
  99. mov SI, 10
  100. xor CX, CX
  101. decimal_non_zero:
  102. xor DX, DX
  103. DIV SI
  104. push DX
  105. INC CX
  106. or AX, AX
  107. JNZ decimal_non_zero
  108. decimal_loop:
  109. pop DX
  110. call write_hexa_digit
  111. loop decimal_loop
  112. pop SI
  113. pop DX
  114. pop CX
  115. pop AX
  116. ret
  117. write_decimal endp
  118.  
  119. read_decimal proc
  120. push ax
  121. push bx
  122. mov bl, 10
  123. xor ax, ax
  124. r_d_new:
  125. call read_char
  126. cmp dl, cr
  127. je r_d_end
  128. mul bl
  129. sub dl,'0'
  130. add al, dl
  131. jmp r_d_new
  132. r_d_end:
  133. mov dl, al
  134. pop ax
  135. pop ax
  136. ret
  137. read_decimal endp
  138.  
  139. read_binary proc
  140. push ax
  141. xor ax,ax
  142. r_b_new:
  143. call read_char
  144. cmp dl,cr
  145. je r_b_end
  146. sub dl, '0'
  147. sal al, 1
  148. add al, dl
  149. jmp r_b_new
  150. r_b_end:
  151. mov dl,al
  152. pop ax
  153. ret
  154. read_binary endp
  155.  
  156. END main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement