-
Notifications
You must be signed in to change notification settings - Fork 3
/
length_of_an_input_string.asm
74 lines (69 loc) · 1012 Bytes
/
length_of_an_input_string.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
DATA SEGMENT
STR1 DB "ENTER YOUR STRING HERE :$"
STR2 DB "ENTERED STRING IS :$"
STR3 DB "LENGTH OF STRING IS (DIRECT) :$"
STR4 DB "LENGTH OF STRING IS (COUNT) :$"
INSTR1 DB 20 DUP("$")
NEWLINE DB 10,13,"$"
LN DB 5 DUP("$")
N DB "$"
S DB ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
FILLY:
MOV AX,DATA
MOV DS,AX
LEA SI, INSTR1
; GET STRING
MOV AH,09H
LEA DX,STR1
INT 21H
MOV AH,0AH
MOV DX,SI
INT 21H
MOV AH,09H
LEA DX,NEWLINE
INT 21H
; PRINT THE STRING
MOV AH,09H
LEA DX, STR2
INT 21H
MOV AH,09H
LEA DX,INSTR1+2
INT 21H
MOV AH,09H
LEA DX,NEWLINE
INT 21H
; PRINT LENGTH OF STRING (DIRECT)
MOV AH,09H
LEA DX, STR3
INT 21H
MOV BL, INSTR1+1
ADD BL,30H
MOV AH,02H
MOV DL,BL
INT 21H
MOV AH,09H
LEA DX,NEWLINE
INT 21H
; PRINT LENGTH OF STRING ANOTHER WAY
MOV AH,09H
LEA DX, STR4
INT 21H
ADD SI,2
MOV AX,00
L2:CMP BYTE PTR[SI],"$"
JE L1
INC SI
ADD AL,1
JMP L2
L1: SUB AL,1
ADD AL,30H
MOV AH,02H
MOV DL,AL
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END FILLY