Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
xor bx,bx
xor ax,ax
mov ss,ax
mov ax,cs
cli
mov word [ss:(0x20*4)],Int20_handler
mov word [ss:(0x20*4+2)],ax
sti
jmp normal
Int20_handler:
cmp ah,0x00
je mep
ret
mep:
blahblahblah
IRET
normal:
...
xor bx,bx
xor ax,ax
mov ss,ax
mov ax,cs
cli
mov word [ss:(0x20*4)],Int20_handler
mov word [ss:(0x20*4+2)],ax
sti
jmp normal
Int20_handler:
cmp ah,0x00
je mep
ret
mep:
blahblahblah
IRET
normal:
...
btw which address mode the statement mov word [ss:(0x20*4)],Int20_handler belong to?
what is the value for SP at that time ? zeroing the stack segment without altering the stack pointer looks like commiting suicide in real mode: as your stack grows it could destroy its interrupt handlers or the BIOS data area ...
If you need a 0-segment, rather use GS or FS or ES if DS is busy for other things, but using SS sounds really weird to me ...
well, if SS was different from 0 before entering the INT 20h setup function, it will definitiely cause trouble by the time you'll issue a RET instruction, as the return address will no longer be the same ...
avoid toying with the stack segment if you don't have to switch to another stack ...