Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .model small
  2. .data
  3.        
  4.         MyString db 28h dup (0) ;Designated array for String to be stored in
  5.         MyChar db ?
  6.  
  7. .stack 100h
  8. .code
  9.  
  10. main:
  11.    
  12.  
  13.     call Initsegs
  14.     call ReadString
  15.     mov DX, OFFSET MyString
  16.     call Print
  17.     call exit
  18.  
  19.  
  20.     ;== PROCS Section ==
  21.    
  22.     PROC Initsegs
  23.     push ax
  24.  
  25.         mov ax, @data
  26.         mov ds,ax
  27.         mov es,ax
  28.  
  29.     pop ax
  30.    
  31.     RET
  32.     ENDP Initsegs
  33.  
  34.     PROC GetChar
  35.     push AX
  36.  
  37.         mov AH, 1
  38.         INT 21h
  39.         mov MyChar, AL      ;Save Char that was entered
  40.  
  41.         cmp MyChar, 13      ;See if its the Return key
  42.         jnz dont_set        ;If it isn't, do nothing more.
  43.         stc         ;Set Carry Flag
  44.  
  45.     dont_set:
  46.        
  47.     pop AX
  48.  
  49.     RET
  50.     ENDP GetChar
  51.  
  52.     PROC ReadString
  53.     push AX BX
  54.  
  55.         clc         ;Clear the Carry Flag
  56.         mov bx, OFFSET MyString
  57.     redo:
  58.         call GetChar
  59.         jc done         ;If the Carry Flag is set, String is finished.
  60.         mov AL, MyChar      ;Move the stored Char into AL
  61.         mov [BX], AL        ;Move Char into next available slot in array
  62.         inc bx          ;Move pointer to next slot
  63.         jmp redo
  64.     done:
  65.         mov [BX], byte ptr '$'  ;Append a $ to the end of array for use with Func. 9 of INT 21 API
  66.  
  67.     pop BX AX
  68.  
  69.     RET
  70.     ENDP ReadString
  71.  
  72.     PROC Print
  73.     push AX
  74.  
  75.         mov AH, 9
  76.         INT 21h
  77.  
  78.     pop AX
  79.    
  80.     RET
  81.     ENDP Print
  82.  
  83.     PROC Exit
  84.        
  85.         mov ah, 4ch
  86.         INT 21H
  87.    
  88.     RET
  89.     ENDP Exit
  90.  
  91. end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement