;;reversing a string... before you read further... write the code in c

;screen shot appears at bottom.
;note these features:  arrays declared and NOT initialized (ie. assume they hold junk)
; usin g stack: pushes and pops
;dos functions to read and write strings to/from the terminal
    .MODEL SMALL
   .STACK 100h

 
   .DATA
MAX EQU 80
prompt db 'enter a string',0ah,0dh,'$'
outpt db 'and your output....',0ah,0dh,'$'
StringToReverse  DB  MAX DUP(?)
ReverseString    DB  MAX DUP(?)
   .CODE
 
start:
   mov  ax,@data
&nb sp;  mov  ds,ax                       ;set DS to point to the data segment
 
    mov ah,9
   mov dx,offset prompt
   int 21h

   mov  ah,3fh                      ;DOS read from handle function #
  ;  mov  bx,0                        ;standard input handle
   mov  cx,MAX        ;read up to maximum number of characters
   mov  dx,OFFSET StringToReverse   ;store the string here
   int  21h              &nb sp;          ;get the string
   and  ax,ax                       ;were any characters read?
   jz   Done                        ;no, so you're done
   mov  cx,ax  & nbsp;                    ;put string length in CX, where
                                    ; you can use it as a counter
   push cx              &nb sp;           ;save the string length
   mov  bx,OFFSET StringToReverse
   mov  si,OFFSET ReverseString
   add  si,cx
   dec  si                          ;point to the end of the
             ;                        ; reverse string buffer
ReverseLoop:
   mov  al,[bx]                     ;get the next character
   mov  [si],al                    ;  ;store the characters in reverse order
   inc  bx                          ;point to next character
   dec  si                          ;point to previous location in reverse buffer
   loop Revers eLoop                 ;move next character, if any
 
 mov ah,9
   mov dx,offset outpt
   int 21h

   pop  cx                          ;get back the string length
   mov  ah,40h      &nb sp;               ;DOS write from handle function #
   mov  bx,1                        ;standard output handle
   mov  dx,OFFSET ReverseString     ;print this string
   int  21h                          ;print the reversed string
Done:
   mov al,0
   mov  ah,4ch                      ;DOS terminate program function #
   int  21h                       &n bsp; ;terminate the program
   END start
   end