1 assume cs:code 2 code segment 3 start: 4 ;-----------安装程序------------ 5 mov ax, cs 6 mov es, ax 7 mov bx, offset openpc 8 9 mov al, 2 10 mov ch, 0 11 mov cl, 1 12 mov dl, 0 13 mov dh, 0 14 15 mov ah, 3 16 int 13h 17 18 mov ax, 4c00h 19 int 21h 20 org 7c00h 21 ;--------------启动电脑程序------------------- 22 openpc: 23 jmp short openpcstart 24 str1: db '1) reset pc', 0 25 str2: db '2) start system', 0 26 str3: db '3) clock', 0 27 str4: db '4) set clock', 0 28 str dw offset str1, offset str2, offset str3, offset str4 29 openpcstart: 30 cli 31 ;---------------读取第二扇区----------------------- 32 mov ax, 0 33 mov es, ax 34 mov bx, 7e00h 35 36 mov al, 1 37 mov ch, 0 38 mov cl, 2 39 mov dl, 0 40 mov dh, 0 41 mov ah, 2 42 int 13h 43 ;----------------------menu--------------------- 44 menu: 45 mov ax, cs 46 mov ds, ax 47 mov dh, 10 48 mov dl, 35 49 mov cx, 4 50 s1: 51 mov bx, 4 52 sub bx, cx 53 add bx, bx 54 mov si, str[bx] 55 call showstr 56 inc dh 57 loop s1 58 sti 59 s2: 60 mov ah, 0 61 int 16h 62 cmp al, '1' 63 je function1 64 cmp al, '2' 65 je jump2 66 cmp al, '3' 67 je function3 68 cmp al, '4' 69 je jump4 70 loop s2 71 72 ;----------1)function--------------------- 73 function1: 74 jmp function1body 75 address1 dw 0, 0ffffh 76 function1body: 77 jmp dword ptr address1 78 ;-------------jump---------------------- 79 jump2: 80 jmp near ptr function2 81 jump4: 82 jmp near ptr function4 83 ;----------3)function------------------- 84 function3: 85 jmp short f3body 86 address2 dw 0, 0 87 f3str1: db 'Press f1 key to change color', 0 88 f3str2: db 'or press esc to return to the menu', 0 89 f3body: 90 mov ax, cs:[9h*4] 91 mov address2, ax 92 mov ax, cs:[9h*4+2] 93 mov address2[2], ax 94 95 mov word ptr cs:[9h*4], offset newint9h 96 mov word ptr cs:[9h*4+2], 0 97 98 call clearscreen 99 mov dh, 20 100 mov dl, 20 101 mov ax, cs 102 mov ds, ax 103 mov si, offset f3str1 104 call showstr 105 inc dh 106 mov si, offset f3str2 107 call showstr 108 109 mov dh, 12 110 mov dl, 35 111 f3loop: 112 call showtime 113 jmp short f3loop 114 ;-----------4)function------------------ 115 function4: 116 jmp function4body 117 str5: db '22/12/09 12:00', 0 118 f4str1: db 'press < or > to move the cursor', 0 119 f4str2: db 'press enter key to save the changes', 0 120 function4body: 121 call clearscreen 122 mov dh, 12 123 mov dl, 33 124 mov ax, cs 125 mov ds, ax 126 mov si, offset str5 127 call showstr 128 129 mov dh, 20 130 mov dl, 20 131 mov si, offset f4str1 132 call showstr 133 mov dh, 21 134 mov dl, 20 135 mov si, offset f4str2 136 call showstr 137 138 mov ah, 2 139 mov bh, 0 140 mov dh, 12 141 mov dl, 33 142 int 10h 143 144 function4loop: 145 mov ah, 0 146 int 16h 147 cmp ah, 1ch 148 jne f4sub1 149 call setclock 150 call clearscreen 151 jmp near ptr menu 152 f4sub1: 153 cmp al, '0' 154 jb f4sub2 155 cmp al, '9' 156 ja f4sub2 157 call showchar 158 f4sub2: 159 cmp ah, 4bh 160 jne f4sub3 161 cmp dl, 33 162 jna f4sub3 163 call moveleft 164 f4sub3: 165 cmp ah, 4dh 166 jne f4end 167 cmp dl, 46 168 jnb f4end 169 call moveright 170 f4end: 171 jmp short function4loop 172 ;----------------------set clock--------------- 173 setclock: 174 jmp short setclockbody 175 port db 9, 8, 7, 4, 2 176 setclockbody: 177 push cx 178 push ax 179 push ds 180 push si 181 182 mov cx, 5 183 mov ax, 0b800h 184 mov ds, ax 185 mov si, 12*160+33*2 186 setclockloop: 187 mov bx, 5 188 sub bx, cx 189 mov al, port[bx] 190 call changetime 191 add si, 6 192 loop setclockloop 193 194 pop si 195 pop ds 196 pop ax 197 pop cx 198 ret 199 changetime: 200 ;al指向端口, ds:di指向显存中的字符 201 push ax 202 push cx 203 out 70h, al 204 mov ah, [si] 205 mov al, [si+2] 206 sub ah, '0'-0 207 mov cl, 4 208 shl ah, cl 209 sub al, '0'-0 210 or al, ah 211 out 71h, al 212 pop cx 213 pop ax 214 ret 215 ;------------show char--------------------- 216 ;al中为字符的ASCII码,dh行,dl列 217 showchar: 218 push dx 219 push di 220 push es 221 222 push ax 223 mov al, 160 224 mul dh 225 mov dh, 0 226 add dx, dx 227 add ax, dx 228 mov di, ax 229 mov ax, 0b800h 230 mov es, ax 231 pop ax 232 mov es:[di], al 233 234 pop es 235 pop di 236 pop dx 237 ret 238 ;-------------move left------------------- 239 moveleft: 240 push ax 241 push bx 242 push dx 243 mov ah, 0 244 mov al, dl 245 mov dl, 3 246 div dl 247 cmp ah, 0 248 jne mlsub2 249 pop dx 250 sub dl, 2 251 jmp short mlret 252 mlsub2: 253 pop dx 254 dec dl 255 mlret: 256 mov ah, 2 257 mov bh, 0 258 int 10h 259 pop bx 260 pop ax 261 ret 262 ;---------move right---------------------- 263 moveright: 264 push ax 265 push bx 266 push dx 267 mov ah, 0 268 mov al, dl 269 mov dl, 3 270 div dl 271 cmp ah, 1 272 jne mrsub2 273 pop dx 274 add dl, 2 275 jmp short mrret 276 mrsub2: 277 pop dx 278 inc dl 279 mrret: 280 mov ah, 2 281 mov bh, 0 282 int 10h 283 pop bx 284 pop ax 285 ret 286 ;----------展示字符串的子函数------------ 287 ;ds:si指向要展示的字符串, 以0结尾 288 ;dh指行, dl指列 289 showstr: 290 push ax 291 push dx 292 push di 293 push es 294 push si 295 296 mov al, 160 297 mul dh 298 mov dh, 0 299 add dx, dx 300 add ax, dx 301 mov di, ax 302 mov ax, 0b800h 303 mov es, ax 304 showstrloop: 305 mov al, [si] 306 cmp al, 0 307 je showstrend 308 mov es:[di], al 309 inc si 310 add di, 2 311 jmp showstrloop 312 showstrend: 313 pop si 314 pop es 315 pop di 316 pop dx 317 pop ax 318 ret 319 ;-------------clear screen--------------- 320 clearscreen: 321 push ax 322 push es 323 push di 324 push cx 325 326 mov ax, 0b800h 327 mov es, ax 328 mov di, 0 329 mov cx, 4000 330 clearscreenloop: 331 mov byte ptr es:[di], ' ' 332 add di, 2 333 loop clearscreenloop 334 335 pop cx 336 pop di 337 pop es 338 pop ax 339 ret 340 ;-----------展示时间的子函数------------ 341 ;dh:行, dl:列 342 showtime: 343 push dx 344 345 mov ax, 0b800h 346 mov es, ax 347 348 mov al, 160 349 mul dh 350 mov dh, 0 351 add dx, dx 352 add ax, dx 353 mov di, ax 354 355 mov al, 9 356 call gettime 357 mov byte ptr es:[di], '/' 358 add di, 2 359 mov al, 8 360 call gettime 361 mov byte ptr es:[di], '/' 362 add di, 2 363 mov al, 7 364 call gettime 365 mov byte ptr es:[di], ' ' 366 add di, 2 367 mov al, 4 368 call gettime 369 mov byte ptr es:[di], ':' 370 add di, 2 371 mov al, 2 372 call gettime 373 mov byte ptr es:[di], ':' 374 add di, 2 375 mov al, 0 376 call gettime 377 378 pop dx 379 ret 380 gettime: 381 out 70h, al 382 in al, 71h 383 mov ah, al 384 mov cl, 4 385 shr ah, cl 386 and al, 00001111b 387 add ah, '0'-0 388 add al, '0'-0 389 mov es:[di], ah 390 add di, 2 391 mov es:[di], al 392 add di, 2 393 ret 394 ;----------------new int9h---------------- 395 newint9h: 396 push ax 397 push es 398 push di 399 push cx 400 401 in al, 60h 402 403 pushf 404 call dword ptr address2 405 406 cmp al, 3bh 407 jne compare 408 changecolor: 409 mov ax, 0b800h 410 mov es, ax 411 mov di, 1 412 mov cx, 4000 413 changecolorloop: 414 add byte ptr es:[di], 1 415 add di, 2 416 loop changecolorloop 417 jmp short newint9hret 418 419 compare: 420 cmp al, 1 421 jne newint9hret 422 gotomenu: 423 call clearscreen 424 mov ax, address2 425 mov word ptr cs:[9h*4], ax 426 mov ax, address2[2] 427 mov word ptr cs:[9h*4+2], ax 428 mov di, sp 429 mov word ptr ss:[di+8], offset menu 430 431 newint9hret: 432 pop cx 433 pop di 434 pop es 435 pop ax 436 iret 437 438 ;----------2)function--------------------- 439 440 function2: 441 mov ax, 0 442 mov es, ax 443 mov bx, 7c00h 444 445 mov al, 1 446 mov ch, 0 447 mov cl, 1 448 mov dl, 80h 449 mov dh, 0 450 mov ah, 2 451 int 13h 452 jmp near ptr openpc 453 openpcend: 454 nop 455 456 code ends 457 end start
标签:课程设计,di,al,pop,mov,第四版,push,ax,王爽 From: https://www.cnblogs.com/thewayof10/p/16969198.html