Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. ; Computer Architectures (02LSEOV)
  2. ; Problem n. 2
  3. ;https://911programming.wordpress.com/2010/05/14/emu8086-read-a-string-from-keyboard/
  4. ;http://www.fysnet.net/kbbuffio.htm
  5. ;https://eclass.upatras.gr/modules/document/file.php/EE649/8086%20Registers.htm
  6. DIM EQU 40h;64 bytes
  7. MIN_L EQU 14h; 20 chars min
  8. MAX_L EQU 32h;50 chars max
  9. CAE_K EQU 03h;Caesar cipher K
  10. .MODEL small
  11. .STACK
  12. ;;data segment: it will contain the four arrays
  13. .DATA
  14. FIRST_ROW DB DIM DUP(?)
  15. SECOND_ROW DB DIM DUP(?)
  16. THIRD_ROW DB DIM DUP(?)
  17. FOURTH_ROW DB DIM DUP(?)
  18. prompt_str DB 'Please enter a string:$'
  19. oob_str DB 'Input out of bounds!$'
  20. ;;code segment
  21. .CODE
  22. .STARTUP
  23. ;;Prepare buffers: buffer[0] must be equal to buffer size.
  24. mov AH, DIM
  25. mov FIRST_ROW[0], AH
  26. mov SECOND_ROW[0], AH
  27. mov THIRD_ROW[0], AH
  28. mov FOURTH_ROW[0], AH
  29. ;;Acquire inputs
  30. lea DX, FIRST_ROW;get address of first row in DX
  31. call input_row
  32. call print; print first row
  33. .EXIT
  34.  
  35. ;;Inputs acquired.
  36. ;retrieves user input into a buffer, which is passed as the argument
  37. ; input_row( DX = buffer, )
  38. PROC input_row NEAR
  39. push BP
  40. mov SP, BP
  41. push AX
  42. push BX
  43. push SI
  44. ;print input prompt
  45. lea DX, prompt_str
  46. call print
  47. ;initialize counter for input'd chars to 0
  48. mov CL, 0
  49. ;use SI as base address for the string
  50. mov SI, DX
  51. ;use BX as a pointer from the base address of the string
  52. mov BX, 0
  53. ;INT 21 AL 1: get single char, then display it
  54. input_loop:
  55. mov AH, 1
  56. INT 21h;result is stored in AL
  57. ;Check it is not return
  58. ;Which would indicate the end of input
  59. cmp AL,13; 13 = RETURN
  60. je check_length
  61. ;Store input'd character in the string
  62. mov [SI][BX], al
  63. ;Move the pointer 1 position forward
  64. inc BX
  65.  
  66. check_length:
  67. input_row_end:
  68. pop SI
  69. pop BX
  70. pop AX
  71. pop BP
  72. ret
  73. ;return values
  74. ;1st byte of the buffer = buffer size
  75. ;2nd byte of the buffer = string length (input'd characters)
  76. ENDP
  77. ;prints a string.
  78. ; print( DX = buff )
  79. PROC print NEAR
  80. push bp
  81. mov sp, bp
  82. push ax
  83. mov ah, 9
  84. int 21h
  85. pop ax
  86. pop bp
  87. ret
  88. ENDP
  89. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement