-
Notifications
You must be signed in to change notification settings - Fork 0
/
4_question.asm
88 lines (72 loc) · 2.1 KB
/
4_question.asm
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
; invert lower/upper in a string
StSeg Segment STACK 'STACK'
DB 100H DUP (?)
StSeg ENDS
DtSeg Segment
; place data here
DtSeg ENDS
CDSeg Segment
ASSUME CS: CDSeg, DS: DtSeg, SS: StSeg
Start:
MOV AX, DtSeg
MOV DS, AX
; my code starts here
char_input: ; loop to print string
mov AH, 07H ; input char
INT 21H
CMP al, 13 ; if it is enter then the loop should be ended
jz end ; zf == 0 => goto end
push ax ; ax saved
sub al, 65 ; al -= 65
mov bl, al ; bl = al
pop ax ; ax loaded
push ax ; ax saved
sub al, 90 ; al -= 90
neg al ; al *= -1
mov bh, al ; bh = al
pop ax ; ax is loaded
or bl,bh ; bl = bl or bh
neg bl ; bl *= -1
js low ; if signed then 64<al<91 so goto low
push ax ; ax saved
sub al, 97 ; al -= 97
mov bl, al ; bl = al
pop ax ; ax loaded
push ax ; ax saved
sub al, 122 ; al -= 122
neg al ; al *= -1
mov bh, al ; bh = al
pop ax ; ax loaded
or bl,bh ; bl = bl or bh
neg bl ; bl *= -1
js up ; if signed then 96<al<123 so goto up
mov ah, 02H ; print if not alphabetic char
mov dl, al
int 21H
jmp char_input ; continue loop
up:
call upper ; make char upper case
jmp char_input ; continue loop
low:
call lower ; make char lower case
jmp char_input ; continue loop
end:
; end of code
MOV AH, 4CH
MOV AL, 0
INT 21H
upper proc
sub al, 20h ; al -= 32
mov ah, 02H ; print char
mov dl, al
int 21H
ret
upper endp
lower proc
add al, 20H ; al += 32
mov ah, 02H ; print char
mov dl, al
int 21H
ret
lower endp
CDSeg ENDS