V
V
Vladimir Borovik2016-04-26 16:55:59
assembler
Vladimir Borovik, 2016-04-26 16:55:59

Why does the resident handler crash when calling the 4ch interrupt 21h function?

I wrote a resident program, everything works, but if my or other programs call the 4ch interrupt 21h function, the console stops responding to pressing, although the cursor blinks. I need to call this function to exit a copy of the program on restart. Also, if after loading I call the mem program, the console stops responding to pressing, although the cursor blinks. Most likely this is due to the replacement of the interrupt vector, but I can’t figure out what exactly is wrong. I will be grateful for help.

code segment
  old_int09 dd 0
  old_int2Fh dd 0
  message1 db "Programm already runs", 10, '$'
  message2 db "Programm unloaded", 10, '$'
  assume cs: code
  jmp start

  new_int2Fh  proc  far
    cmp ax,0FF00h
    jz installed
    jmp dword ptr cs:old_int2Fh
    installed:
    mov ax,00FFh
    iret
  new_int2Fh  endp

  new_int09h proc
    pushf
    call old_int09
    pushf
    push ax
    push dx
    push bx
    push cx
    push si
    push ds

    mov ah, 01h
    int 16h
    cmp al, 24
    je write_data
    cmp al, 19
    je unload
    jmp return

    write_data:
    push 0f000h
    pop ds
    mov ah, 02h
    mov bx, 0e00eh
    mov cx, 103
    mov si, 0
    write_hex:
    cmp byte ptr [bx][si], 0
    je continue1
    mov dl, [bx][si]
    call write_byte
    continue1:
    inc si
    loop write_hex
    call new_line
    call new_line
    mov cx, 103
    mov si, 0
    write:
    cmp byte ptr [bx][si], 0
    je continue2
    mov dl, [bx][si]
    int 21h
    continue2:
    inc si
    loop write
    call new_line
    mov ah, 00h
    int 16h
    jmp return

    unload:
    mov ah, 00h
    int 16h
    mov ax, 2509h
    mov dx, word ptr old_int09
    mov ds, word ptr old_int09+2
    int 21h
    mov ax, 252fh
    mov dx, word ptr old_int2Fh
    mov ds, word ptr old_int2Fh+2
    int 21h
    mov ah, 09h
    push cs
    pop ds
    mov dx, offset message2
    int 21h
    mov ax, 04c00h
    int 21h
    return:
    pop ds
    pop si
    pop cx
    pop bx
    pop dx
    pop ax
    popf
    iret
    new_int09h endp
start:
  main proc far
    mov ax, 0FF00h
    int 2Fh
    cmp ax, 00FFh
    jne first_start
    mov ah, 09h
    push cs
    pop ds
    mov dx, offset message1
    int 21h
    mov ax, 4c00h
    int 21h

    first_start:
    push cs
    pop ds
    mov ax, 3509h
    int 21h
    mov word ptr old_int09, bx
    mov word ptr old_int09+2, es
    mov ax, 2509h
    mov dx, offset new_int09h
    int 21h
    mov ax, 352fh
    int 21h
    mov word ptr old_int2Fh, bx
    mov word ptr old_int2Fh+2, es
    mov ax, 252fh
    mov dx, offset new_int2Fh
    int 21h

    mov dx, (start - new_int09h +0fh)/16
    mov ah, 31h
    int 21h
  main endp

write_byte proc
    push ax
    push cx
    push dx
    mov ah, 02h
    mov cx, 2
    mov dh, dl
    shr dh, 4
    and dl, 0fh
    xchg dl, dh
    push dx
    write_sign:
    cmp cx, 1
    jne second_sign
    pop dx
    shr dx, 8
    second_sign:
    cmp dl, 9
    jle number
    add dl, 7
    number:
    add dl, '0'
    int 21h
    loop write_sign
    mov dl, ' '
    int 21h
    pop dx
    pop cx
    pop ax
    ret
write_byte endp

new_line proc
    mov ah, 02h
    mov dl, 10
    int 21h
    ret
new_line endp

code ends
end start

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2016-04-26
@borovik_96

mov dx, (start - new_int09h +0fh)/16

And why such a size of reserved memory? Is it exe or com?
You have functions called from the resident part after start:
write_data corrupts ds.

V
Vladimir Kuts, 2016-04-26
@fox_12

What OS are you running under?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question