fork download
  1. ; Assembler. Task №1.
  2. ; 13. Malashenkov Anton. group 1538. ITMO, KT.
  3. ; Variant 1. HashTable
  4.  
  5. ;cl - key/value
  6. ;ch - enter?
  7. ;bx - hash
  8.  
  9. org 100h
  10. xor cl, cl
  11. xor bx, bx
  12. xor ch, ch
  13.  
  14. ReadChar:
  15. mov ah, 01h
  16. int 21h
  17. cmp al, CODE_SPACE
  18. je Space
  19.  
  20. cmp al, CODE_ENTER
  21. je Enter_1
  22.  
  23. mov ch, 0
  24. cmp cl, 1
  25. call InsertNextCharOfValue
  26.  
  27. cmp cl, 0
  28. call CalcHash
  29.  
  30. jmp ReadChar
  31.  
  32. Enter_1:
  33. cmp ch, 1
  34. je Start
  35.  
  36. mov byte[si], '$'
  37. mov cl, 0
  38. xor ch, 1
  39. jmp ReadChar
  40.  
  41. InsertNextCharOfValue:
  42. mov [si], al
  43. inc si
  44. ret
  45.  
  46. Space:
  47. ;-------------------
  48. ; mov ah, 02h
  49. ; mov dx, bx
  50. ; int 21h
  51. ; jmp exit0
  52. ;-------------------
  53. mov cl, 1
  54. mov di, HashTable
  55. mov si, HashTable
  56. while_bx_nz_1:
  57. cmp bx, 0
  58. je end_while_1
  59.  
  60. add di, LENGTH_WORDS
  61. dec bx
  62. jmp while_bx_nz_1
  63.  
  64. end_while_1:
  65. mov si, di
  66. jmp ReadChar
  67.  
  68. CalcHash:
  69. ;hash = (hash * 29 + s[i]) % 1543, where s[i] - iый символ ключа
  70. push cx
  71.  
  72. imul bx, 29
  73. mov di, SIZE_HASH_TABLE
  74. mov ax, bx
  75. div di
  76. mov bx, dx
  77.  
  78. pop cx
  79. ret
  80.  
  81. Start:
  82. xor ch, ch
  83. xor bx, bx
  84.  
  85. ReadQuery:
  86. mov ah, 01h
  87. int 21h
  88. cmp al, CODE_ENTER
  89. je Enter_2
  90.  
  91. call CalcHash
  92. mov ch, 0
  93. jmp ReadQuery
  94.  
  95. Enter_2:
  96. cmp ch, 1
  97. je exit0
  98.  
  99. mov ch, 1
  100.  
  101. FindValue:
  102. mov di, HashTable
  103. while_bx_nz_2:
  104. cmp bx, 0
  105. je end_while_2
  106.  
  107. add di, LENGTH_WORDS
  108. dec bx
  109. jmp while_bx_nz_2
  110.  
  111. end_while_2:
  112. mov ah, 9
  113. mov dx, di
  114. int 21h
  115.  
  116. mov ah, 9
  117. mov dx, NewLine
  118. int 21h
  119.  
  120. jmp ReadQuery
  121.  
  122. exit0:
  123. mov ax, 4c00h
  124. int 21h
  125.  
  126. HashTable: rb (SIZE_HASH_TABLE * LENGTH_WORDS)
  127. NewLine: db 13, 10, '$'
  128.  
  129. CODE_ENTER = 13
  130. CODE_SPACE = 32
  131. LENGTH_WORDS = 16
  132. SIZE_HASH_TABLE = 1543
  133.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.asm:9: error: parser: instruction expected
prog.asm:126: error: parser: instruction expected
prog.asm:129: error: parser: instruction expected
prog.asm:130: error: parser: instruction expected
prog.asm:131: error: parser: instruction expected
prog.asm:132: error: parser: instruction expected
stdout
Standard output is empty