-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelstartspaces.asm
93 lines (76 loc) · 1.11 KB
/
delstartspaces.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
89
90
91
92
93
.model small
.stack 100h
.386
.data
arr1 db 10,13,'Enter a string: $'
arr2 db 10,13,'After trim: $'
inp_str db 50 dup ('$')
out_str db 50 dup ('$')
len dw '0'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
call read_str
call delete_blanks
terminate:
mov ah,4ch
int 21h
main endp
read_str proc
push ax
push di
lea dx, arr1
mov ah,09h
int 21h
cld
lea di, inp_str
xor bx, bx
read_char:
mov ah, 01h
int 21h
cmp al, 13
je end_input
cmp al, 08h ; backspace
jne store_char
cmp bx, 0
je read_char
dec di
dec bx
jmp read_char
store_char:
stosb
inc bx
jmp read_char
end_input:
mov len ,bx
mov byte ptr [di], '$'
pop di
pop ax
ret
read_str endp
delete_blanks proc
lea dx,arr2
mov ah,9
int 21h
mov al,' '
lea di,inp_str
lea si,out_str
repe scasb
dec di
inc cx
again2:
mov bl,[di]
mov [si],bl
inc si
inc di
dec cx
cmp cx,0
jnz again2
lea dx,out_str
mov ah,9
int 21h
ret
delete_blanks endp
end main