Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .MODEL SMALL
- .386
- .STACK 4096
- .DATA
- Prompt db "Enter a string: ", '$'
- ;-------------------------Variables---------------------------
- ;STRLENGTH db 254 ;Max amount of characters
- STRLENGTH db 254 ;Allocated space
- STRCHAR dw ? ;Will be filled with amount of characters entered
- INPUTBUFF db 254 dup(?) ;The buffer that will contain the input
- ;PRINTBUFF db 256 dup(?) ;dup(?) pretty much means you want 254 bytes of something
- ;OUTPUTBUFF db 254
- ;SHAREDBUFF dw ?
- LINEFEED db 13, 10, '$'
- ;------------------------Code Segement------------------------
- .CODE
- ;=========================================================================================================
- MAIN PROC
- .STARTUP
- ;Here we would call the other procs to carry out the comparing, etc
- ;------------------------Display Prompt------------------------
- MOV AH, 9 ;Print Function
- MOV DX, OFFSET Prompt ;Address for prompt
- INT 21h ;DOS Call
- MOV AH, 0Ah ;Input Function
- MOV DX, OFFSET STRLENGTH ;Start of buffer
- INT 21h ;DOS Call
- CALL BUFFERCOPY
- .EXIT
- MAIN ENDP
- ;=========================================================================================================
- ;---------------Copys original string to a "shared" buffer and terminates the copy with a '$'-----------
- BUFFERCOPY PROC
- ;------------Adding $ to end of chars inputted------------
- MOV SI, OFFSET STRLENGTH + 1 ;Pointing to numbers of chars entered
- MOV CL, [ SI ] ;Moving length to CL
- MOV CH, 0 ;Clearing CH to use CX
- INC CX ;Incrementing to get to last character
- ADD SI, CX ;SI now points to address of enter key (chr(13))
- MOV AL, '$' ;Moving $ into AL
- MOV [ SI ], AL ;Replacing last character (chr(13)) with $
- ;-------NEW LINE-------
- MOV AH, 9
- MOV DX, OFFSET LINEFEED
- INT 21h
- CALL PRINTBUFFER
- CALL LOWERCASE
- RET
- BUFFERCOPY ENDP
- ;--------------Lowercase the shared buffer (convert to lowercase)-----------------
- LOWERCASE PROC
- ; To convert lowercase to uppercase, zero out the 5th bit
- ; Check for lowercase letter
- MOV SI, 0 ;Zero out SI
- MOV SI, OFFSET STRLENGTH + 2 ;Move address of first character entered into SI
- MOV BL, [ SI ] ;Move the contents of that address into BL
- JMP COMPARE
- COMPARE:
- MOV BL, [ SI ]
- CMP BL, 'a' ; Comparing binary value of a and typed character
- JB NEXTCHAR ; If below, its not lowercase
- CMP BL, 'z' ; Comparing binary value of z and typed character
- JA NEXTCHAR ; If above, its not lowercase
- JMP @F
- ;NOT_LOWERCASE:
- ;RET
- @@: ;Might need to rever BL back to SI
- SUB BL, 20h ; Subtracts 00100000 from whatever value it is working with. This zeroes out the fifth bit
- MOV STRLENGTH[ SI ], BL ; Move the result of previous instruction into where the address of SI is pointing to in regards to STRLENGTH
- INC SI ; Increments SI to next characters address
- CMP SI, '$' ; Compares terminator $ with current character held in SIs pointer address
- JE @F ; If it is a $, it jumps to next @@ which starts new linefeed and CALLs PRINTBUFFER
- JMP COMPARE ; If it is not a $, it jumps to COMPARE label
- NEXTCHAR:
- INC SI
- CMP SI, '$'
- JE @F
- JMP COMPARE
- ;MOV SI, 0
- ;MOV CX, STRCHAR
- @@:
- ;-------NEW LINE-------
- MOV AH, 9
- MOV DX, OFFSET LINEFEED
- INT 21h
- CALL PRINTBUFFER
- RET
- LOWERCASE ENDP
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement