⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pmprint.asm

📁 DOS保护模式下汇编程序设计.zip
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;                Protected-Mode Screen Management Procedures.
;
;
;   DS assumed to be set to flat-model data selector.  Screen address assumed at
;B8000H.  Cursor position address assumed at 450H.
;   A full explanation of each procedure is provided above the procedure.  The
;following is a brief summary of all included procedures:
;
;Procedure     Description
;PCH           Print ASCII character in AL at cursor
;CRLF          Issue carriage return and line feed
;SCRLUP        Scoll screen up
;SPC           Print AL spaces at cursor
;GETCSR        Get cursor position in AX.  AH = row, AL = column
;SETCSR        Set cursor position at (row,col) = (AH,AL)
;CLS           Clear screen
;PSTR          Print zero terminated ASCII string at ES:EBX
;PCSSTR        Print zero terminated ASCII string at CS:EBX
;PHW           Print hexadecimal WORD in AX
;PHD           Print hexadecimal DWORD in EAX
;PUW           Print unsigned WORD in AX as decimal
;PUD           Print unsigned DWORD in EAX as decimal
;PSW           Print signed WORD in AX as decimal
;PSD           Print signed DWORD in EAX as decimal
;FPST          Print ST of FPU using format in AX.  AH = characters to left of
;              decimal.  AL = characters to right of decimal.

SCRNBASEADR    EQU            000B8000H
CURPOS         EQU            00000450H

;Print ASCII code in AL at cursor.
PCH            PROC NEAR
               PUSH           EBX
               PUSH           EDX
               MOV            EDX,DWORD PTR DS:[CURPOS]     ;Cursor (row,col) in (DH,DL)
               PUSH           EDX                           ;Push cursor position
               XOR            EBX,EBX
               MOV            BL,DH                         ;Multiply row by 160
               SHL            BL,2
               ADD            BL,DH
               SHL            EBX,5
               AND            EDX,0FFH                      ;Clear all but column
               ADD            DL,DL                         ;Multiply column by 2
               ADD            EBX,EDX
               ADD            EBX,SCRNBASEADR
               POP            EDX                           ;POP cursor position
               MOV            [EBX],AL
               INC            DL                            ;Increment column
               CMP            DL,79
               JBE            RCDCURSOR
               XOR            DL,DL                         ;Move to zero column of next row
               INC            DH                            ;Move to next row
RCDCURSOR:     MOV            WORD PTR DS:[CURPOS],DX       ;Assume row is valid
               CMP            DH,24
               JA             DOSCROLL
EXIT:          POP            EDX
               POP            EBX
               RET
DOSCROLL:      CALL           SCRLUP
               JMP            EXIT
PCH            ENDP

;Clear cursor to end of line and issue CRLF.  Scroll up if necessary.
CRLF           PROC NEAR
               PUSH           EAX
               PUSH           EBX
               PUSH           ECX
               MOV            EAX,DWORD PTR DS:[CURPOS]
               PUSH           EAX                           ;PUSH cursor position
               XOR            EBX,EBX
               MOV            BL,AH                         ;Multiply row by 160
               SHL            BL,2
               ADD            BL,AH
               SHL            EBX,5
               AND            EAX,0FFH                      ;Clear all but column
               MOV            CL,80
               SUB            CL,AL                         ;Get number of bytes to clear in CL
               ADD            AL,AL                         ;Multiply column by 2
               ADD            EBX,EAX
               ADD            EBX,SCRNBASEADR
               MOV            AL,32
CLREOL:        MOV            [EBX],AL                      ;Clear to end of line
               ADD            EBX,2
               DEC            CL
               JNZ            CLREOL
               POP            EAX                           ;POP cursor position
               INC            AH                            ;Increment row
               CMP            AH,24
               JA             DOSCROLL
               XOR            AL,AL                         ;Set column to zero
               MOV            WORD PTR DS:[CURPOS],AX
EXIT:          POP            ECX
               POP            EBX
               POP            EAX
               RET
DOSCROLL:      CALL           SCRLUP
               JMP            EXIT
CRLF           ENDP

;Scroll entire screen up one line and leave cursor at start of line 24.
SCRLUP         PROC NEAR
               PUSH           EAX
               PUSH           EBX
               PUSH           ECX
               MOV            EBX,SCRNBASEADR
               MOV            ECX,960                       ;960 = (80*24*2)/4 (DWORDS to scroll)
SCROLLLOOP:    MOV            EAX,[EBX+160]
               MOV            [EBX],EAX
               ADD            EBX,4
               DEC            ECX
               JNZ            SCROLLLOOP
               MOV            CL,80
               MOV            AL,32
CLR24:         MOV            [EBX],AL                      ;Clear line 24
               ADD            EBX,2
               DEC            CL
               JNZ            CLR24
EXIT:          MOV            WORD PTR DS:[CURPOS],1800H    ;Set cursor to bottom line in zero column
               POP            ECX
               POP            EBX
               POP            EAX
               RET
SCRLUP         ENDP

;Print AL spaces at cursor.
SPC            PROC NEAR
               OR             AL,AL
               JZ             EXIT
               PUSH           EAX
               MOV            AH,AL
               MOV            AL,32
PRINTSPC:      CALL           PCH
               DEC            AH
               JNZ            PRINTSPC
               POP            EAX
EXIT:          RET
SPC            ENDP

;Set cursor location at (row,col) = (AH,AL).
SETCSR         PROC NEAR
               CMP            AH,24                         ;Do not allow row greater than 24
               JBE            CHKCOL
               MOV            AH,24
CHKCOL:        CMP            AL,79                         ;Do not allow column greater than 79
               JBE            SETCURSOR
               MOV            AL,79
SETCURSOR:     MOV            WORD PTR DS:[CURPOS],AX
               RET
SETCSR         ENDP

;Get cursor position in AX.
GETCSR         PROC NEAR
               MOV            AX,WORD PTR DS:[CURPOS]
               RET
GETCSR         ENDP

;Clear screen and leave cursor at (0,0) position.
CLS            PROC NEAR
               PUSH           EAX
               PUSH           EBX
               PUSH           ESI
               MOV            EBX,SCRNBASEADR
               MOV            ESI,1999
               MOV            AL,32
DOCLS:         MOV            [EBX+2*ESI],AL
               DEC            ESI
               JNS            DOCLS
               MOV            WORD PTR DS:[CURPOS],0H
               POP            ESI
               POP            EBX
               POP            EAX
               RET
CLS            ENDP

;Print ASCIIZ string at address in ES:EBX.
PSTR           PROC NEAR
               PUSH           EAX
               PUSH           EBX
CHARLOOP:      MOV            AL,ES:[EBX]
               OR             AL,AL                         ;See if at end of string
               JZ             EXIT
               CALL           PCH
               INC            EBX
               JMP            CHARLOOP
EXIT:          POP            EBX
               POP            EAX
               RET
PSTR           ENDP

;Print ASCIIZ string at address CS:EBX.
PCSSTR         PROC NEAR
               PUSH           EAX
               PUSH           EBX
CHARLOOP:      MOV            AL,CS:[EBX]                   ;See if at end of string
               OR             AL,AL
               JZ             EXIT
               CALL           PCH
               INC            EBX
               JMP            CHARLOOP
EXIT:          POP            EBX
               POP            EAX
               RET
PCSSTR         ENDP

;Print hexadecimal WORD in AX.
PHW            PROC NEAR
               PUSH           EAX
               PUSH           ECX
               PUSH           EDX
               MOV            EDX,EAX
               MOV            CL,4                          ;Print four nibbles
CALCNIBS:      MOV            AL,DL
               AND            AL,0FH
               ADD            AL,48
               CMP            AL,57
               JBE            PUSHDIGIT
               ADD            AL,7
PUSHDIGIT:     PUSH           EAX
               SHR            EDX,4
               DEC            CL
               JNZ            CALCNIBS
               MOV            CL,4
PRNTNIBS:      POP            EAX
               CALL           PCH
               DEC            CL
               JNZ            PRNTNIBS
               POP            EDX
               POP            ECX
               POP            EAX
               RET
PHW            ENDP

;Print hexadecimal DWORD in EAX.
PHD            PROC NEAR
               PUSH           EAX
               PUSH           ECX
               PUSH           EDX
               MOV            EDX,EAX
               MOV            CL,8                          ;Print eight nibbles
CALCNIBS:      MOV            AL,DL
               AND            AL,0FH
               ADD            AL,48
               CMP            AL,57
               JBE            PUSHDIGIT
               ADD            AL,7
PUSHDIGIT:     PUSH           EAX
               SHR            EDX,4
               DEC            CL
               JNZ            CALCNIBS

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -