0

In some example code written in Intel syntax there was a line that said [org 0x7c00]. I couldn’t seem to figure out how to get this to work with AT&T syntax and couldn’t find it online.

Also, I found a line that had $$(this might not be considered an assembler directive). From what I could tell, this references the beginning of the binary(?) I can’t seem to find the AT&T equivalent of this either.

To ask a broader question. What is a good way to find AT&T equivalents to (obscure?) Intel statements?

phuclv
  • 37,963
  • 15
  • 156
  • 475
AAJ
  • 55
  • 7
  • 1
    [Is there a complete x86 assembly language reference that uses AT&T syntax?](https://stackoverflow.com/q/1776570/995714) – phuclv Sep 23 '18 at 02:22
  • Different assemblers handle `org` differently. For NASM, `org` doesn't actually let you "seek" in the output file, and definitely not go back and overwrite something that was assembled earlier. So you have to figure out exactly what it does to the resulting binary ([What's the real meaning of $$ in nasm](https://stackoverflow.com/q/14928741)), and then do something equivalent in AT&T. (or find out what is needed in AT&T for a boot sector, for example.) , [Calculating padding length with GAS AT&T directives for a boot sector?](https://stackoverflow.com/q/47859273) – Peter Cordes Sep 23 '18 at 02:28
  • But in GAS, `.org` can seek forwards (like MASM `org`), as Ross's answer on that linked question shows. Don't assume that all Intel-syntax assemblers use exactly the same directives. – Peter Cordes Sep 23 '18 at 02:29
  • Oh of course it was .org. I don’t know why I didn’t try that. – AAJ Sep 23 '18 at 02:30
  • 1
    If you are assembling with `as` directly and then using a linker `ld` to link your object to an executable then the `org 0x7c00` is done via the `ld` command line option `-Ttext=0x7c00`. Alternatively you can use a linker script but that is more complex – Michael Petch Sep 23 '18 at 02:39
  • @MichaelPetch In this particular case I am not linking – AAJ Sep 23 '18 at 02:40
  • 1
    what commands are you using to make your bootloader? If you aren't linking then it is possible you have a step missing that result in creating an improperly formed boot sector. – Michael Petch Sep 23 '18 at 02:41
  • 1
    It is possible to use `gcc` to do the linking, compiling and outputting the binary all in one command.Is that what you are doing? – Michael Petch Sep 23 '18 at 02:43
  • @MichaelPetch I’ve just started with this kind of thing. I’m using gas to make an elf and then using objcopy to get a .bin file. – AAJ Sep 23 '18 at 02:48
  • 1
    When you say GAS, do you mean you are using the `as` command? – Michael Petch Sep 23 '18 at 02:49
  • That is correct – AAJ Sep 23 '18 at 02:50
  • 3
    You are then missing a step. `as` outputs an object file. Without the linking step objcopy is going to take your elf object and output it without setting an origin point and that is going to cause you a bunch of grief. Usually you can do something like `as --32 boot.s -o boot.o` `ld -melf_i386 -Ttext=0x7c00 boot.o -o boot.elf` then you can use objcopy with `objcopy -O binary boot.elf boot.bin` `boot.bin` would be the file you can use as a bootloader – Michael Petch Sep 23 '18 at 02:57
  • 1
    While gas supports `.org` it doesn't do what you expect and is usually not useful. Instead, proceed as Michael Petch said. – fuz Sep 23 '18 at 06:22

1 Answers1

1

org in at&t syntax is . =, so:

. = 0x7c00
.globl _a
_a: ret

After compiling, nm produces:

0000000000007c00 T _a

But because ld is different from the dos tools, you mightn’t get the effect you want; that is a further relocation might be applied to _a, so it would end up with something like:

0000000100000000 T __mh_execute_header
0000000100007fac T _a
0000000100000390 T _main
mevets
  • 10,070
  • 1
  • 21
  • 33