; CS2011, A Term 1999
; Prof. Sergio A. Alvarez

title Sample I/O Module

.model small
.stack

.data
inrecord db 100, ?, 100 dup(?)

.code

public getstring, putstring

getstring proc
; reads a string from the console using DOS function 0Ah
; preconditions: pointer to string buffer in DX
; postconditions: string entered by user has been '$'-terminated
;   and stored in [DX]
;   no registers have been altered
;
   push ax
   push cx
   mov ah,0Ah
   push dx
   mov dx,offset inrecord
   int 21h
   pop dx
   mov cl,inrecord[1]
   mov ch,0
   mov di,2
   mov si,dx
   copyloop:
      mov al,inrecord[di]
      mov [si],al
      inc si
      inc di
   loop copyloop
   mov al,'$'
   mov [si],al
   pop cx
   pop ax
   ret
getstring endp

putstring proc
; writes a '$'-terminated string to the console using DOS function 09h
; preconditions:  DX contains the offset of the output string
;   the last character of the string is '$'
; postconditions: the string has been written to the console
;   no registers have been altered
   push ax
   mov ah,09
   int 21h
   pop ax
   ret
putstring endp

end


