Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22248

Efficient ways to implement in/out instructions in C/ higher level languages

$
0
0

Here are my "vanilla" assembly routines:

read_port:
    mov edx, [esp + 4]
    in al, dx   
    ret
write_port:
    mov   edx, [esp + 4]    
    mov   eax, [esp + 4 + 4]  
    out   dx, al  
    ret

read_port_word:    ;Btw is there a better way to do this??? I use gcc. Something like inb/outb?
    mov edx, [esp + 4]
    in ax, dx   
    ret

write_port_word:
    mov   edx, [esp + 4]    
    mov   eax, [esp + 4 + 4]  
    out   dx, ax
    ret

I make these global and call them in my C routines. I'm using gcc, and I suspect there are already macros for this!

Also, if I write_port_word to a port of 1 byte size, what happens? Error? Or the lower byte is transferred? Do I even need these many routines?

What is the suggested way to solve this issue?


Viewing all articles
Browse latest Browse all 22248

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>