-
Notifications
You must be signed in to change notification settings - Fork 0
/
print a string failed.asm
112 lines (61 loc) · 1.88 KB
/
print a string failed.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
.model small
.stack 100h
.data
;the string to be printed
string db 'this is a simple string, '$' '
.code
main proc
mov ax,@data
mov ds,ax
;call reverse function
call reverse
;load address of the string
lea dx,string
;output the string located in dx
mov ah,09h
int 21h
reverse proc
;load the offset of the string
mov si,offset string
;offset string count of characters of the string
mov cx,0h
loop1:
;compare if this is the last charcter
mov ax,[si]
cmp al,'$'
;je labbl1
;else push it in the stack
push [si]
;increment the pointer count
inc si
inc cx
jmp loop1
labeli:
;again load the starting address of the string
mov si,offset string
loop2:
;if count not equal to zero
cmp cx,0
je exit
;pop the top of stack
pop dx
;make dh,0
xor dh,dh
;put the character of the reversed string
mov [si],dx
;increment si and decrement count
inc si
dec cx
jmp loop2
exit:
;add $ to the end of string
mov [si],'$'
ret
reverse endp
end main
;interrupt to exit
exit:
mov ah,4ch
int 21h
main endp
end main