Asm code bug, please help!
Posted: Sat Oct 18, 2003 3:47 am
I can't figure out why this code doesn't do its job correctly. It is suppost to run the User_Program: routine until a timer tick happens. Then it will return to DOS (for now).
The problem is odd. The program will run two or three times from the command prompt in DOS and most the time on the third or fourth time the program will stall.
All the stuff seems to be there thats needed? I have coded the EOI along with CLI and STI where needed but why does the program fail after being ran more then twice? This program will be ran MANY times so I need it working upto snuff.
When running a debugger I found that after being ran two times the timer routine doesn't want to reenter, thus the User_Program: that contains just a "jmp $" just loops forever and locks up the machine. If it worked correctly it would exit do to the fact that the timer 1Ch routine does its thing and exits to DOS (through a RETF).
BITS 16
ORG 100H
mov ax, cs
mov [Return_Addr], ax
mov ax, done
mov [Return_Addr + 2], ax
jmp Enter
done:
sti
int 0x20
Return_Addr: DW 0 ;Segment
DW 0 ;Offset
Enter:
XOR BX, BX
MOV ES, BX
MOV BX, [ES:1CH * 4 + 0]
MOV DX, [ES:1CH * 4 + 2]
MOV [Old_Vector + 0], BX
MOV [Old_Vector + 2], DX
CLI
MOV [ES:1CH * 4 + 0], WORD Task_Done
MOV [ES:1CH * 4 + 2], CS
STI
JMP User_Program
Task_Done:
CLI
XOR BX, BX
MOV ES, BX
MOV BX, [CS:Old_Vector + 0]
MOV DX, [CS:Old_Vector + 2]
MOV [ES:1CH * 4 + 0], BX
MOV [ES:1CH * 4 + 2], DX
MOV AL, 20H ;EOI
OUT 20H, AL ;
PUSH WORD [CS:Return_Addr + 0]
PUSH WORD [CS:Return_Addr + 2]
RETF ;Return to DOS from above..
Old_Vector: DW 0
DW 0
User_Program: ;code will go here that can only
;be ran for 18.2 x a sec MAX.
jmp $
Thanks people for your help!
The problem is odd. The program will run two or three times from the command prompt in DOS and most the time on the third or fourth time the program will stall.
All the stuff seems to be there thats needed? I have coded the EOI along with CLI and STI where needed but why does the program fail after being ran more then twice? This program will be ran MANY times so I need it working upto snuff.
When running a debugger I found that after being ran two times the timer routine doesn't want to reenter, thus the User_Program: that contains just a "jmp $" just loops forever and locks up the machine. If it worked correctly it would exit do to the fact that the timer 1Ch routine does its thing and exits to DOS (through a RETF).
BITS 16
ORG 100H
mov ax, cs
mov [Return_Addr], ax
mov ax, done
mov [Return_Addr + 2], ax
jmp Enter
done:
sti
int 0x20
Return_Addr: DW 0 ;Segment
DW 0 ;Offset
Enter:
XOR BX, BX
MOV ES, BX
MOV BX, [ES:1CH * 4 + 0]
MOV DX, [ES:1CH * 4 + 2]
MOV [Old_Vector + 0], BX
MOV [Old_Vector + 2], DX
CLI
MOV [ES:1CH * 4 + 0], WORD Task_Done
MOV [ES:1CH * 4 + 2], CS
STI
JMP User_Program
Task_Done:
CLI
XOR BX, BX
MOV ES, BX
MOV BX, [CS:Old_Vector + 0]
MOV DX, [CS:Old_Vector + 2]
MOV [ES:1CH * 4 + 0], BX
MOV [ES:1CH * 4 + 2], DX
MOV AL, 20H ;EOI
OUT 20H, AL ;
PUSH WORD [CS:Return_Addr + 0]
PUSH WORD [CS:Return_Addr + 2]
RETF ;Return to DOS from above..
Old_Vector: DW 0
DW 0
User_Program: ;code will go here that can only
;be ran for 18.2 x a sec MAX.
jmp $
Thanks people for your help!