Portál AbcLinuxu, 1. května 2025 20:32
#include <stdint.h> inline int sys_write(int fd, char const* text, uint32_t length) { uint64_t retval; asm volatile ( /* SYSCALL instruction invokes the kernel */ "syscall" /* return value will be read from rax */ : "=rax"(retval) /* where the input arguments should be placed */ : "a"(1), /* eax = syscall number */ "D"(fd), /* argument 1 (fd) goes to rdi/edi */ "S"(text), /* argument 2 (text) goes to rsi/esi */ "d"(length) /* argument 3 (length) goes to rdx/edx */ /* registers that may contain garbage after the call - for syscalls, they are rcx, r11 */ : "rcx", "r11" ); return retval; } inline void sys_exit() { asm volatile ( "syscall" : : "a"(60), "D"(0) : "rcx", "r11" ); } void _start() { sys_write(1, "Hello world!\n", 13); sys_exit(); }
all: gcc tinyhello.c -o tinyhello --static -nostdlib -Ttinyhello.lnk -Ofast -nostartfiles -nodefaultlibs -s -fsyntax-only size: du -b tinyhello | awk '{print $$1}'
Bez žiadnej zmeny – takže kopia od pôvodného autora.
OUTPUT_FORMAT(elf64-x86-64) ENTRY(_start) SECTIONS { . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS; .text : { *(.text); *(.rodata*); } /DISCARD/ : { *(*); } }
Preklad | Výsledok |
---|---|
Bluebear kód a preklad | 864 B |
S mojimi úpravami/prekladom | 496 B |
Ušetrené: | 368 B (42,59 %) |
Tiskni
Sdílej:
nóóóó a kolik ztoho je jakoby samotnej ten helloworld string?? :O :D
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.