home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 9.ddi / CHAPXMPL.ZIP / MASEXMPL.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-02-13  |  3.1 KB  |  74 lines

  1. ; Turbo Assembler    Copyright (c) 1988, 1991 By Borland International, Inc.
  2.  
  3. ; MASEXMPL.ASM - MASM Mode example program to uppercase a line
  4.  
  5. ; From the Turbo Assembler Users Guide - Turbo Assembler Ideal Mode
  6.  
  7.      TITLE  Example MASM Program      ;this comment is in the
  8.                                       ;title!
  9.      .286
  10.  
  11. bufsize  =   128                      ;size of input and output
  12.                                       ;buffers
  13.  
  14. dosint MACRO intnum
  15.      mov  ah,intnum                   ;assign FN number to AH
  16.      int  21h                         ;call DOS function &INTNUM
  17. ENDM
  18.  
  19. stk SEGMENT STACK
  20.      db   100h DUP (?)                ;reserve stack space
  21. stk ENDS
  22.  
  23. data SEGMENT WORD
  24. inbuf     db   bufsize DUP (?)        ;input buffer
  25. outbuf    db   bufsize DUP (?)        ;output buffer
  26. data ENDS
  27.  
  28. DGROUP GROUP stk,data                 ;group stack and data segs
  29.  
  30. code SEGMENT WORD
  31.      ASSUME   cs:code                 ;assume CS is code seg
  32. start:
  33.      mov  ax,DGROUP                   ;assign address of DGROUP
  34.      mov  ds,ax                       ;segment to DS
  35.      ASSUME   ds:DGROUP               ;default data segment is DS
  36.      mov  dx,OFFSET DGROUP:inbuf      ;load into DX inbuf offset
  37.      xor  bx,bx                       ;standard input
  38.      call readline                    ;read one line
  39.      mov  bx,ax                       ;assign length to BX
  40.      mov  inbuf[bx],0                 ;add null terminator
  41.      push ax                          ;save AX on stack
  42.      call mungline                    ;convert line to uppercase
  43.      pop  cx                          ;restore count
  44.      mov  dx,OFFSET DGROUP:outbuf     ;load into DX outbuf offset
  45.      mov  bx,1                        ;standard output
  46.      dosint    40h                    ;write file function
  47.      dosint    4ch                    ;exit to DOS
  48.  
  49. ;Read a line, called with dx => buffer, returns count in AX
  50. readline PROC near
  51.      mov  cx,bufsize                  ;specify buffer size
  52.      dosint    3fh                    ;read file function
  53.      and  ax,ax                       ;set zero flag on count
  54.      ret                              ;return to caller
  55. readline ENDP
  56.  
  57. ;Convert line to uppercase
  58. mungline PROC NEAR
  59.      mov  si,OFFSET DGROUP:inbuf      ;address inbuf with SI
  60.      mov  di,0                        ;initialize DI
  61. @@uloop:
  62.      cmp  BYTE PTR[si],0              ;end of text?
  63.      je   @@done                      ;if yes, jump to @@done
  64.      mov  al,[si]                     ;else get next character
  65.      and  al,not 'a' - 'A'            ;convert to uppercase
  66.      mov  outbuf[di],al               ;store in output buffer
  67.      inc  si                          ;better to use lodsb,stosb
  68.      inc  di                          ;...this is just an example!
  69.      jmp  @@uloop                     ;continue converting text
  70. @@done:   ret
  71. mungline ENDP                         ;end of procedure
  72. code ENDS                             ;end of code segment
  73.      END  start                       ;end of text and DOS entry                                       ;point
  74.