Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. code segment
  2. assume cs:code, ss:stosik, ds:dane
  3. mov ax,dane
  4. mov ds,ax
  5. mov ax,stosik
  6. mov ss,ax
  7. mov sp,offset szczyt
  8. ;tak
  9. mov ah,09h ;usł. wysw string
  10. lea dx,tx1 ;wczytaj adres efektywny tx1
  11. int 21h
  12. mov ah,0Ah ;wczytanie lancucha
  13. lea dx,max ;il znaków do ah
  14. int 21h
  15. mov ah,09h
  16. lea dx,crlf
  17. int 21h
  18. ;zerowanie
  19. xor ax,ax
  20. xor bx,bx
  21. xor cx,cx
  22. xor dx,dx
  23. mov cl,len ;len faktyczna dlugosc
  24.  
  25. testDlugosc:
  26. cmp len,0
  27. je pusty
  28. jmp testCzyLiczba
  29.  
  30. pusty:
  31. mov ah,09h
  32. lea dx,err1
  33. int 21h
  34. mov ax,4c03h
  35. int 21h
  36.  
  37. testCzyLiczba:
  38. mov dl,tab[bx]
  39. cmp dl,'0'
  40. jl blednaLiczba
  41. cmp dl,'9'
  42. jg blednaLiczba
  43. inc bx
  44. loop testCzyLiczba
  45. xor bx,bx
  46. mov cl,len
  47. jmp testZakres
  48.  
  49. blednaLiczba:
  50. mov ah,09h
  51. lea dx,err2
  52. int 21h
  53. mov ax,4c02h
  54. int 21h
  55.  
  56. testZakres:
  57. mov dx,10
  58. mov ax,suma
  59. mul dx
  60. jc przekroczono ;test overflow dla mnozenia
  61. mov dh,0
  62. mov dl,tab[bx]
  63. sub dx,'0'
  64. add ax,dx
  65. jc przekroczono ;test carry dla dodawania (add nie ustawia O)
  66. mov suma,ax
  67. inc bx
  68. loop testZakres
  69. jmp wypiszDec
  70.  
  71. przekroczono:
  72. mov ah,09h
  73. lea dx,err3
  74. int 21h
  75. mov ax,4c03h
  76. int 21h
  77.  
  78. ;jesli poprawny zakres, wypisz dziesietnie
  79. wypiszDec:
  80. mov ah,09h
  81. lea dx,txD ;text Decimal
  82. int 21h
  83. lea dx,tab
  84. int 21h
  85. lea dx,txB
  86. int 21h
  87. ;liczba binarnie
  88.  
  89. ;ilosc znakow do przejscia binarnie
  90. ;maska 1
  91. mov ah,02h
  92. mov cx,16
  93. mov bx,suma
  94. wypiszBin:
  95. rol bx,1
  96. push bx
  97. and bx,1
  98. add bx,'0'
  99. mov dl,bl
  100. int 21h
  101. pop bx
  102.  
  103. loop wypiszBin
  104.  
  105. mov ah,09h
  106. lea dx,txH
  107. int 21h
  108.  
  109. mov ah,02h
  110. ;liczba hex
  111. mov cx,4 ;4x 4znaki
  112. mov bx,suma
  113. wypiszHex:
  114. rol bx,4
  115. push bx
  116. and bx,15
  117. mov dl,hex[bx]
  118. int 21h
  119. pop bx
  120. loop wypiszHex
  121. ;koniec
  122. mov ax,4c00h
  123. int 21h
  124. code ends
  125.  
  126. dane segment
  127. tx1 db 10,13,'Wpisz liczbe (0-65535): $'
  128. err1 db 10,13,'Podany ciag jest pusty!$'
  129. err2 db 10,13,'Podany ciag nie jest liczba!$'
  130. err3 db 10,13,'Podana liczba jest za duza!$'
  131. txD db 'Liczba dziesietnie: $'
  132. txB db 10,13,'Liczba binarnie: $'
  133. txH db 10,13,'Liczba szesnastkowo: $'
  134. hex db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
  135. crlf db 10,13,'$'
  136. max db 6
  137. len db ?
  138. tab db 7 dup('$')
  139. suma dw 0 ;liczba dziesietnie
  140. db '$'
  141. dane ends
  142.  
  143. stosik segment
  144. dw 100h dup(0)
  145. szczyt Label word
  146. stosik ends
  147. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement