Jump to content

general question about i/o in assembly

- - - - -

  • Please log in to reply
12 replies to this topic

#1
SteveC

SteveC

    Newbie

  • Members
  • Pip
  • 5 posts
Hello,
I have a series of related questions and if you think I should post them separately please say so.
So far I've made console programs & window programs where macros have handled user input and output, but just for the sake of learning (not for efficiency, obviously!) I want to learn how to address ports etc. Like in a grass-roots way without includes. Some specific questions I have are:

1. are interrupts the same in x64 and x86

2. do proper programs use interrupts like 21 9, also how would a program like microsoft word take your input and output it to the screen

3. how do you tell the computer to colour in a particular pixel, for example given the information below for a display adaptor does anyone know the role of the different memory and i/o ranges and how you would use them in assembly?
Memory Range 00000000e0000000-00000000efffffff
Memory Range 00000000f0020000-00000000f003ffff
i/o range d000-d0ff
irq 0xfffffffe (-2)
i/o range 03b0-03bb
i/o range 03c0-03df
memory range 00000000000a0000-00000000000bffff

4. how does a program know from computer to computer what port and memory is given to a device or is it generally the same?

Sorry if the questions are asking too much & thank you very much if you can answer even just a small aspect of one of them.

#2
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,251 posts
  • Location:C:\Countries\US
I don't know whether I am right or wrong, but as far as I know Windows PE programs are structured sort of like this:
section: rdata
exitprocess DWORD ?
section: code
call ExitProcess
section: code
ExitProcess: jmp dword ptr [exitprocess]

So that the PE loader loads the actual address of the ExitProcess() function into the 'exitprocess' dword, so the program can call that function using some sort of that method. I do not know how the assembler or the PE loader knows where to load what address, though.

And interrupts and input/output instructions are generally not allowed for regular programs to use.

Correct me if I'm wrong, but this is as far as I know.

#3
SteveC

SteveC

    Newbie

  • Members
  • Pip
  • 5 posts
Thanks RhetoricalRuvim for the heads up about portable executables, which I didn't know about
I will do some looking around on how they get system information:thumbup:

#4
Slider

Slider

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
Here are some sites than can help you.

Andy

ASM Community Messageboard - Index
The MASM Forum - Index
The winasm.net programming forum

#5
Gunner

Gunner

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Comment inline

SteveC said:

Hello,
I have a series of related questions and if you think I should post them separately please say so.
So far I've made console programs & window programs where macros have handled user input and output, but just for the sake of learning (not for efficiency, obviously!) I want to learn how to address ports etc. Like in a grass-roots way without includes. Some specific questions I have are:

1. are interrupts the same in x64 and x86
Windows program do not use interrupts directly, maybe you can in RING 0?

2. do proper programs use interrupts like 21 9, also how would a program like microsoft word take your input and output it to the screen
As in #1, int is not used in Windows programming, DOS/16bit code, yes. Well, int 3 is used often :) MS Word uses COM and OLE, to make a simple text editor you would use SendMessage and the message WM_GETTEXT for "input" and to use WM_SETTEXT for "output", or DrawText there are many ways...

3. how do you tell the computer to colour in a particular pixel, for example given the information below for a display adaptor does anyone know the role of the different memory and i/o ranges and how you would use them in assembly?
Memory Range 00000000e0000000-00000000efffffff
Memory Range 00000000f0020000-00000000f003ffff
i/o range d000-d0ff
irq 0xfffffffe (-2)
i/o range 03b0-03bb
i/o range 03c0-03df
memory range 00000000000a0000-00000000000bffff
you cannot access irqs, ports, memory (of other programs) you need to use the Windows API, to draw text in a differant color, you would use the RichEdit control, or DrawText, TextOut and other APIs

4. how does a program know from computer to computer what port and memory is given to a device or is it generally the same?
By using the windows API OR writing your own driver

Sorry if the questions are asking too much & thank you very much if you can answer even just a small aspect of one of them.

HTH

#6
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,251 posts
  • Location:C:\Countries\US

Quote

Comment inline

Quote

Originally Posted by SteveC
Hello,
I have a series of related questions and if you think I should post them separately please say so.
So far I've made console programs & window programs where macros have handled user input and output, but just for the sake of learning (not for efficiency, obviously!) I want to learn how to address ports etc. Like in a grass-roots way without includes. Some specific questions I have are:

1. are interrupts the same in x64 and x86
Windows program do not use interrupts directly, maybe you can in RING 0?

2. do proper programs use interrupts like 21 9, also how would a program like microsoft word take your input and output it to the screen
As in #1, int is not used in Windows programming, DOS/16bit code, yes. Well, int 3 is used often MS Word uses COM and OLE, to make a simple text editor you would use SendMessage and the message WM_GETTEXT for "input" and to use WM_SETTEXT for "output", or DrawText there are many ways...

3. how do you tell the computer to colour in a particular pixel, for example given the information below for a display adaptor does anyone know the role of the different memory and i/o ranges and how you would use them in assembly?
Memory Range 00000000e0000000-00000000efffffff
Memory Range 00000000f0020000-00000000f003ffff
i/o range d000-d0ff
irq 0xfffffffe (-2)
i/o range 03b0-03bb
i/o range 03c0-03df
memory range 00000000000a0000-00000000000bffff
you cannot access irqs, ports, memory (of other programs) you need to use the Windows API, to draw text in a differant color, you would use the RichEdit control, or DrawText, TextOut and other APIs

4. how does a program know from computer to computer what port and memory is given to a device or is it generally the same?
By using the windows API OR writing your own driver

Sorry if the questions are asking too much & thank you very much if you can answer even just a small aspect of one of them.
HTH
I think maybe what he meant by question number 4 is how does the operating system learn what ports to use for what tasks.

#7
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
#4 - they're standardized, i.e. ports 80 and 8080 are always used for HTTP, 22 is always used for SSH, and so on.
sudo rm -rf /

#8
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,251 posts
  • Location:C:\Countries\US
Wait, what type of ports is he talking about? Hardware I/O ports or networking ports (network port 80 is HTTP, but I'm not sure about the assembly language port 80)?

#9
SteveC

SteveC

    Newbie

  • Members
  • Pip
  • 5 posts
Thanks very much for all your replies.

Slider I will look more closely at those forums when I get a chance

Gunner I understand now about kernel32 & gdi etc and others in the api. I didn't realise how integral they were to windows & I thought that the functions in kernel32.lib which I think calls the dll were just optional like the random high-level function includes that usually come with an installation of an assembler...shows I have a lot to learn:blushing:!

Ruvim & Gunner I did mean how does the operating system know about the hardware below the level of the api, but there might be out there a detailed description of the api libraries which would probably give a clue.

Dargueta I did mean hardware but maybe they too use standard addresses

Thank you:)

#10
SteveC

SteveC

    Newbie

  • Members
  • Pip
  • 5 posts
sorry .lib and .dll are homologous I think

Edit: No sorry the dll file is got to by the lib file.

#11
SteveC

SteveC

    Newbie

  • Members
  • Pip
  • 5 posts
Microsoft Windows library files - Wikipedia, the free encyclopedia

Hardware abstraction layer - Wikipedia, the free encyclopedia

#12
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Oops, my bad. Hardware ports do use standard addresses as well, at least on IBM-compatible computers.* Some examples:

Keyboard: ports 0x60, 0x6D
VGA BIOS: 0x3b4 - 0x3da
Serial IO controller: 0x3f8, 0x2f8, 0x3e8, 0x2e8

* IBM-Compatible: PCs and Macs; other minority systems like Amiga are not.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users