Wang Shuang's learning process of the third edition of assembly language experiment 13

Posted by Liquid Fire on Wed, 01 Jan 2020 20:22:58 +0100

Write and apply interrupt routine

First interrupt routine:
Requirement:
Write and install int 7ch interrupt routine. The function is to display a string ending with 0. The interrupt routine is installed at 0:200.
Parameters: (DH = row number, (DL = column number, (cl) = color, ds:si points to the first address of the string.

Assembly code:

assume cs:codesg

codesg segment
        mov ax, cs
        mov ds, ax
        mov si, offset print_str    ;source address

        mov ax, 0
        mov es, ax
        mov di, 200h                ;Destination address

        mov cx, offset print_str_end - offset print_str
        cld

        rep movsb

        mov word ptr es:[7ch*4], 200h
        mov word ptr es:[7ch*4+2], 0    ;Set interrupt vector table

        mov ax, 4c00h
        int 21h

 print_str: 
        push es
        push ax
        push bx
        push cx
        push dx     
        push di
        push si

        mov ax, 0b800h
        mov es, ax                   ;Initialize memory

        mov al, 0a0h
        sub dh, 1
        mul dh
        mov bx, ax      ;Row calculation

        sub dl, 1
        add dl, dl
        mov dh, 0
        mov di, dx      ;Column calculation

        mov al, cl      ;output color
        mov cx, 0       ;Used as end judgment
        mov si, 0       ;String pointer

   print_s:
        mov cl, [si]
        jcxz print_ok

        mov es:[bx][di], cl
        mov es:[bx][di+1], al
        inc si
        add di, 2       ;Pointer back offset

        jmp short print_s

   print_ok:
        pop si
        pop di
        pop dx
        pop cx
        pop bx
        pop ax
        pop es
        iret

   print_str_end:
        nop         ;Free a byte to calculate code length
codesg ends
end

Operation result:

The second interrupt routine:
Requirement:
Write and install the int 7ch interrupt routine, which is used to complete the loop instruction.
Parameter: (cx) = number of cycles, (bx) = displacement.

Assembly code:

assume cs:code

code segment
 start:
        mov ax, cs
        mov ds, ax
        mov si, offset copy_loop

        mov ax, 0
        mov es, ax
        mov di, 200h

        mov cx, offset copy_loop_end - offset copy_loop
        cld

        rep movsb

        mov word ptr es:[7ch*4], 200h
        mov word ptr es:[7ch*4+2], 0

        mov ax, 4c00h
        int 21h

------------------------------------------------
--------------------copy_loop-------------------
-------Parameters:(cx)=Number of cycles,(bx)=Movement displacement---------
------------------------------------------------
 copy_loop:
        push bp

        dec cx
        jcxz loop_ok            ;cx 0, end of loop

        add [bp+2], bx          ;IP+displacement

   loop_ok:
        pop bp
        iret

   copy_loop_end:
        nop

code ends
end start

Operation result:

The third interrupt routine:
Space one: [si]
Space two: [bx]
Space 3: inc si
Space 4: add bx, 2