laba 4

  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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
.dsabl gbl
.globl test
.globl gets,strcat,printf,xstrtok,xstrlwr
.psect gbl,rw,d,con
str1: .ASCII/(), \t/
.word 0
str2: .ASCII/; /
.word 0
str3: .ASCII/\r\n/
.word 0
str4: .ASCII/\r%s/
.word 0
.psect stat, rw, d, con
strok: .blkb 1750
.psect text, gbl, ro, i, con
test:
mov sp,r1
mov R5, -(SP)
mov sp,r5
mov 2(r1),-(sp) ;ac->sp -2(r5)
mov 4(r1),-(sp) ;av->sp -4(r5)
sub #2, SP ;*d -6(r5)
sub #2, SP ;*s -10(r5)
sub #2, SP ;*p -12(r5)
sub #2, SP ;f -14(r5)
mov #strok, -(SP) ;str[1000] -16(r5)
sub #100, SP ;buf[64] -116(r5)
mov #strok,r1
mov #764,r0
nex:
mov #0,(r1)+
sob r0,nex
cmp -2(r5), #2
bge s1
mov #str1, -6(r5)
jmp s2
s1: mov -4(r5),r0
add #2,r0
mov r0, -6(r5)
s2: cmp -2(r5),#3
bge s3
mov #str2, -10(r5)
jmp s4
s3: mov -4(r5),r0
add #4,r0
mov r0, -10(r5)
s4:
mov #0,-14(r5)
mov -116(r5),-(sp)
call gets
mov -116(r5),r0
mov -6(r5),r1
call xstrtok
add #2,sp
mov r0,-12(r5)
tst -12(r5)
bne e1
s5: tst @-12(r5) ;<while(p),if(*p)
beq s6
tst -14(r5) ;if(f)
beq s7
mov -10(r5),-(sp)
mov #strok,-(sp)
call strcat
add #4,sp
s7: mov -12(r5),r0
call xstrlwr
mov r0,-(sp)
mov #strok,-(sp)
call strcat
add #4,sp
mov #1,-14(r5)
s6: mov -6(r5),r1
mov #0,r0
call xstrtok
mov r0,-12(r5)
tst -12(r5)
bne s5
mov #str3,-(sp)
mov #strok,-(sp)
call strcat
jmp s4
e1: mov #strok,-(sp)
mov #str4,-(sp)
call printf
add #4,sp
mov r5,sp
mov (sp)+,r5
mov #6,r0
return
.end
strlwr::
mov R2,-(SP)
mov R3,-(SP)
mov R4,-(SP)
mov R5,-(SP)
mov #101,r2
mov #132,r3
mov #40,r4
br e1
e3: cmp r1,r2
bcs e2
cmp r1,r3
bhi e2
add r4,r1
e2: movb r1,(r0)+
e1: movb (r0),r1
bne e3
mov (SP)+,R5
mov (SP)+,R4
mov (SP)+,R3
mov (SP)+,R2
rts pc
strtok::
mov R2,-(SP)
mov R3,-(SP)
mov R4,-(SP)
mov R5,-(SP)
tst r0
bne e1
mov @#4000,r0
e1: mov r0,r3
beq e2
mov r1,r2
e4: mov r2,r1
movb (r0)+,r5
beq e3
e5: movb (r1)+,r4
beq e4
cmp r4,r5
bne e5
dec r0
clrb (r0)+
mov r0,@#4000
mov r3,r0
e2: jmp en
e3: mov r3,r0
clr @#4000
en: mov (SP)+,R5
mov (SP)+,R4
mov (SP)+,R3
mov (SP)+,R2
rts pc