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

📄 trap-out.asm

📁 linux 下svgalib编的一个界面程序示例
💻 ASM
📖 第 1 页 / 共 2 页
字号:
                                 ; IN/OUT/INT Normal INT calls would clear
                                 ; the trap flag and then INT 01h would never
                                 ; be called.
        iret                                                  ; end interrupt
INT10 endp

; function that prints the highest 4 bits of ax as text {0-9,A-F} to stdout
; ax will be shifted left 4 bits on return.
ShowHex proc
        push ax                                              ; save registers
        push dx

        shr ax,0Ch                  ; move the highest 4 bits to the lowest 4
        and al,0Fh                  ; limit to lowest 4 bits
        or  al,30h                  ; change range to 30h-3Fh {0-9:;<=>?}
        cmp al,39h                  ; if it is 30h-39h
        jbe is_0_thru_9             ; then its already set
        add al,07h                  ; otherwise change :;<=>? to A-F
    is_0_thru_9:
        mov dl,al
        mov ah,02h
        int 21h

        pop dx                                      ; restore dx
        pop ax                                      ; restore ax
        shl ax,4                                    ; set up ax for next call
        ret                                         ; return
ShowHex endp

Start:                               ; Program begins here
        mov si,0080h                 ; CS:0080h is the command line 
        cmp byte ptr [si],10         ; I want it to be at least 10 bytes long
        jae  process_command_line    ; if not, abort

        mov dx,offset no_command_line        ; ds is preset
        mov ah,09h                           ; Dos function 09h
        int 21h                              ; Display no command line string
        ret                                  ; Exit program

    process_command_line:
        inc si                  ; move si to start of actual string
        mov ax,[si+1]           ; copy first 2 chrs to ax, skipping the space
        mov bx,[si+3]           ; copy 2nd two characters to bx
        sub al,30h              ; subtract 30h so chrs 0-9 have value 0-9
        cmp al,09h              ; if its 0-9, its ok.
        jbe al_is_ok            ; if its not, its probably A-F or a-f
        sub al,07h              ; so subtract 7 more
        and al,0Fh              ; and limit to 0-F
    al_is_ok:
        sub ah,30h              ; do the same to ah
        cmp ah,09h
        jbe ah_is_ok
        sub ah,07h
        and ah,0Fh
    ah_is_ok:
        sub bl,30h              ; do the same to bl
        cmp bl,09h
        jbe bl_is_ok
        sub bl,07h
        and bl,0Fh
    bl_is_ok:
        sub bh,30h              ; do the same to bh
        cmp bh,09h
        jbe bh_is_ok
        sub bh,07h
        and bh,0Fh
    bh_is_ok:
        shl al,04h              ; Combine the values so that AL-AH-BL-BH
        or  ah,al               ; Goes into                  --AH- --AL-
        mov al,bl               ;                            <----AX--->
        shl al,04h
        or  al,bh
        mov word ptr [si],ax    ; store the value over the string
        
        mov ax,[si+6]           ; copy 3rd 2 chrs to ax, skip the 2nd space
        mov bx,[si+8]           ; copy 4th two characters to bx
        sub al,30h              ; subtract 30h so chrs 0-9 have value 0-9
        cmp al,09h              ; if its 0-9, its ok.
        jbe al_is_ok2           ; if its not, its probably A-F or a-f
        sub al,07h              ; so subtract 7 more
        and al,0Fh              ; and limit to 0-F
    al_is_ok2:
        sub ah,30h              ; do the same to ah
        cmp ah,09h
        jbe ah_is_ok2
        sub ah,07h
        and ah,0Fh
    ah_is_ok2:
        sub bl,30h              ; do the same to bl
        cmp bl,09h
        jbe bl_is_ok2
        sub bl,07h
        and bl,0Fh
    bl_is_ok2:
        sub bh,30h              ; do the same to bh
        cmp bh,09h
        jbe bh_is_ok2
        sub bh,07h
        and bh,0Fh
    bh_is_ok2:
        shl al,04h              ; Combine the values so that AL-AH-BL-BH
        or  ah,al               ; Goes into                  --AH- --AL-
        mov al,bl               ;                            <----AX--->
        shl al,04h
        or  al,bh
        mov word ptr [si+2],ax  ; store the value over the string
                             ; Now [si] contains the real values of AX and BX

        mov dx,offset tracing                      ; ds is preset
        mov ah,09h                                 ; Dos function 09h
        int 21h                                    ; Display tracing string
        mov ax,word ptr [si]                       ; Restore ax
        call ShowHex                               ; Display command line
        call ShowHex                               ;  ax value back to user
        call ShowHex                               ;  by placing it in ax
        call ShowHex                               ;  and calling ShowHex
        mov dx,offset bx_msg                       ; ds is preset
        mov ah,09h                                 ; Dos function 09h
        int 21h                                    ; Display bx message
        mov ax,word ptr [si+2]                     ; Restore bx into ax
        call ShowHex                               ; Display command line
        call ShowHex                               ;  bx value back to user
        call ShowHex                               ;  by placing it in ax
        call ShowHex                               ;  and calling ShowHex
        mov dx,offset header                       ; ds is preset
        mov ah,09h                                 ; Dos function 09h
        int 21h                                    ; Display header to output

        mov ax,3501h                ; Dos function 35h, Get vector of INT 01h
        int 21h                     ; Store it in es:bx
        mov word ptr [realINT1],bx   ; Store address of original INT 01h
        mov word ptr [realINT1+2],es ; into realINT1
        
        mov ax,3510h                ; Dos function 35h, Get vector of INT 10h
        int 21h                     ; Store it in es:bx
        mov word ptr [realINT10],bx  ; Store address of original INT 10h
        mov word ptr [realINT10+2],es ; into realINT10 so we can fake an INT

        mov ax,2501h               ; Dos function 25h, Store DS:DX to INT 01h
        mov dx,offset INT1         ; ds is preset, dx is the handler's offset
        int 21h                    ; Set new Single Step handler
        
        mov ax,2510h               ; Dos function 25h, Store DS:DX to INT 10h
        mov dx,offset INT10        ; ds is preset, dx is the handler's offset
        int 21h                    ; Set new Video Interrupt

        mov ax,word ptr [si]             ; We will use the command line ax/bx
        mov bx,word ptr [si+2]           ; values for the fake int call
        int 10h                          ; Call my int 10 which fakes the
                                         ;  real int 10 and traps it.

        mov ax,2501h               ; Dos function 25h, Store DS:DX to INT 01h
        mov dx,word ptr [realINT1] ; ds/dx are in realINT1
        push ds                    ; Save old ds
        push word ptr [realINT1+2] ; Put segment on stack
        pop ds                     ; Set ds to the segment
        int 21h                    ; Reset old Single Step handler
        pop ds                     ; Restore old ds

        mov ax,2510h               ; Dos function 25h, Store DS:DX to INT 10h
        mov dx,word ptr [realINT10] ; ds/dx are in realINT10
        push ds                     ; Save old ds
        push word ptr [realINT10+2] ; Put segment on stack
        pop ds                      ; Set ds to the segment
        int 21h                     ; Reset old Video Interrupt
        pop ds                      ; Restore old ds

        mov ax,0003h               ; Set ax to 3
        int 10h                    ; Set 80x25 Text mode
        ret                        ; End of program
end                                                             ; End of file

⌨️ 快捷键说明

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