Simple procedure to receive character from serial port

Hi

I have a procedure getchar() which is in called in a C program and implemented in assembly. It is basic function which check the status of the serial controller and gets the data from the buffer. The code for the procedure is as such.

-----------------------------------------------------------------------

_getchar PROC FAR ;Retrieve a character from serial port

NO_CHAR:

mov dx,LSR ;Status Register of Serial Port
in al,dx
and al,00000001B ;Test whether a byte has been received
cmp al,0
jz NO_CHAR ;No character recieved

;Character received

mov dx,SRB ;Serial Receive Buffer
in al,dx ;Get character received
out dx,al ; ? ? ?
ret

_getchar ENDP

-----------------------------------------------------------------------

In the C code, the function is called as follows.
.
.
.
char *msg
msg=getchar()
if (msg='1')....
.
.
.

I do not understand how the character recieved in the assembly function is passed back to the C program. Would someone kindly advise? I am also unsure why we have to output contents of "AL" to "DX" (the last line of code)? Lastly, does the procedure return an 8bit data?

Regards
Wilson

Comments

  • :[code]
    : _getchar PROC FAR ;Retrieve a character from serial port
    :
    : NO_CHAR:
    :
    : mov dx,LSR ;Status Register of Serial Port
    : in al,dx
    : and al,00000001B ;Test whether a byte has been received
    : cmp al,0
    : jz NO_CHAR ;No character recieved
    :
    : ;Character received
    :
    : mov dx,SRB ;Serial Receive Buffer
    : in al,dx ;Get character received
    : out dx,al ; ? ? ?
    : ret ;[red]Since the value must be returned in AX,
    : ;it is still in the correct place.[/red]
    :
    : _getchar ENDP
    :[/code]

    Davi Medrade
    Master Programmer of Agnetron Software Ltda.
    davimedrade@hotmail.com
    So Paulo, Brazil


  • Thank you for your reply.

    Can you also explain why the statement "out dx,al" is neccesary?

    Thank you again in advance.
  • Sorry, but i dont know that...

    I think it is needed to sign to the Serial Controller (16550, I think) that we have just read that byte, so, it can send another byte. Its for preventing that it send a byte before we read the preceding.

    Note: I am not shure about it, then, try asking other people...

    If you need help, mail me!
    Davi Medrade
    Master Programmer of Agnetron Software Ltda.
    davimedrade@hotmail.com
    So Paulo, Brazil

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories