Ïðèìåðû ìàêðîêîìàíä ïå÷àòè

Èñõîäíûé êîä (ðåêîìåíäóåòñÿ ïîìåñòèòü â îòäåëüíûé ôàéë)

; ïå÷àòü áàéòà

printb macro xxxyyy

extrn hex : far

push dx

push ax

mov dl,byte ptr xxxyyy

call hex

pop ax

pop dx

endm

;ïå÷àòü ñëîâà

printw macro xxxyyy

extrn hexw : far

push dx

push ax

mov dx,xxxyyy

call hexw

pop ax

pop dx

endm

;ïå÷àòü òåêñòà áåç ïåðåâîäà ñòðîêè

print macro txt

local msg,next

push dx

push ax

lea dx,cs:msg

jmp short next

msg db txt,'$'

next: mov ah,9h

int 21h

pop ax

pop dx

endm

;ïå÷àòü òåêñòà ñ ïåðåâîäîì ñòðîêè

println macro txt

local msg,next

push dx

push ax

lea dx,cs:msg

jmp short next

IFB <txt>

msg db txt,10,13,'$'

ELSE

msg db txt,10,13,'$'

ENDIF

next: mov ah,9h

int 21h

pop ax

pop dx

endm

; êîíåö îïèñàíèÿ ìàêðîêîìàíä

;Íà÷àëî ïðîãðàììû

include èìÿ_ôàéëà_ìàêðîêîìàíä

STK SEGMENT STACK

DW 64 DUP (?)

STK ENDS

CODE SEGMENT 'CODE' PUBLIC

EXTRN hexw : far

;;;extrn pgmz : far

ASSUME CS:CODE

START PROC FAR

PUSH DS ; ÑÅÃÌÅÍÒ ÀÄÐÅÑÀ ÂÎÇÂÐÀÒÀ

MOV AX,0 ; ÑÌÅÙÅÍÈÅ ÀÄÐÅÑÀ ÂÎÇÂÐÀÒÀ

PUSH AX

CLD ; ÓÑÒÀÍÎÂÊÀ ÍÀÏÐÀÂËÅÍÈß

MOV AX,CS ; ÓÑÒÀÍÎÂÊÀ ÑÅÃÌÅÍÒÍÎÃÎ ÐÅÃÈÑÒÐÀ

MOV DS,AX

ASSUME DS:CODE

lea bx,cs:($+5) ;; cs:z

jmp short m1

z db 'ïðèâåò èç òåëà',10,13,'$'

m1:

mov dx,bx

MOV AH,9H

INT 21H

print 'ïðèâåò1'

println 'ïðèâåò2'

println 'ïðèâåò3'

mov dx,55h

call hexw

println

println 'endddddddddddd'

printb 05

printb 55

printb b1

println ' '

printw w1

printw w2

println '+++++++++++++++++++'

mov ax,abc

print 'ax,abc='

printw ax

mov es,ax

lea bx,b

printw es:[bx]

println

print '1) w1='

printw w1

println

push ds

push w1

call pgmz

print '2) w1='

printw w1

println

RET

MESSAGE db '123456789ABCDEFHello....',10,13, '$'

b1 db '5'

w1 dw 13

w2 dw 255

START ENDP

CODE ENDS

abc segment 'abcCODE' PUBLIC

a dw 1

b dw 2

abc ends

zzz segment 'zzzCODE' PUBLIC

assume cs:zzz

pgmz proc far

PUSH bp

mov bp,sp

mov bx,[bp+2]

mov es,[bp+4]

mov es:[bx],word ptr 0

pop bp

ret

pgmz endp

zzz ends

END START

Ðåçóëüòàò âûïîëíåíèÿ ïðîãðàììû

C:\Test\Assembler\bsu\1>x

ïðèâåò èç òåëà

ïðèâåò1ïðèâåò2

ïðèâåò3

0055

endddddddddddd

053735

000D 00FF +++++++++++++++++++

ax,abc=07CA 0002

1) w1=000D

2) w1=000D

«Ëèñòèíã ïðîãðàììû»

Turbo Assembler Version 4.1 31/03/08 14:38:19 Page 1

x.asm

1 printb macro xxxyyy

2 extrn hex : far

3 push dx

4 push ax

5 mov dl,byte ptr xxxyyy

6 call hex

7 pop ax

8 pop dx

9 endm

10 printw macro xxxyyy

11 extrn hexw : far

12 push dx

13 push ax

14 mov dx,xxxyyy

15 call hexw

16 pop ax

17 pop dx

18 endm

19

20

21 print macro txt

22 local msg,next

23 push dx

24 push ax

25 lea dx,cs:msg

26 jmp short next

27 msg db txt,'$'

28 next: mov ah,9h

29 int 21h

30 pop ax

31 pop dx

32 endm

33

34 println macro txt

35 local msg,next

36 push dx

37 push ax

38 lea dx,cs:msg

39 jmp short next

40 IFB <txt>

41 msg db txt,10,13,'$'

42 ELSE

43 msg db txt,10,13,'$'

44 ENDIF

45 next: mov ah,9h

46 int 21h

47 pop ax

48 pop dx

49 endm

50

51 0000 STK SEGMENT STACK

52 0000 40*(????) DW 64 DUP (?)

53 0080 STK ENDS

54

55 0000 CODE SEGMENT 'CODE' PUBLIC

56 EXTRN hexw : far

57 ;;;extrn pgmz : far

58

59 ASSUME CS:CODE

60 0000 START PROC FAR

61 0000 1E PUSH DS ; ÑÅÃÌÅÍÒ ÀÄÐÅÑÀ ÂÎÇÂÐÀÒÀ

62 0001 B8 0000 MOV AX,0 ; ÑÌÅÙÅÍÈÅ ÀÄÐÅÑÀ ÂÎÇÂÐÀÒÀ

63 0004 50 PUSH AX

64 0005 FC CLD ; ÓÑÒÀÍÎÂÊÀ ÍÀÏÐÀÂËÅÍÈß

65 0006 8C C8 MOV AX,CS ; ÓÑÒÀÍÎÂÊÀ ÑÅÃÌÅÍÒÍÎÃÎ ÐÅÃÈÑÒÐÀ

66 0008 8E D8 MOV DS,AX

67 ASSUME DS:CODE

68

69 000A BB 000Fr lea bx,cs:($+5) ;; cs:z

70

71 000D EB 11 jmp short m1

72 000F AF E0 A8 A2 A5 E2 20+ z db 'ïðèâåò èç òåëà',10,13,'$'

73 A8 A7 20 E2 A5 AB A0+

74 0A 0D 24

75 0020 m1:

76 0020 8B D3 mov dx,bx

77 0022 B4 09 MOV AH,9H

78 0024 CD 21 INT 21H

79

80 print 'ïðèâåò1'

1 81 0026 52 push dx

1 82 0027 50 push ax

1 83 0028 BA 002Dr lea dx,cs:??0000

1 84 002B EB 08 jmp short ??0001

1 85 002D AF E0 A8 A2 A5 E2 31+ ??0000 db 'ïðèâåò1','$'

86 24

1 87 0035 B4 09 ??0001: mov ah,9h

1 88 0037 CD 21 int 21h

1 89 0039 58 pop ax

1 90 003A 5A pop dx

91 println 'ïðèâåò2'

1 92 003B 52 push dx

1 93 003C 50 push ax

1 94 003D BA 0042r lea dx,cs:??0002

1 95 0040 EB 0A jmp short ??0003

1 96 IFB <'ïðèâåò2'>

1 97 ??0002 db 'ïðèâåò2',10,13,'$'

1 98 ELSE

1 99 0042 AF E0 A8 A2 A5 E2 32+ ??0002 db 'ïðèâåò2',10,13,'$'

100 0A 0D 24

1 101 ENDIF

1 102 004C B4 09 ??0003: mov ah,9h

1 103 004E CD 21 int 21h

1 104 0050 58 pop ax

1 105 0051 5A pop dx

106 println 'ïðèâåò3'

1 107 0052 52 push dx

1 108 0053 50 push ax

1 109 0054 BA 0059r lea dx,cs:??0004

1 110 0057 EB 0A jmp short ??0005

1 111 IFB <'ïðèâåò3'>

1 112 ??0004 db 'ïðèâåò3',10,13,'$'

1 113 ELSE

1 114 0059 AF E0 A8 A2 A5 E2 33+ ??0004 db 'ïðèâåò3',10,13,'$'

115 0A 0D 24

1 116 ENDIF

1 117 0063 B4 09 ??0005: mov ah,9h

1 118 0065 CD 21 int 21h

1 119 0067 58 pop ax

1 120 0068 5A pop dx

121

122 0069 BA 0055 mov dx,55h

123 006C 0E E8 0000e call hexw

124 println

1 125 0070 52 push dx

1 126 0071 50 push ax

1 127 0072 BA 0077r lea dx,cs:??0006

1 128 0075 EB 04 jmp short ??0007

1 129 IFB <>

1 130 0077 ?? 0A 0D 24 ??0006 db ,10,13,'$'

1 131 ELSE

1 132 ??0006 db ,10,13,'$'

1 133 ENDIF

1 134 007B B4 09 ??0007: mov ah,9h

1 135 007D CD 21 int 21h

1 136 007F 58 pop ax

1 137 0080 5A pop dx

138 println 'endddddddddddd'

1 139 0081 52 push dx

1 140 0082 50 push ax

1 141 0083 BA 0088r lea dx,cs:??0008

1 142 0086 EB 11 jmp short ??0009

1 143 IFB <'endddddddddddd'>

1 144 ??0008 db 'endddddddddddd',10,13,'$'

1 145 ELSE

1 146 0088 65 6E 64 64 64 64 64+ ??0008 db 'endddddddddddd',10,13,'$'

147 64 64 64 64 64 64 64+

148 0A 0D 24

1 149 ENDIF

1 150 0099 B4 09 ??0009: mov ah,9h

1 151 009B CD 21 int 21h

1 152 009D 58 pop ax

1 153 009E 5A pop dx

154 printb 05

1 155 extrn hex : far

1 156 009F 52 push dx

1 157 00A0 50 push ax

1 158 00A1 B2 05 mov dl,byte ptr 05

1 159 00A3 0E E8 0000e call hex

1 160 00A7 58 pop ax

1 161 00A8 5A pop dx

162 printb 55

1 163 extrn hex : far

1 164 00A9 52 push dx

1 165 00AA 50 push ax

1 166 00AB B2 37 mov dl,byte ptr 55

1 167 00AD 0E E8 0000e call hex

1 168 00B1 58 pop ax

1 169 00B2 5A pop dx

170 printb b1

1 171 extrn hex : far

1 172 00B3 52 push dx

1 173 00B4 50 push ax

1 174 00B5 8A 16 01D6r mov dl,byte ptr b1

1 175 00B9 0E E8 0000e call hex

1 176 00BD 58 pop ax

1 177 00BE 5A pop dx

178 println ' '

1 179 00BF 52 push dx

1 180 00C0 50 push ax

1 181 00C1 BA 00C6r lea dx,cs:??000A

1 182 00C4 EB 04 jmp short ??000B

1 183 IFB <' '>

1 184 ??000A db ' ',10,13,'$'

1 185 ELSE

1 186 00C6 20 0A 0D 24 ??000A db ' ',10,13,'$'

1 187 ENDIF

1 188 00CA B4 09 ??000B: mov ah,9h

1 189 00CC CD 21 int 21h

1 190 00CE 58 pop ax

1 191 00CF 5A pop dx

192 printw w1

1 193 extrn hexw : far

1 194 00D0 52 push dx

1 195 00D1 50 push ax

1 196 00D2 8B 16 01D7r mov dx,w1

1 197 00D6 0E E8 0000e call hexw

1 198 00DA 58 pop ax

1 199 00DB 5A pop dx

200 printw w2

1 201 extrn hexw : far

1 202 00DC 52 push dx

1 203 00DD 50 push ax

1 204 00DE 8B 16 01D9r mov dx,w2

1 205 00E2 0E E8 0000e call hexw

1 206 00E6 58 pop ax

1 207 00E7 5A pop dx

208 println '+++++++++++++++++++'

1 209 00E8 52 push dx

1 210 00E9 50 push ax

1 211 00EA BA 00EFr lea dx,cs:??000C

1 212 00ED EB 16 jmp short ??000D

1 213 IFB <'+++++++++++++++++++'>

1 214 ??000C db '+++++++++++++++++++',10,13,'$'

1 215 ELSE

1 216 00EF 2B 2B 2B 2B 2B 2B 2B+ ??000C db '+++++++++++++++++++',10,13,'$'

217 2B 2B 2B 2B 2B 2B 2B+

218 2B 2B 2B 2B 2B 0A 0D+

219 24

1 220 ENDIF

1 221 0105 B4 09 ??000D: mov ah,9h

1 222 0107 CD 21 int 21h

1 223 0109 58 pop ax

1 224 010A 5A pop dx

225 010B B8 0000s mov ax,abc

226 print 'ax,abc='

1 227 010E 52 push dx

1 228 010F 50 push ax

1 229 0110 BA 0115r lea dx,cs:??000E

1 230 0113 EB 08 jmp short ??000F

1 231 0115 61 78 2C 61 62 63 3D+ ??000E db 'ax,abc=','$'

232 24

1 233 011D B4 09 ??000F: mov ah,9h

1 234 011F CD 21 int 21h

1 235 0121 58 pop ax

1 236 0122 5A pop dx

237 printw ax

1 238 extrn hexw : far

1 239 0123 52 push dx

1 240 0124 50 push ax

1 241 0125 8B D0 mov dx,ax

1 242 0127 0E E8 0000e call hexw

1 243 012B 58 pop ax

1 244 012C 5A pop dx

245 012D 8E C0 mov es,ax

246 012F BB 0002r lea bx,b

247

248 printw es:[bx]

1 249 extrn hexw : far

1 250 0132 52 push dx

1 251 0133 50 push ax

1 252 0134 26: 8B 17 mov dx,es:[bx]

1 253 0137 0E E8 0000e call hexw

1 254 013B 58 pop ax

1 255 013C 5A pop dx

256 println

1 257 013D 52 push dx

1 258 013E 50 push ax

1 259 013F BA 0144r lea dx,cs:??0010

1 260 0142 EB 04 jmp short ??0011

1 261 IFB <>

1 262 0144 ?? 0A 0D 24 ??0010 db ,10,13,'$'

1 263 ELSE

1 264 ??0010 db ,10,13,'$'

1 265 ENDIF

1 266 0148 B4 09 ??0011: mov ah,9h

1 267 014A CD 21 int 21h

1 268 014C 58 pop ax

1 269 014D 5A pop dx

270

271 print '1) w1='

1 272 014E 52 push dx

1 273 014F 50 push ax

1 274 0150 BA 0155r lea dx,cs:??0012

1 275 0153 EB 07 jmp short ??0013

1 276 0155 31 29 20 77 31 3D 24 ??0012 db '1) w1=','$'

1 277 015C B4 09 ??0013: mov ah,9h

1 278 015E CD 21 int 21h

1 279 0160 58 pop ax

1 280 0161 5A pop dx

281 printw w1

1 282 extrn hexw : far

1 283 0162 52 push dx

1 284 0163 50 push ax

1 285 0164 8B 16 01D7r mov dx,w1

1 286 0168 0E E8 0000e call hexw

1 287 016C 58 pop ax

1 288 016D 5A pop dx

289 println

1 290 016E 52 push dx

1 291 016F 50 push ax

1 292 0170 BA 0175r lea dx,cs:??0014

1 293 0173 EB 04 jmp short ??0015

1 294 IFB <>

1 295 0175 ?? 0A 0D 24 ??0014 db ,10,13,'$'

1 296 ELSE

1 297 ??0014 db ,10,13,'$'

1 298 ENDIF

1 299 0179 B4 09 ??0015: mov ah,9h

1 300 017B CD 21 int 21h

1 301 017D 58 pop ax

1 302 017E 5A pop dx

303

304 017F 1E push ds

305 0180 FF 36 01D7r push w1

306 0184 9A 00000000sr call pgmz

307

308

309 print '2) w1='

1 310 0189 52 push dx

1 311 018A 50 push ax

1 312 018B BA 0190r lea dx,cs:??0016

1 313 018E EB 07 jmp short ??0017

1 314 0190 32 29 20 77 31 3D 24 ??0016 db '2) w1=','$'

1 315 0197 B4 09 ??0017: mov ah,9h

1 316 0199 CD 21 int 21h

1 317 019B 58 pop ax

1 318 019C 5A pop dx

319 printw w1

1 320 extrn hexw : far

1 321 019D 52 push dx

1 322 019E 50 push ax

1 323 019F 8B 16 01D7r mov dx,w1

1 324 01A3 0E E8 0000e call hexw

1 325 01A7 58 pop ax

1 326 01A8 5A pop dx

327 println

1 328 01A9 52 push dx

1 329 01AA 50 push ax

1 330 01AB BA 01B0r lea dx,cs:??0018

1 331 01AE EB 04 jmp short ??0019

1 332 IFB <>

1 333 01B0 ?? 0A 0D 24 ??0018 db ,10,13,'$'

1 334 ELSE

1 335 ??0018 db ,10,13,'$'

1 336 ENDIF

1 337 01B4 B4 09 ??0019: mov ah,9h

1 338 01B6 CD 21 int 21h

1 339 01B8 58 pop ax

1 340 01B9 5A pop dx

341

342 01BA CB RET

343 01BB 31 32 33 34 35 36 37+ MESSAGE db '123456789ABCDEFHello....',10,13, '$'

344 38 39 41 42 43 44 45+

345 46 48 65 6C 6C 6F 2E+

346 2E 2E 2E 0A 0D 24

347 01D6 35 b1 db '5'

348 01D7 000D w1 dw 13

349 01D9 00FF w2 dw 255

350 01DB START ENDP

351 01DB CODE ENDS

352

353 0000 abc segment 'abcCODE' PUBLIC

354 0000 0001 a dw 1

355 0002 0002 b dw 2

356 0004 abc ends

357 0000 zzz segment 'zzzCODE' PUBLIC

358 assume cs:zzz

359 0000 pgmz proc far

360 0000 55 PUSH bp

361 0001 8B EC mov bp,sp

362

363 0003 8B 5E 02 mov bx,[bp+2]

364 0006 8E 46 04 mov es,[bp+4]

365

366 0009 26: C7 07 0000 mov es:[bx],word ptr 0

367

368 000E 5D pop bp

369 000F CB ret

370 0010 pgmz endp

371 0010 zzz ends

372

373 END START