flat assembler
Message board for the users of flat assembler.

flat assembler > Linux > Writing (and maybe reading) the parallel port

Author
Thread Post new topic Reply to topic
Kikin



Joined: 22 Apr 2008
Posts: 2
Hey people:

I need to know exactly how to write to the parallel port using nasm. Do I have to open a device or something? Is there any permissions issue?

Thanks in advance...
Post 22 Apr 2008, 21:50
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16057
Location: 112 Ocean Avenue, Amityville
That is kinda weird, you're looking for a nasm solution on a fasm board!

If someone does provide the solution, then don't be disappointed if it comes in fasm format. Be prepared to convert it of you need to.
Post 23 Apr 2008, 02:32
View user's profile Send private message Visit poster's website Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
Set your bios as Bidirectional Parallel port mode (SPP) Wink

This set I/O permission
Code:
mov eax,101                      ; SYS_IOPERM
mov ebx,Base_Parallel         ; 378H
mov ecx,Size                      ; 3
mov edx,1                         ; Turn ON
int 80H
test eax,eax
js Error_Set_IO
    


to write

Code:
mov dx,37ah
in al,dx
and al,11011111b             ; reset bit 5 ( Write mode)
out dx,al  

mov al,0ffh                         ; turn on all 8 pin
mov dx,378h
out dx,al                           ; Write byte

    

to read
Code:

mov dx,37ah
in     al,dx
or     al,00100000b          ; set bit 5 ( Read mode)
out   dx,al

mov dx,378h
in    al,dx                        ; Read byte
    
Post 23 Apr 2008, 09:57
View user's profile Send private message Reply with quote
Kikin



Joined: 22 Apr 2008
Posts: 2
Ok, first of all, sorry for posting this issue here, but it was the only forum referring assembly I could find and since the question was more OS-specific rather than assembler-specific I decided it wouldn't hurt anybody's feelings.

Thanks DJ Mauretto, I still don't understand quite well the part where you set/reset bit 5 on port 37ah, but it looks great, can't wait to try it out.

Just one question, do I need to run my program as root in order to get permission with ioperm?
Post 24 Apr 2008, 03:33
View user's profile Send private message Visit poster's website Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
Quote:
Just one question, do I need to run my program as root in order to get permission with ioperm?


yes Wink (sudo)
Quote:
I still don't understand quite well the part where you set/reset bit 5 on port 37ah, but it looks great, can't wait to try it out.

When the parallel port is bidirectional mode it use same 8 pin for IN/OUT,
you must tell at the controller ( port 37ah) that you want perform a Read or Write operation,with bit 5 you select Write or Read operation Very Happy

Remember to set Bidirectional mode in your Bios.
Note that if you need only to Write then forget bit 5 and bidirectional mode,
the only code that you need is:
Code:
mov dx,378h
mov al,Value                    ; Value to Write
out  dx,al
    

Parallel port is standard from 20 years ,there are many tutorial on line
this is only a simply way to go ,but you can do it better and more learning
about Paralel Port Smile
Post 24 Apr 2008, 09:41
View user's profile Send private message Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Umm, to read/write to the parallel port don't you just open "/dev/lp0" for reading/writing using the standard open/read/write/close syscalls, and let the kernel do all the hard stuff like buffering, etc...

PS. If you want to talk directly to the port as described, then yes you'll need to run as root (or set your application as setuid root).
Post 28 Apr 2008, 02:46
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.