Clarskon
Clarskon

Reputation: 159

How to set trap flag without using pop instruction

I want to set trap flag = 1, but without using pop algorithm. I know that it's possible, but I am not able to figure it out.

Upvotes: 1

Views: 1217

Answers (1)

Nate Eldredge
Nate Eldredge

Reputation: 58518

FLAGS is pushed onto the stack when an interrupt is generated, and popped from the stack by IRET. So if you are still allowed PUSHF, you could do something like

    pushf
    pop ax
    or ax, 100h
    push ax
    call far do_iret
    ...

do_iret:
    iret

If PUSHF is not allowed, you could install an interrupt handler:

handler:
    push bp
    mov bp, sp
    or word ptr [bp+6], 100h
    pop bp
    iret
set_trap_flag:
    push 0
    pop es
    mov [es:42h*4], offset handler
    mov [es:42h*4+2], segment handler
    int 42h

where 42h is some interrupt vector that's not otherwise being used.

(Note: code not tested and could have syntax errors or bugs.)

Upvotes: 1

Related Questions