1

I'm using the GoAsm assembler on a Windows 7 - 64 bit OS and I'll be asking you a few (not so dumb) questions.

First question :

How can I find the physical address of a file ? Let's suppose file "Text.txt" is at the root of my C:\ partition. Is there a way to get the exact memory address where this file is ?

Second question :

Is it possible to call a routine which will just do like if I invoked a C function ?

(i.e. : Consider a C function "WriteToScreen", is it possible to have the same function, but in assembler format, that means without having the need to use high-level invokes to do that work ?

Third question :

Are there somewhere on the net some include files for GoAsm containing useful routines like (move, copy, edit, erase) commands ? I've first thought of ms-dos interrupts but I can't manage to get them to work without crashing the program. I guess it just not compatible with Windows OS even though the command prompt acts like ms-dos... ?

Fourth question :

I've heard from different sources and myself that NASM works pretty bad on Win7 x64, is it just true, or am I doing it the wrong way ?

Mat
  • 202,337
  • 40
  • 393
  • 406
Chuck Norris
  • 11
  • 1
  • 2
  • 9
    Files don't have memory addresses. They are located at locations on the disk which have "locations" e.g., disk block numbers. The fact that this is unclear to you suggests you'd be better off spending time learning about computer architectures and operating systems before you spend much more energy on assembly code. – Ira Baxter Jun 19 '11 at 17:03
  • First, thanks for the answer. But I don't agree to what yer' saying, though I may be wrong. If I write a byte on a random part of an HDD, this byte is obviously put in one of the sectors, and should have its address to locate where the byte is. I mean, I don't write "Data is here ->" with a pencil on the surface of the disk if I want to tell that Foo is at Bar position. Why wouldn't it work like ROM and RAM when it's all numeral ? We all know the CPU doesn't recognize anything else than binary, the binary notation being used to specify a binary address. – Chuck Norris Jun 19 '11 at 18:17
  • 1
    @Chunk Norris: Don't confuse what happens inside the computer for where the file data eventually ends up. Your postal box has an address, and it collects letters. But there is vast amount of mechanical shuffling of the letters inside the Post Office you never see, and each place where that shuffling occurs in the PO has an "address" too (if nothing else, its GPS coordinates). But the two kinds of addresses are completely unrelated. I'm back to my comment: you need to go read about computer and OS architectures more before you spend any more time following your original train of thought. – Ira Baxter Jun 19 '11 at 18:22
  • This just proves the point, that you should go learn about basic computer architecture before trying assembly. Just because something is addressable (and most things are!) doesn't mean addresses are numerical or randomly accessible. To read disk you need to send a command to the hard drive to copy data to memory, these instructions are privileged so you have to ask the OS. Memory is the same way: you have to issue a command to copy data to a register (I'm simplifying), but these instructions are not privileged. Web pages are addressable too, but they don't have memory locations. – Dietrich Epp Jun 19 '11 at 18:26

2 Answers2

0

1 An hard drive, from a logical point of view, can be seen as a sequence of "blocks" (the more common name is sectors). How these blocks are organized physically on the disks can be disregarded, but the driver must know someway how to get data of course, though you send to modern hd driver "high level" commands that, as far as you know, are not strongly related to where data physically are (you can say "read the block 123", but there's no extern evidence of where that block lives).

However this way you can "name" a block with a number, and say e.g. that block 0 is the MBR. Each block contains several bytes (512, 1024...). Not all used blocks contain actual data of a file, in fact there are metainformations of any sort, depending on the filesystem but even related to the "structure" of the hd (I mean, partitions).

A file located on an hd is not automatically loaded into memory, so it has no memory address. Once you read it, piece of it if not all are of course copied into the memory you give, which is not an intrinsic property of the file. (Filesystems retrieve the blocks belonging to the file and "show" them as we are used to see them, as a single "unit", the file)

Summarizing: files have no memory address. The physical address could be the set of blocks holding data (and metadata, like inodes ) of the file, or just the first block (but if a block of data is N, N+1 could not belong to the same file - the blocks need no to be one next to the other). To know them, you have to analyse the structure of the filesystem you use. I don't know if there's an API to retrieve them easily, but in the worst case you can analyse the source code of the filesystem... good luck!

2 C functions are translated into assembly. If you respect the C calling convention, you can write a "C function" directly in assembly. Try reading this and this for x86.

3 You can call windows API from asm. Forget MS-DOS, MS-DOS is dead, MS-DOS is not Windows, the cmd is a sort of "emulation"... indeed no, not an emulation but just a command line interface that resemble the one MS-DOS users was used to. But it is not exaclty the same, i.e. there are no MS-DOS system interrupt you can use. Iczelion's assembly tutorials, though old, could be an interesting resource. (If links expire, try with the wayback machine)

4 I do not own Win7 and never installed nasm on windows, so I can't say anything about.

ShinTakezou
  • 9,432
  • 1
  • 29
  • 39
  • The link to online.fr isn't working for me (DNS not resolved.) Another assembler tutorial site is: http://win32assembly.programminghorizon.com/tutorials.html . Furthermore for #2, if the assembler object file is included in the C project, it should be able to find the assembler routine just as if it were any other C routine. Of course this is all done slightly differently depending on OS / compiler / assembler / IDEs used. [Here is a GCC example](http://stackoverflow.com/questions/13901261/calling-assembly-function-from-c). – rdtsc May 27 '15 at 03:48
  • the link seems gone. I am going to change it; your link is not "another assembler tutorial", but it was exactly iczelion's one on [online.fr](http://web.archive.org/web/20110721015009/http://win32assembly.online.fr/tutorials.html). For #2, the focus was on using C calling convention in asm code, not the scope/visibility of the assembler routine. – ShinTakezou May 27 '15 at 05:46
-2

For the first question just drag the file into the address bar in the browser