How does the .ascii
directive in x86 assembly work? When does it place the ASCII in memory? I would assume the text is part of the machine code that gets placed in main memory, but what exactly is being done in the yourText portion of the machine code here?
In 40100e, the start of the yourText code portion is placed into the buffer argument for the write syscall. In C I would interpret this as passing the pointer to the first character of a string literal, but I don't exactly get why it would go to more code rather than the spot where the literal is found in the memory.
hwa.out: file format elf64-x86-64
Disassembly of section .text:
0000000000401000 <_start>:
401000: 48 c7 c0 01 00 00 00 mov $0x1,%rax
401007: 48 c7 c7 01 00 00 00 mov $0x1,%rdi
40100e: 48 c7 c6 2a 10 40 00 mov $0x40102a,%rsi
401015: 48 c7 c2 0d 00 00 00 mov $0xd,%rdx
40101c: 0f 05 syscall
40101e: 48 c7 c0 3c 00 00 00 mov $0x3c,%rax
401025: 48 31 ff xor %rdi,%rdi
401028: 0f 05 syscall
000000000040102a <yourText>:
40102a: 48 rex.W
40102b: 65 6c gs insb (%dx),%es:(%rdi)
40102d: 6c insb (%dx),%es:(%rdi)
40102e: 6f outsl %ds:(%rsi),(%dx)
40102f: 2c 20 sub $0x20,%al
401031: 57 push %rdi
401032: 6f outsl %ds:(%rsi),(%dx)
401033: 72 6c jb 4010a1 <yourText+0x77>
401035: 64 fs
401036: 0a .byte 0xa
This is the code found in this question: Hello world without using libraries, assembled then disassembled.
I've tried looking for information as to what the instructions do, but I can't find info on rex.W
, and the gs
at the start of insb
. I can see why the program would want to put data into a port (insb
), but it doesn't make sense to me to do the branching (jb
) below an outsl
line. I assume jb
uses signals from the previous instruction.