hi guys , what am i doing wrong here, i have instigated several approaches, in assembly 8086 using borland/turbo 7.0 pascal on win 98se (so i can communicate easily to parallel port and stipulation of assignment)

my issue lies with being able to allow execution of a looped routine but keep a constant listen out for a keypress from the keyboard, at the point of the keypress the routine should jump to a call which then runs and returns back to the main routines loop.

i have done as much as i can using interrupts but alas , even with the "Advanced ms-dos programming bible" i seem to lack the knowledge to search for or instigate the all encompassing int that will handle my needs. (i am aware of using int 9 to create my own interrupt etc , but again maybe out of my initial grasp)

please view the code below and if poss give me a direction to take :)

Any reply is welcome but. i also really need the help of someone capable of explaining where i may have gone wrong, so that i may learn to put it right. (maybe a dummy code example , that i can identify simalarities with my own code problem) just a thought, if you want to tell me straight out what to do it will probably save me time, but can one learn from an answer without knowing the right question ?
(....................FOR NOOBS, LIKE ME........................................)
THE SYNTAX HIGHLIGHTING MAKES IT A BIT DIFFICULT TO READ I THINK, BUT HOPE IT ALL STILLS MAKES SENSE, WHERE THERE IS A {}, THIS HOLDS A COMMENT SO IGNORE ANY
HIGHLIGHTING IN THESE CURLY BRACES. THAKN AGAIN ANY HELPERS OUT THERE :)
(..............................................................................)

PROGRAM light_interrupt;
{******gruffy321 2011**********}
{prog designed to loop through a sequence sent to the parallel port...}
{and continually listen for  keyboard press ("p" or "P" in this case) during the loop}
{upon the keypress of "p" or "P" it should je(jump if equal) to a sub routine, if the keypress....} 
{is nt equal to "p"or"P" then it should return to the main program loop}
LABEL {these are labels attached to jumps and calls}
loop_1,
loop_2,
loop_3,
loop_4,
loop_5,
listen,
keypress,
wait,
state_1,
state_2,
state_3;

BEGIN
    ASM
       mov dx, $378 {put $378 (parallel port address) into register dx}
					{used to send signal to binary led display}
					
{*********start main routine here**********}
call listen			{call the listen sub-routine to check for a keypress}

state_1:
{below is just a noob way of ensuring reg`s are all at zero...}
{i know i know, but it works for right now}
   mov ax, 0000h	{fill ax with 0`s}
   mov bx, 0000h	{fill bx with 0`s}
   mov cx, 0000h	{fill cx with 0`s}
       mov ax, $81	{mov $81 TO ax}
       out dx, ax	{send out to parallel port}
       call wait	{call the wait sub-routine}

call listen			{call the listen sub-routine to check for a keypress}

state_2:
   mov ax, 0000h	{fill ax with 0`s}
   mov bx, 0000h	{fill bx with 0`s}
   mov cx, 0000h	{fill cx with 0`s}
       mov ax, $18	{mov $18 TO ax}
       out dx, ax	{send out to parallel port}
       call wait	{call the wait sub-routine}

call listen			{call the listen sub-routine to check for a keypress}

state_3:
   mov ax, 0000h	{fill ax with 0`s}
   mov bx, 0000h	{fill bx with 0`s}
   mov cx, 0000h	{fill cx with 0`s}
       mov ax, $2C	{mov $2C TO ax}
       out dx, ax	{send out to parallel port}
       call wait	{call the wait sub-routine}
	   
{**********lissten sub routine**********}
   listen:
        push ax			{push registers ax, bx , cx, si , sp to stack}
        push bx
        push cx
        push si
        push sp
             mov ah, 01		{initialise int 21}
             INT 21H		{***THIS PLACES 70 INTO AL*********}
             mov bh, "p"	{i move "p" into reg bh}
             cmp al, bh		{compre thesse two values}
             je keypress	{if equal go to keypress sub-routine zero flag should =0}
             jnz state_1	{if zero flag not set = 0 then return to main loop at this point)}
             mov ch, "P"	{same as above , but for "P"}
             cmp al, ch
             je keypress
             jnz state_1
        pop ax			{pop all values ax, bx, cx, si, sp back from stack}
        pop bx
        pop cx
        pop si
        pop sp

   ret		{return to main routine}
       
{********countdown delay  sub routine***********}

      wait:		{a decrement loop to nake a time delay}
             mov ah, $1			{currently very small due to debug and stepping through}
								{change to larger hex value for more realistic time countdown}
             loop_3:
			 
             mov bx,$1			{currently very small due to debug and stepping through}
								{change to larger hex value for more realistic time countdown}
             loop_2:
			 
             mov cx, $1			{currently very small due to debug and stepping through}
								{change to larger hex value for more realistic time countdown}
             loop_1:
			 
             dec cx				{decrement reg cx}
             jnz loop_1			{return to loop until register in cx holds 0}
             dec bx				{decrement reg bx}
             jnz loop_2			{return to loop until register in bx holds 0}
             dec ah				{decrement reg ax}
             jnz loop_3			{return to loop until register in ah holds 0}

call state_1	{return to main routine loop}

{************keypress routine**********}
      keypress: 	{sub-routine that occurs due to keypress of "p" or "P"from keyboard}
        push ax		{push registers ax, bx , cx, to stack}
        push bx
        push cx
             mov ax, $A1
             out dx, ax	{send out to parallel port}
             mov cx, $F
             loop_5:		{loop label}
             mov bx, $F
             loop_4:
             dec bx
             jnz loop_4
             dec cx
             jnz loop_5
        pop ax		{pop all values ax, bx, cx, back from stack}
        pop bx
        pop cx
      ret
{**********************}

    END;

END.

thanks again for any helps peeps
Gruffy 321

please people, anything ? ...... i have asked the wrong question ? is it something so difficult that the microcosm of dani web does not get it either, surely not i say :)
...ave i don it right and just have my ordering of code wrong ?
i dunno , its upsetting thtas for sure :(

Few problems in your code.
First, your pops are in a wrong order. The last thing pushed shall be first to pop.
Second, can you explain line 105? The way it is written, you are (a) jailed to state_1 and (b) bound to a stack overflow.

Few problems in your code.
First, your pops are in a wrong order. The last thing pushed shall be first to pop.
Second, can you explain line 105? The way it is written, you are (a) jailed to state_1 and (b) bound to a stack overflow.

(1st) these are the obvious things i am hoping one day to spot, thanks :)
(2nd)at line 105.. , i coded it to refer to the label state_1 in case the sub-routine looped infinitely (i am guessing i have done this wrong, due to newbieness)

So, if poss, could you tell me if the direction i am taking will succesfully create a situation where the program will loop around untill a key is pressed and then run to a new sub routine (keypress routine) complete keypress loop and return to main routine?

Thanks for answering in the first place "nezachem" and thanks for reading this, if you get back to it etc :) gruffy321

> (2nd)at line 105..

The wait label is entered via a call instruction, so logically the control shall be relinquished by ret , shouldn't it?
In your case, the control is always getting back to state_1 , so no other state is possibly reachable. That is, listen is never called.
Besides, each call wait deposits a return address on the stack, and without ret it is never cleaned up, meaning the stack grows indefinitely.
So, make wait a proper subroutine, see what happens, and which new problems appear.

> Thanks for answering in the first place "nezachem"

Never mind. I solve problems

Nazchem, i am sensing you are a genius of sorts , or atleast know your stuff...
Is there a way you might show me what to code step by step, as i have been on this for days and days now and, although i can appreciate the eureka moment of discovering the answer through gentle pointers. I am really frustrated my lecturer has given such a task (i want o get into asm in c or 32 asm at least but am stuck with trying to work this out in 16 bit turbo pascal assembler)

It all to do with bloody parallel communication and that fact (correct me if wrong) one cannot communicate with it after winXP etc making this project a bit difficult to achieve....im just so stuck and am losing my thread a little on it

Totally cool if not as your advice has been excellent as of this moment and i really appreciate that you even bothered, as i seem to have had little else in the way of reply posts.

THANKS, once again and again and again.
Gruffy
PS am just going to adjust my code to be inline with what you have already said, here goes nothing :)

right have changed end of wait routine to "ret" instead of "call state_1" and sorted push/pop issue

when i run the program, no light sequence occurs and if i press a key other than "p" the prog bums out and returns to ide shutting down turbo 7 and giving me an illegal operation msgbox.
(if i run the prog and press "p" that prog does something cos it doesnt crash, but nothing seems to happen and i have to press Ctr+Break to get out of the program )

am i biting off more than i can chew or is this a mountain out of a mole hill im making ?
i dunno
thanks for reading :)

Right, first of i would like to thank Nezachem for his contributions but. Aside from his valiant attempt to understand and engage in my coding problem, the rest of you shyed away, pretending this type of problem to be beneath you or perhaps the truth (it scared you), well there are many other forums out there people and i think those of you who are new should know this - unless your problem is easy to understand and something that most people can post a link or two to a website that also generally lacks in ability to teach someone new or returning to code.

This is shameful and strikes me as a community spirit, once famed among the newbie whispers for its amazing responses and guidance, is no longer in occupancy or responsive to the zeitgeist of coding and its growth in hungry new takers/returners.
FOR THE SAKE OF MOVING THIS THRED TO ANSWERED I HAVE POSTED THE CODE BELOW WHICH DOES , INDEED, CARRY OUT THE PROCESS OF RUNNING THE PROGRAM, WHILE LISTENING FOR A KEYBOARD INTERRUPT. IT IS POSSIBLE AND NOBODY HERE SPOTTED IT, EXCEPT Nezachem (toots to this muthaf*ckin dude, he has balls , I like balls).
Of course , this is only my opinion and before some one pipe up and says "perhaps you weren`t asking the right question" or "steady on you shouldn`t expect a flux of people just waiting to answer to your needs" - well you are right, i shouldn`t and i do not. however i do believe in the community and real help when you can see genuine need of it....
do you know, in another section of this site, i simply asked - http://www.daniweb.com/software-development/c/threads/361265 (follow this link to see it, if you wish)


"hi all , can i access the parallel port using c`s assembly language syntax and using windows 98 se as the os or xp if i could (dont think xp is possible though, i dunno?)
AOAP

Thanks for reading , gruffy
bw , if is possible can i get direction to interrupt handling in C and how to catch port 378 and the keyboard for a keypress (hopefully an interrupt out there that can listen for keypress and not make the program wait until there is one ) "

anyway this was the reply i got ....

"2 Days Ago
This post is useful and well-written 0 This post is unclear
Re: can i access the parallel port using c assembly language in win98 se
Windows has always allowed programs to use the various ports and keyboard input. Can you do it without working through Windows on Win98 SE, -- I'm not sure.

If you're thinking about making a keylogger, stop right there. They have a serious risk of being misused - whether it's by you, or by someone else who stumbles upon the program. They have very little reason to exist that is not illegal, or immoral, and no one here will help you code one up. "Just to see if I can... just to study how it works...just to learn more about the system... NONE OF IT sounds credible in the least.

Give up on the keylogger idea, as fast as you can. They are nothing but trouble, even if you are a saint and would not abuse it -- because others would hear about it, or stumble across it, copy it, and then THEY would abuse it. "

Not overly rude in the first instance, but give it a minute and re read it, tis a bit presumptuous on that guys part, and an example of my point.

That was all and thankyou once again nezachem, for stepping up, you should stand tall

Gruffy321
CODE AS STATED, FINISHED AND WORKING
(THANKS TO ALL WHO GUIDED ME WHEN I NEEDED IT, I HOPE TO PAY IT FORWARD)

PROGRAM PELICAN_light_interrupt;
{******gruffy321 2011**********}
{prog designed to loop through a sequence sent to the parallel port...}
{and continually listen for  keyboard press ("p" or "P" in this case) during the loop}
{upon the keypress of "p" or "P" it should je(jump if equal) to a sub routine, if the keypress....}
{is not equal to "p"or"P" then it should return to the main program loop}
LABEL {these are labels attached to jumps and calls}
loop_1,
loop_2,
loop_3,
loop_4,
loop_5,
keypress,
wait,
start,
state_1,
state_2,
state_3,
state_4,
finish_prog,
flash_amber,
pelican_lights;

BEGIN
    ASM
       mov dx, $378 {put $378 (parallel port address) into register dx}
					{used to send signal to binary led display}
start:
{*********start main routine here**********}
			{call the listen sub-routine to check for a keypress}

state_1:{green/red state}
       mov al, $24	{mov $81 TO ax}
       out dx, ax	{send out to parallel port}
       call wait	{call the wait sub-routine}
       call wait

state_2:{amber/red amber state}
       mov al, $46	{mov $18 TO ax}
       out dx, ax	{send out to parallel port}
       call wait	{call the wait sub-routine}

state_3:{red/green state}
       mov al, $81	{mov $2C TO ax}
       out dx, ax	{send out to parallel port}
       call wait	{call the wait sub-routine}
       call wait

state_4:{red amber/amber}
       mov al, $C2       {mov $C2 TO ax}
       out dx, al        {send out to parallel port}
       call wait         {call the wait sub-routine}

       call keypress     {call the keypress sub-routine}
call state_1             {return loop to state_1}
{***********************************************}
{***************Time delay**********************}
{a decremental loop to make a time delay}
wait:
             mov ah, $5f	{currently very small due to debug and stepping through}
	                        {change to larger hex value for more realistic time countdown}
             loop_3:

             mov bx,$0fff	{currently very small due to debug and stepping through}
	                        {change to larger hex value for more realistic time countdown}
             loop_2:

             mov cx, $0fff	{currently very small due to debug and stepping through}
	                        {change to larger hex value for more realistic time countdown}
             loop_1:

             dec cx		{decrement reg cx}
             jnz loop_1		{return to loop until register in cx holds 0}
             dec bx		{decrement reg bx}
             jnz loop_2		{return to loop until register in bx holds 0}
             dec ah		{decrement reg ah}
             jnz loop_3		{return to loop until register in ah holds 0}

ret	{return to main routine loop}

{************keypress routine**********}
{sub-routine that occurs due to keypress of "p" or "P"from keyboard}
      keypress:
             mov ah, 01h
             int 16h
                 cmp al, 'p'
                 je pelican_lights
                 cmp al, 'P'
                 je pelican_lights
                 cmp al, 'q'
                 je finish_prog
                 cmp al, 'Q'
                 je finish_prog
ret
{***************************************}
{*********Pelican light sequence********}
      pelican_lights:
      mov dx, $378 {make sure we have outport}

      mov al, $24 {wait on green wait for traffic to pass}
      out dx, al  {send out to parallel port $378}
      call wait

      mov al, $44 {amber_red}
      out dx, al  {send out to parallel port $378}
      call wait


      mov al, $84+$18 {red,red + pelican walk middle lights}
      out dx, al {send out to parallel port $378}
      call wait  {long wait}
      call wait
      call wait
      call wait

      mov ah, $04 {start loop}
      flash_amber:{pedestrian light state}
      push ax     {save inner loop state to stack}
      mov al, $04 {Blank State, Amber + offset}
      out dx, al  {send out to parallel port $378}
      call wait

      mov al, $44  {all red status}
      out dx, al   {send out to parallel port $378}
      call wait

      pop ax       {retrieve ah loop state from stack}
      dec ah
      jnz flash_amber {jump if zero flag set to 1}
      mov ah, $00  {initiate interrupt 16H}
      int 16h      {use interrupt 16H}
ret
{***********finish program sub-routine}
{on result of pressing "q"or "Q" during program execution}
      finish_prog:
                mov ax, $4c00 {exit dos code}
                int 21        {execute to dos using int21}
{*************************************************************}
{*************************************************************}
{**        ***  **  **       ***       **   *****  **     ****}
{*****  ******  **  **  ********  *******    ****  **      ***}
{*****  ******  **  **  ********  *******  *   **  **  **   **}
{*****  ******      **     *****     ****  **   *  **  **   **}
{*****  ******  **  **  ********  *******  ***     **  **   **}
{*****  ******  **  **  ********  *******  ****    **      ***}
{*****  ******  **  **       ***       **  *****   **     ****}
{*************************************************************}
{**********GRUFFY 2011 FdSc COMPUTING YEAR1 ******************}
   end;
end.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.