Re: How does NASM input and output from console?




"Tom Gear" asked:

I downloaded and read the NASM manual, searching for the anwser. I
searched the archive of this newsgroup.

I'm used to MASM... INT 21, INT 10, whatever, all over the place.

Can someone tell me about IN and OUT commands that send bits through
DX to an I/O port? I'd like to learn how that works.

I'd prefer to go as low level as possible for the time being. Not
that I will avoid HLL interfacing forever, or libraries. If I can
satisfy my curiosity as to "how low can you go" then I'll either write
my own procs and use them or use someone else's. What I did with MASM
was write my own procs and cut and paste them into subsequent
programs.

I've got Linux 8.0 on some kind of Intel chip, don't know right now.
If that really matters I will find out.

HW wont matter the OS in charge. Assuming you got any x86 CPU:

The I/O instructions [IN and OUT] exists in various forms:

hex-opcode |usual Mnemonic (FASM/NASM/Intel)
E4 xx IN al,(Zxb port) ;Immediate byte to address a port<0100h
E6 xx OUT (Zxb port),al ;as above
EC IN al,[dx] ;read from port
ED IN ax,[dx] ; if 16 bit operand size
ED IN eax,[dx] ; if 32 bit operand size
EE OUT [dx],al ;write to port
EF OUT [dx],ax ;if 16 bit code(op-size)
EF out [dx],eax ;if 32 bit code(op-size)
6C INSb ;[read: byte[edi]<=port[dx]; +advance EDI
6D INSw/INSq ;read ax/eax (depends on 16/32 op-size)
6E OUTSb ;[write port [dx]<=[ESI]; +advance ESI
6F OUTSw/OUTSq ; write ax or eax (16/32 bit op-size)

The group 6C..6F can be preceded by an REP instruction (F2 or F3 yet)
which uses ECX(if address-size=32) or CX (if address-size=16) as a count
until Zero loop iterator.
The 'advance' ESI/EDI either increments or decrement the register,
depending on the "D"-flag (direction-flag) within the EFL-register
(see CLD/STD instructions for details).

These ports are either byte/word/dword sized, so if you want to alter
just single bits you have to use AND/OR-masks with RD(IN)-modyfy-WR(OUT).

If you need more help just ask away.

__
wolfgang



.



Relevant Pages

  • [RFC 3/6] Char: moxa, remove port->port
    ... We don't need to hold a reference to port index. ... int close_delay; ... static int MoxaDriverPoll; ... -static void MoxaPortDisable; ...
    (Linux-Kernel)
  • [PATCH 07/19] Char: moxa, remove port->port
    ... We don't need to hold a reference to port index. ... int close_delay; ... static int MoxaDriverPoll; ... -static void MoxaPortDisable; ...
    (Linux-Kernel)
  • [PATCH 3/3] Intel IXP4xx network drivers
    ... - hardware queue manager ... endif #NETDEVICES ... +static inline void debug_desc(unsigned int queue, u32 desc_phys, ... +static int request_queues(struct port *port) ...
    (Linux-Kernel)
  • [EXPL] MSMQ Heap Overflow (Exploit)
    ... /* stub data, 8-octet aligned ... Destination port: '' ... // with a string that got longer by one unicode 'A' each time. ... unsigned int a, b, c, d, p; ...
    (Securiteam)
  • Re: Problem to read on a serial port
    ... int portOpen ... Note that none of the above ever close the serial port unless ... Your port configuration function needs to be changed. ...
    (comp.unix.programmer)