Serial Port Communication

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2007
Posts: 10
Reputation: toxicboy is an unknown quantity at this point 
Solved Threads: 1
toxicboy toxicboy is offline Offline
Newbie Poster

Serial Port Communication

 
0
  #1
Jul 29th, 2007
first of all, i am using windows xp, and i am using nasm to assemble my code, and djgpp to compile it with driver.c

what i basically want to do is do a chat thing using serial ports, pretty much like Choink23 is trying to do in another thread.

here's the code i've done so far:

  1. segment .text
  2. global _asm_main
  3.  
  4. _asm_main:
  5. enter 0,0
  6. pusha
  7.  
  8. mov dx, 0 ;send 'a' through com1
  9. mov al, 'a'
  10. mov ah, 1
  11. int 14h
  12.  
  13. mov ah,3 ;check serial port status
  14. int 14h ;to check if data is available
  15.  
  16. shr ax,9 ;puts bit8 to the carryflag
  17. jc fetch ;if bit8=1, fetch
  18. jnc cont ;data is not available
  19.  
  20. fetch:
  21. mov dx, 1 ;receives 'a' from com2
  22. mov ah, 2
  23. int 14h
  24.  
  25. mov dl, al ;prints the received charac
  26. mov ah, 02h
  27. int 21h
  28.  
  29. cont:
  30. popa
  31. mov eax, 0
  32. leave
  33. ret

this code is not printing anything! i'm not sure if something's wrong with the cable, or something's wrong in the backside of my cpu, or something's wrong with my code. pls help me! thanks
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 10
Reputation: toxicboy is an unknown quantity at this point 
Solved Threads: 1
toxicboy toxicboy is offline Offline
Newbie Poster

Re: Serial Port Communication

 
0
  #2
Jul 29th, 2007
i wrote this code:

  1. segment .text
  2. global _asm_main
  3.  
  4. _asm_main:
  5. enter 0,0
  6. pusha
  7.  
  8. mov dx,0 ;send 'a' through com1
  9. mov al,'a'
  10. mov ah,1
  11. int 14h
  12. test ah,80h ;got this thing from ArtofASM
  13. jnz error
  14.  
  15. error:
  16. mov ah,02
  17. mov dl,'e'
  18. int 21h
  19.  
  20. popa
  21. mov eax,0
  22. leave
  23. ret

and when i ran it, it printed e! so does this means something's wrong with my hardware?

this chat thing should be between 2 computers, but since i only have one computer, i just plugged one end of the serial cable to com1, and the other end to com2..
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 10
Reputation: toxicboy is an unknown quantity at this point 
Solved Threads: 1
toxicboy toxicboy is offline Offline
Newbie Poster

Re: Serial Port Communication

 
0
  #3
Jul 29th, 2007
oh my i just found out that attaching the cable to com1 and the other to com2 to test my code is wrong!

i found out that what i need to do is attach it to com1 and short of short-circuit pins 2 and 3! (i am using a "cross" serial cable, this being specified in our project specifications, including how a cross serial cable looks like)

how do you do that? do i have to stick some piece of metal both on pins 2 and three?
Last edited by toxicboy; Jul 29th, 2007 at 10:51 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 130
Reputation: Evenbit is on a distinguished road 
Solved Threads: 4
Evenbit's Avatar
Evenbit Evenbit is offline Offline
Junior Poster

Re: Serial Port Communication

 
0
  #4
Aug 1st, 2007
Your best bet would probably be to look at existing (hopefully *working*) example code which you can find stored away all over the Internet. Here are some links to get you started:

http://www.programmersheaven.com/zone5/mh1.htm
ftp://ftp.simtel.net/pub/simtelnet/msdos/asmutl/
http://www.textfiles.com/programming/
http://www.nondot.org/sabre/os/artic...cationDevices/

Nathan.
Last edited by Evenbit; Aug 1st, 2007 at 2:55 pm. Reason: forum didn't like one link
while (CPU is present) {some assembly required}
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 10
Reputation: toxicboy is an unknown quantity at this point 
Solved Threads: 1
toxicboy toxicboy is offline Offline
Newbie Poster

Re: Serial Port Communication

 
0
  #5
Aug 4th, 2007
http://www.beyondlogic.org/serial/termpoll.c

above is a code from beyondlogic. i would like to basically translate this code into assembly. i would like to interface c and assembly, having inportb and outportb written in c, and the two fuction being called in asm.

can you pls. give me references on how i could write those functions in c?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,648
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Serial Port Communication

 
0
  #6
Aug 4th, 2007
The major problem you fase is the operating system you plan to use. MS-Windows and *nix will not permit programs to access the ports directly like that program you posted. Only MS-DOS will permit it.

Search some of these google links to see it they contain anything useful to you.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 10
Reputation: toxicboy is an unknown quantity at this point 
Solved Threads: 1
toxicboy toxicboy is offline Offline
Newbie Poster

Re: Serial Port Communication

 
0
  #7
Aug 15th, 2007
WHAT IS WRONG WITH THIS CODE? It's not printing anything..

i am compiling using gcc in ms-dos, and is using nasmide to assemble, which is on ms-dos as well..

  1. %define port1 3f8h
  2.  
  3. segment .data
  4. char dw 'a', 0
  5. format dw "%s", 0
  6.  
  7. segment .text
  8. global _asm_main
  9. extern _outportb, _inportb, _printf
  10.  
  11. _asm_main:
  12. enter 0,0
  13. pusha
  14.  
  15. push char ;send character to port1
  16. push port1
  17. call _outportb
  18. add esp, 8
  19.  
  20. push port1 ;receive char from port1
  21. call _inportb
  22. add esp, 4
  23.  
  24. ;mov edx, eax ;print received char
  25. ;mov ah, 02h ;using assembly
  26. ;int 21
  27.  
  28. ; i tried either way, it's not working
  29.  
  30. push eax ;print using printf
  31. push format
  32. call _printf
  33. add esp, 8
  34.  
  35. popa
  36. leave
  37. mov eax, 0
  38. ret

i am linking this code with these C code for the inport/outport functions

  1. #include <stdio.h>
  2. #include <dos.h>
  3.  
  4. int main()
  5. {
  6. int ret_status;
  7. ret_status = asm_main();
  8. return ret_status;
  9. }

thanks..

edit: also, the termpoll.c is running perfectly in my pc, i ran it on dos. i really dont understand why my asm translation is not working.. i'm stuck
Last edited by toxicboy; Aug 15th, 2007 at 6:07 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 4708 | Replies: 6
Thread Tools Search this Thread



Tag cloud for Assembly
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC