Break of Assembly Source series

Source: Internet
Author: User

This is the past DOS era of the compilation of source code, although has passed, but for the study of the assembly is still helpful, assembly language is just a basic programmer language, most people can grasp, not necessarily in-depth research.

Title Control-break handler for lattice C programs
Name break
Include Dos.mac
;
; Control-break Interrupt Handler for lattice C programs
; Running on IBM PCs (and ROM BIOS compatibles)
;
; Ray Duncan, May 1985
;
; This module allows C programs running on the IBM PC
; To retain control when the user enters a control-break
; or control-c. This is accomplished by taking over the
; int 23H (MS-DOS Control-break) and int 1BH (IBM PC
; ROM BIOS Keyboard Driver control-break) interrupt
; Vectors. The interrupt handler sets an internal
; Flag (which must is declared STATIC INT) to TRUE within
; The C program; The C program can poll or ignore this
; Flag as it wishes.
;
; The module follows the lattice C parameter passing
; Conventions, and also relies on the lattice file DOS. Mac
; For the definition of certain constants and macros.
;
; The Int 23H control-break handler is a function of MS-DOS
; and is present on all MS-DOS machines, however, the Int 1BH
; Handler is a function of the IBM PC ROM BIOS and won't
; Necessarily is present on the other machines.
;
If Lprog
args equ 6; offset of arguments, Large models
Else
args equ 4; offset of arguments, Small models
endif
CR Equ 0DH; ASCII Carriage return
LF equ 0ah; ASCII line Feed
Pseg
Public capture,release function names for C
;
; The function CAPTURE is called by the C program to
; Take over the MS-DOS and keyboard driver control-
; Break interrupts (1BH and 23H). It is passed the
; Address to a flag within the C program which is set
; To TRUE whenever a control-break or control-c
; is detected. The function is used in the form:
;
; static int flag;
; Capture (&flag)
;
Capture proc near take over Control-break
Push BP; interrupt vectors
MOV bp,sp
Push DS
mov Ax,word ptr [Bp+args]
MOV cs:flag,ax save address of Integer
mov cs:flag+2,ds; flag variable in C
;p ick up original vector contents
MOV ax,3523h for interrupt 23H (MS-DOS
int 21h; Control-break handler)
MOV cs:int23,bx
MOV cs:int23+2,es
mov ax,351bh and interrupt 1BH
int 21h;(IBM PC ROM BIOS Keyboard driver
MOV cs:int1b,bx; Control-break Interrupt Handler)
MOV cs:int1b+2,es
Push CS; Set address of new handler
Pop ds
MOV Dx,offset CTRLBRK
MOV ax,02523h for interrupt 23H
int 21h
mov ax,0251bh and interrupt 1BH
int 21h
Pop DS; restore registers and
Pop bp;
Ret
Capture ENDP
;
; The function release was called by the C program to
; Return the MS-DOS and keyboard driver control-break
; Interrupt vectors to their original state. Int 23h is
; Also automatically restored by MS-DOS upon the termination
; Of a process, however, calling release allows the C
; Program to restore the default action of a control-c
; Without terminating. The function is used in the form:
;
; Release ()
;
Release proc near Restore Control-break interrupt
; vectors to their original state
Push BP
MOV bp,sp
Push DS
MOV dx,cs:int1b set interrupt 1BH
MOV ds,cs:int1b+2;(MS-DOS Control-break
MOV ax,251bh; interrupt handler)
int 21h
MOV dx,cs:int23 set interrupt 23H
mov ds,cs:int23+2;(IBM PC ROM BIOS Keyboard driver
MOV ax,2523h; Control-break Interrupt Handler)
int 21h
Pop DS; restore registers and
Pop bp;
Ret
Release ENDP
;
; This is the actual interrupt handler which are called by
; The ROM BIOS keyboard driver or by MS-DOS when a control-c
; Or Control-break is detected. Since the interrupt Handler
; May is called asynchronously by the keyboard driver, it
; is severely restricted in what it could do without crashing
; The system (e.g. no calls on DOS allowed). In this
; version, it simply sets a flag within the C program to
; TRUE to indicate that a control-c or control-break has
; been detected; The address is flag was passed
; By the "C" program during the "call" to the CAPTURE function.
;
CTRLBRK proc far; Control-break Interrupt Handler
Push BX; Save affected registers
Push DS
MOV bx,cs:flag set flag within C program
mov ds,cs:flag+2; to "True"
mov word ptr ds:[bx],-1
    
Pop DS; restore registers and exit
Pop bx
Iret
CTRLBRK ENDP
Flag DW 0,0 Long address of the C program ' s
; Control-break detected flag
int23 DW 0,0; original contents of MS-DOS
; Control-break Interrupt 23H
; vector
    
INT1B DW 0,0; original contents of ROM BIOS
; Keyboard driver Control-break
; Interrupt 1BH Vector
Endps
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.