КУРСОВА РАБОТА

ПО

МИКРОПРОЦЕСОРНА ТЕХНИКа

СТУДЕНТ: ДЕАН ДЕНЕВ РЪКОВОДИТЕЛ

ГРУПА 29А ИНЖ. Б. ХРИСТОВ

НОМЕР 083268 / /

1. ИЗХОДЕН КОД

Error! No index entries found.

name "MOVE_ARR_HEX"

org 100h

jmp BEGIN

;------

; Define variable

;------

msgStartAddr DB "START_ADDR:" , 20h, 24h

msgSize DB 0dh, 0ah, "SIZE:" , 20h, 20h, 20h, 20h, 20h, 20h, 20h, 24h

msgNewAddr DB 0dh, 0ah, "TR_ADDR:" , 20h, 20h, 20h, 20h, 24h

msgCount DB 0dh, 0ah, "COUNT=" , 20h, 20h, 20h, 20h, 20h, 20h, 24h

msgFinish DB 0dh, 0ah, "End." , 24h

msgError DB 0dh, 0ah, "ERROR!" , 24h

;example array

;array DB ',', ' ', 0ah, 'ï', '5', 0ch, '7', 0eh, '9', 'a', 0dh, 'c', 'd', 0bh, 'f'

starter DW ?

arrSize DW ?

newAddr DW ?

;------

;Main program code

;------

BEGIN:

;Init:

;Set video mode:

mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3)

int 10h ; do it!

;Show first text line:

lea ax, msgStartAddr

call print

;Read array begin address:

mov cx, 4

call read

mov starter, bx

;Show next text line:

lea ax, msgSize

call print

;Read array size length:

mov cx, 4

call read

mov arrSize, bx

;Show next text line:

lea ax, msgNewAddr

call print

;Read array new address:

mov cx, 4

call read

mov newAddr, bx

;Call validate input param. :

call valid

;Move array and count ASCII symbols:

call move

;Show number of ASCII symbol:

lea ax, msgCount

call print

call shCnt

;Show finish message:

lea ax, msgFinish

call print

;On end wait to press KEY

mov ah, 0

int 16h

int 20h

; ret

;------

;Funkcii

;------

;Show text:

print: mov dx,ax

mov ah,09h ;09h-izliza string

int 21h

ret

; ASCII to HEX:

a2h: add al,40h

cbw ;convert byte to word

and ah,09h

add al,ah

and al,0fh

ret

;Proverka za korestekn simvol:

check: cmp al,30h;

jb n ;ako e po-malko

cmp al,3ah

jb y

cmp al,41h

jb n

cmp al,47h

jb y

cmp al,61h;

jb n

cmp al,67h

jb y

n: jmp badHex

y: ret

;Pro4itanen a hex simvol

badHex: pop bx

read: mov ah,0

int 16h

call check

push ax

mov ah,0eh

int 10h

loop read

;Packed four readed ASCCI numbers:

pop ax

call a2h

mov bl,al

pop ax

call a2h

mov cl,4

shl al,cl

or bl,al

pop ax

call a2h

mov bh,al

pop ax

call a2h

mov cl,4

shl al,cl

or bh,al

ret

valid: mov ax, starter

add ax, arrSize

cmp ax, newAddr

jb pass

mov ax, newAddr

add ax, arrSize

cmp ax, starter

jb pass

lea ax, msgError

call print

mov ah, 0

int 16h

int 20h

pass: ret

;Premestvane:

move: mov si, starter

mov di, newAddr

mov cx, arrSize

and bx, 0

lp: lodsb

stosb

;Provekra za ASCII:

cmp al, 30h

jb no

cmp al, 3ah

jb yes

cmp al, 41h

jb no

cmp al, 47h

jb yes

cmp al, 61h

jb no

cmp al, 66h

ja no

yes: inc bx

no: loop lp

ret

;Show counted number:

shCnt: mov cl, 4

mov al, bh

shr al, cl

call toAsci

mov al, bh

and al, 0fh

call toAsci

mov al, bl

shr al, cl

call toAsci

mov al, bl

and al, 0fh

call toAsci

ret

;Konvertirane:

toAsci: cmp al, 0ah

jb a

sub al, 09h

or al, 40h

jmp skip

a: or al, 30h

skip: mov ah, 0eh

int 10h

ret

TURBO ASSEMBLER December 1,2010 07:57:23 a.m. Page 1

2. ЛИСЪНИНГ

1 name "MOVE_ARR_HEX"

2 0100 org 100h

3 0100 E9 0189 jmp BEGIN

4 ;------

5 ; Define variable

6 ;------

7 0103 53 74 61 72 74 6F starter DB "Startov adres" , 20h, 24h

76 20 61 64 72 65

73 20 24

8 0112 0D 0A 52 61 73 6D sizer DB 0dh,0ah, "Rasmer:" ,20h,20h,20h,20h,24h

65 72 3A 20 20 20

20 24

9 0120 0D 0A 41 64 72 65 adresser DB 0dh, 0ah, "Adres za prexvarlane:" , 20h, 20h, 20h, 20h, 24h

73 20 7A 61 20 70

72 65 78 76 61 72

6C 61 6E 65 3A 20

20 20 20 24

10 013C 0D 0A 42 72 6F 71 counter DB 0dh, 0ah, "Broq4=" , 20h, 20h, 20h, 20h, 20h, 20h, 24h

34 3D 20 20 20 20

20 20 24

11 014B 0D 0A 45 6E 64 2E finito DB 0dh, 0ah, "End." , 24h

24

12 0152 0D 0A 47 72 65 73 error DB 0dh, 0ah, "Greshka!Masivite se pripokrivat" , 24h

68 6B 61 21 4D 61

73 69 76 69 74 65

20 73 65 20 70 72

69 70 6F 6B 72 69

76 61 74 24

13

14 ;example array

15 0174 2C 20 0A EF 35 0C array DB ',', ' ', 0ah, 'п', '5', 0ch, '7', 0eh, '9', 'a', 0dh, 'c', 'd', 0bh, 'f'

37 0E 39 61 0D 63

64 0B 66

16

17 0183 ???? begin_address DW ?

18 0185 ???? arraysize DW ?

19 0187 ???? new_address DW ?

20

21 ;------

22 ;Main program code

23 ;------

24 0189 BEGIN:

25 ;Init:

26

27 ;Set video mode:

28 0189 B8 0003 mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3)

29 018C CD 10 int 10h ; do it!

30

31 ;Show first text line:

32 018E 8D 06 0103 lea ax, starter

33 0192 E8 01DE call print

34 ;Read array begin address:

35 0195 B9 0004 mov cx, 4

36 0198 E8 020D call read

37 019B 89 1E 0183 mov begin_address, bx

38

39 ;Show next text line:

40 019F 8D 06 0112 lea ax, sizer

41 01A3 E8 01DE call print

42 ;Read array size length:

TURBO ASSEMBLER December 1,2010 07:57:23 a.m. Page 2

43 01A6 B9 0004 mov cx, 4

44 01A9 E8 020D call read

45 01AC 89 1E 0185 mov arraysize, bx

46

47 ;Show next text line:

48 01B0 8D 06 0120 lea ax, adresser

49 01B4 E8 01DE call print

50 ;Read array new address:

51 01B7 B9 0004 mov cx, 4

52 01BA E8 020D call read

53 01BD 89 1E 0187 mov new_address, bx

54

55 ;Call validate input param. :

56 01C1 E8 023C call valid

57

58 ;Move array and count ASCII symbols:

59 01C4 E8 0264 call move

60

61 ;Show number of ASCII symbol:

62 01C7 8D 06 013C lea ax, counter

63 01CB E8 01DE call print

64 01CE E8 0292 call shCnt

65

66 ;Show finish message:

67 01D1 8D 06 014B lea ax, finito

68 01D5 E8 01DE call print

69

70 ;On end wait to press KEY

71 01D8 B4 00 mov ah, 0

72 01DA CD 16 int 16h

73 01DC CD 20 int 20h

74 ; ret

75

76 ;------

77 ;Program functions

78 ;------

79 ;Show text:

80 01DE 8B D0 print: mov dx,ax

81 01E0 B4 09 mov ah,09h

82 01E2 CD 21 int 21h

83 01E4 C3 ret

84

85 ;Convert ASCII to HEX:

86 01E5 04 40 a2h: add al,40h

87 01E7 98 cbw

88 01E8 80 E4 09 and ah,09h

89 01EB 00 E0 add al,ah

90 01ED 24 0F and al,0fh

91 01EF C3 ret

92

93 ;Check correct HEX symbol:

94 01F0 3C 30 check: cmp al,30h;

95 01F2 72 14 jb n

96 01F4 3C 3A cmp al,3ah

97 01F6 72 13 jb y

98 01F8 3C 41 cmp al,41h

99 01FA 72 0C jb n

100 01FC 3C 47 cmp al,47h

101 01FE 72 0B jb y

102 0200 3C 61 cmp al,61h;

TURBO ASSEMBLER December 1,2010 07:57:23 a.m. Page 3

103 0202 72 04 jb n

104 0204 3C 67 cmp al,67h

105 0206 72 03 jb y

106 0208 EB 02 90 n: jmp badHex

107 020B C3 y: ret

108

109 ;Read one kyeboard symbol:

110 020C 5B badHex: pop bx

111 020D B4 00 read: mov ah,0

112 020F CD 16 int 16h

113 0211 E8 01F0 call check

114 0214 50 push ax

115 0215 B4 0E mov ah,0eh

116 0217 CD 10 int 10h

117 0219 E2 F2 loop read

118 ;Packed four readed ASCCI numbers:

119 021B 58 pop ax

120 021C E8 01E5 call a2h

121 021F 8A D8 mov bl,al

122 0221 58 pop ax

123 0222 E8 01E5 call a2h

124 0225 B1 04 mov cl,4

125 0227 D2 E0 shl al,cl

126 0229 08 C3 or bl,al

127 022B 58 pop ax

128 022C E8 01E5 call a2h

129 022F 8A F8 mov bh,al

130 0231 58 pop ax

131 0232 E8 01E5 call a2h

132 0235 B1 04 mov cl,4

133 0237 D2 E0 shl al,cl

134 0239 08 C7 or bh,al

135 023B C3 ret

136

137 ;Validate input param. :

138 023C A1 0183 valid: mov ax, begin_address

139 023F 03 06 0185 add ax, arraysize

140 0243 3B 06 0187 cmp ax, new_address

141 0247 72 1A jb pass

142 0249 A1 0187 mov ax, new_address

143 024C 03 06 0185 add ax, arraysize

144 0250 3B 06 0183 cmp ax, begin_address

145 0254 72 0D jb pass

146 ;Show bad input param. :

147 0256 8D 06 0152 lea ax, error

148 025A E8 01DE call print

149 025D B4 00 mov ah, 0

150 025F CD 16 int 16h

151 0261 CD 20 int 20h

152 0263 C3 pass: ret

153

154 ;Move array:

155 0264 8B 36 0183 move: mov si, begin_address

156 0268 8B 3E 0187 mov di, new_address

157 026C 8B 0E 0185 mov cx, arraysize

158 0270 81 E3 0000 and bx, 0

159 0274 AC lp: lodsb

160 0275 AA stosb

161 ;Check for ASCII:

162 0276 3C 30 cmp al, 30h

TURBO ASSEMBLER December 1,2010 07:57:23 a.m. Page 4

163 0278 72 15 jb no

164 027A 3C 3A cmp al, 3ah

165 027C 72 10 jb yes

166 027E 3C 41 cmp al, 41h

167 0280 72 0D jb no

168 0282 3C 47 cmp al, 47h

169 0284 72 08 jb yes

170 0286 3C 61 cmp al, 61h

171 0288 72 05 jb no

172 028A 3C 66 cmp al, 66h

173 028C 77 01 ja no

174

175 028E 43 yes: inc bx

176 028F E2 E3 no: loop lp

177 0291 C3 ret

178

179 ;Show counted number:

180 0292 B1 04 shCnt: mov cl, 4

181 0294 8A C7 mov al, bh

182 0296 D2 E8 shr al, cl

183 0298 E8 02B1 call toAsci

184 029B 8A C7 mov al, bh

185 029D 24 0F and al, 0fh

186 029F E8 02B1 call toAsci

187 02A2 8A C3 mov al, bl

188 02A4 D2 E8 shr al, cl

189 02A6 E8 02B1 call toAsci

190 02A9 8A C3 mov al, bl

191 02AB 24 0F and al, 0fh

192 02AD E8 02B1 call toAsci

193 02B0 C3 ret

194 ;Convert HEX to ASCII and print:

195 02B1 3C 0A toAsci: cmp al, 0ah

196 02B3 72 07 jb a

197 02B5 2C 09 sub al, 09h

198 02B7 0C 40 or al, 40h

199 02B9 EB 03 90 jmp skip

200 02BC 0C 30 a: or al, 30h

201 02BE B4 0E skip: mov ah, 0eh

202 02C0 CD 10 int 10h

203 02C2 C3 ret

204

205

1. ИЗХОДЕН КОД 2

2. ЛИСЪНИНГ 6

2