Repository navigation
Expand file tree
/
Copy pathto_uppercase.asm
More file actions
98 lines (82 loc) · 3.04 KB
/
Copy pathto_uppercase.asm
File metadata and controls
98 lines (82 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
; =============================================================================
; TITLE: String to Uppercase Conversion
; DESCRIPTION: A program that iterates through a string and converts all
; lowercase characters (a-z) to uppercase (A-Z).
; AUTHOR: Amey Thakur (https://github.com/Amey-Thakur)
; REPOSITORY: https://github.com/Amey-Thakur/8086-ASSEMBLY-LANGUAGE-PROGRAMS
; LICENSE: MIT License
; =============================================================================
.MODEL SMALL
.STACK 100H
; -----------------------------------------------------------------------------
; DATA SEGMENT
; -----------------------------------------------------------------------------
.DATA
STR1 DB 'hello world', '$'
NEWLINE DB 0DH, 0AH, '$' ; String for carriage return and line feed
MSG1 DB 'Original: $'
MSG2 DB 'Uppercase: $'
; -----------------------------------------------------------------------------
; CODE SEGMENT
; -----------------------------------------------------------------------------
.CODE
MAIN PROC
; Initialize the Data Segment
MOV AX, @DATA
MOV DS, AX
; Display "Original: " message
LEA DX, MSG1
MOV AH, 09H
INT 21H
; Display the original string
LEA DX, STR1
MOV AH, 09H
INT 21H
; Print a newline for better formatting
LEA DX, NEWLINE
MOV AH, 09H
INT 21H
; --- Case Conversion Logic ---
LEA SI, STR1 ; SI points to the start of the string
CONVERT_LOOP:
MOV AL, [SI] ; Load current character into AL
CMP AL, '$' ; Check if it is the terminator character
JE DISPLAY ; If yes, we are done
; Range Check: Only convert characters between 'a' (61H) and 'z' (7AH)
CMP AL, 'a'
JB NEXT ; If less than 'a', skip
CMP AL, 'z'
JA NEXT ; If greater than 'z', skip
; Conversion: SUB 20H to convert Lower to Upper
; 'a' is 61H (0110 0001) -> 'A' is 41H (0100 0001)
SUB AL, 20H
MOV [SI], AL ; Update the character in memory
NEXT:
INC SI ; Move to the next memory location
JMP CONVERT_LOOP ; Repeat for the next character
DISPLAY:
; Display "Uppercase: " message
LEA DX, MSG2
MOV AH, 09H
INT 21H
; Display the modified string
LEA DX, STR1
MOV AH, 09H
INT 21H
; Clean termination
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
; =============================================================================
; TECHNICAL NOTES
; =============================================================================
; 1. ASCII RELATIONSHIP:
; - Uppercase and lowercase letters differ by 32 (20H).
; - Bit 5 is 1 for Lower and 0 for Upper.
; 2. LOGIC:
; - SUB AL, 20H effectively clears the 5th bit (like AND AL, DFH).
; 3. SAFETY:
; - Range checking ('a' <= char <= 'z') is mandatory to prevent corrupting
; non-alphabetic characters.
; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =