home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 181.img / TASM-101.ZIP / REVERSE.ASM < prev    next >
Assembly Source File  |  1988-10-31  |  2KB  |  41 lines

  1.    DOSSEG
  2.    .MODEL SMALL
  3.    .STACK 100h
  4.    .DATA
  5. MAXIMUM_STRING_LENGTH  EQU  1000
  6. StringToReverse  DB  MAXIMUM_STRING_LENGTH DUP(?)
  7. ReverseString    DB  MAXIMUM_STRING_LENGTH DUP(?)
  8.    .CODE
  9.    mov  ax,@data
  10.    mov  ds,ax                       ;set DS to point to the data segment
  11.    mov  ah,3fh                      ;DOS read from handle function #
  12.    mov  bx,0                        ;standard input handle
  13.    mov  cx,MAXIMUM_STRING_LENGTH    ;read up to maximum number of characters
  14.    mov  dx,OFFSET StringToReverse   ;store the string here
  15.    int  21h                         ;get the string
  16.    and  ax,ax                       ;were any characters read?
  17.    jz   Done                        ;no, so you're done
  18.    mov  cx,ax                       ;put string length in CX, where
  19.                                     ; you can use it as a counter
  20.    push cx                          ;save the string length
  21.    mov  bx,OFFSET StringToReverse
  22.    mov  si,OFFSET ReverseString
  23.    add  si,cx
  24.    dec  si                          ;point to the end of the
  25.                                     ; reverse string buffer
  26. ReverseLoop:
  27.    mov  al,[bx]                     ;get the next character
  28.    mov  [si],al                     ;store the characters in reverse order
  29.    inc  bx                          ;point to next character
  30.    dec  si                          ;point to previous location in reverse buffer
  31.    loop ReverseLoop                 ;move next character, if any
  32.    pop  cx                          ;get back the string length
  33.    mov  ah,40h                      ;DOS write from handle function #
  34.    mov  bx,1                        ;standard output handle
  35.    mov  dx,OFFSET ReverseString     ;print this string
  36.    int  21h                         ;print the reversed string
  37. Done:
  38.    mov  ah,4ch                      ;DOS terminate program function #
  39.    int  21h                         ;terminate the program
  40.    END
  41.