944,105 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 6711
  • Assembly RSS
Jul 29th, 2007
0

Serial Port Communication

Expand Post »
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:

Assembly Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
toxicboy is offline Offline
10 posts
since Jul 2007
Jul 29th, 2007
0

Re: Serial Port Communication

i wrote this code:

Assembly Syntax (Toggle Plain Text)
  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..
Reputation Points: 10
Solved Threads: 1
Newbie Poster
toxicboy is offline Offline
10 posts
since Jul 2007
Jul 29th, 2007
0

Re: Serial Port Communication

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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
toxicboy is offline Offline
10 posts
since Jul 2007
Aug 1st, 2007
0

Re: Serial Port Communication

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
Reputation Points: 99
Solved Threads: 5
Junior Poster
Evenbit is offline Offline
140 posts
since Mar 2005
Aug 4th, 2007
0

Re: Serial Port Communication

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?
Reputation Points: 10
Solved Threads: 1
Newbie Poster
toxicboy is offline Offline
10 posts
since Jul 2007
Aug 4th, 2007
0

Re: Serial Port Communication

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
Aug 15th, 2007
0

Re: Serial Port Communication

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..

Assembly Syntax (Toggle Plain Text)
  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

Assembly Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
toxicboy is offline Offline
10 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Please help me with this code...
Next Thread in Assembly Forum Timeline: Question on Interrupts...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC