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

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