Advertisement
Guest User

To uppercase

a guest
Oct 9th, 2015
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .MODEL SMALL
  2. .386
  3. .STACK 4096
  4.  
  5.  
  6.  
  7. .DATA
  8. Prompt      db  "Enter a string: ", '$'
  9.  
  10. ;-------------------------Variables---------------------------
  11. ;STRLENGTH  db      254             ;Max amount of characters
  12. STRLENGTH   db      254         ;Allocated space
  13. STRCHAR     dw      ?           ;Will be filled with amount of characters entered
  14. INPUTBUFF   db      254 dup(?)      ;The buffer that will contain the input
  15. ;PRINTBUFF  db      256 dup(?)      ;dup(?) pretty much means you want 254 bytes of something
  16. ;OUTPUTBUFF db      254
  17. ;SHAREDBUFF     dw      ?
  18. LINEFEED    db      13, 10, '$'
  19.  
  20.  
  21.  
  22.  
  23. ;------------------------Code Segement------------------------
  24. .CODE
  25.  
  26. ;=========================================================================================================
  27. MAIN        PROC
  28.             .STARTUP
  29.  
  30.             ;Here we would call the other procs to carry out the comparing, etc
  31.             ;------------------------Display Prompt------------------------
  32.             MOV     AH, 9                   ;Print Function
  33.             MOV     DX, OFFSET Prompt       ;Address for prompt
  34.             INT     21h                     ;DOS Call
  35.  
  36.             MOV     AH, 0Ah                 ;Input Function
  37.             MOV     DX, OFFSET STRLENGTH    ;Start of buffer   
  38.             INT     21h                     ;DOS Call
  39.  
  40.  
  41.             CALL    BUFFERCOPY
  42.  
  43.  
  44.             .EXIT
  45. MAIN        ENDP
  46. ;=========================================================================================================
  47.  
  48. ;---------------Copys original string to a "shared" buffer and terminates the copy with a '$'-----------
  49. BUFFERCOPY  PROC
  50.  
  51.             ;------------Adding $ to end of chars inputted------------
  52.             MOV     SI, OFFSET STRLENGTH + 1    ;Pointing to numbers of chars entered
  53.             MOV     CL, [ SI ]                  ;Moving length to CL
  54.             MOV     CH, 0                       ;Clearing CH to use CX
  55.             INC     CX                      ;Incrementing to get to last character
  56.             ADD     SI, CX                      ;SI now points to address of enter key (chr(13))
  57.             MOV     AL, '$'                     ;Moving $ into AL
  58.             MOV     [ SI ], AL                  ;Replacing last character (chr(13)) with $
  59.  
  60.             ;-------NEW LINE-------
  61.             MOV     AH, 9
  62.             MOV     DX, OFFSET LINEFEED
  63.             INT     21h
  64.  
  65.             CALL    PRINTBUFFER
  66.             CALL    LOWERCASE
  67.  
  68.             RET
  69. BUFFERCOPY  ENDP
  70.  
  71.  
  72.  
  73. ;--------------Lowercase the shared buffer (convert to lowercase)-----------------
  74. LOWERCASE   PROC
  75.             ; To convert lowercase to uppercase, zero out the 5th bit
  76.  
  77.             ; Check for lowercase letter
  78.             MOV     SI, 0                       ;Zero out SI
  79.             MOV     SI, OFFSET STRLENGTH + 2    ;Move address of first character entered into SI
  80.             MOV     BL, [ SI ]                  ;Move the contents of that address into BL
  81.             JMP     COMPARE
  82.    
  83. COMPARE:
  84.             MOV     BL, [ SI ]
  85.             CMP     BL, 'a'                     ; Comparing binary value of a and typed character
  86.             JB      NEXTCHAR                    ; If below, its not lowercase
  87.             CMP     BL, 'z'                     ; Comparing binary value of z and typed character
  88.             JA      NEXTCHAR                ; If above, its not lowercase
  89.             JMP     @F
  90.  
  91. ;NOT_LOWERCASE:
  92.             ;RET
  93.  
  94.  
  95. @@:         ;Might need to rever BL back to SI
  96.             SUB     BL, 20h                     ; Subtracts 00100000 from whatever value it is working with. This zeroes out the fifth bit
  97.             MOV     STRLENGTH[ SI ], BL         ; Move the result of previous instruction into where the address of SI is pointing to in regards to STRLENGTH
  98.             INC     SI                          ; Increments SI to next characters address
  99.             CMP     SI, '$'                     ; Compares terminator $ with current character held in SIs pointer address
  100.             JE      @F                          ; If it is a $, it jumps to next @@ which starts new linefeed and CALLs PRINTBUFFER
  101.             JMP     COMPARE                     ; If it is not a $, it jumps to COMPARE label
  102.  
  103.  
  104. NEXTCHAR:
  105.             INC     SI
  106.             CMP     SI, '$'
  107.             JE      @F
  108.             JMP     COMPARE
  109.  
  110.             ;MOV    SI, 0
  111.             ;MOV    CX, STRCHAR
  112.  
  113.  
  114. @@:
  115.             ;-------NEW LINE-------
  116.             MOV     AH, 9
  117.             MOV     DX, OFFSET LINEFEED
  118.             INT     21h
  119.  
  120.             CALL    PRINTBUFFER
  121.  
  122.             RET
  123. LOWERCASE   ENDP
  124.  
  125. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement