Skip to content

Instantly share code, notes, and snippets.

@nektro
Last active October 28, 2022 17:59
Show Gist options
  • Save nektro/0c0fe18a3d6c1c645a870d45ec3eedb4 to your computer and use it in GitHub Desktop.
Save nektro/0c0fe18a3d6c1c645a870d45ec3eedb4 to your computer and use it in GitHub Desktop.
32bit x86 Linux hello world exploration
.text
.intel_syntax noprefix
.file "test"
.globl _start
.type _start,@function
_start:
push ebp
push ebx
push edi
push esi
push eax
xor edi, edi
push 4
pop esi
xor ebx, ebx
xor eax, eax
inc ebx
.LBB0_1:
cmp eax, 11
ja .LBB0_6
lea ecx, [eax + __unnamed_1]
push 12
pop edx
sub edx, eax
mov dword ptr [esp], eax
.LBB0_3:
mov eax, esi
#APP
int 128
#NO_APP
mov ebp, eax
neg eax
cmp ebp, -4095
cmovb eax, edi
cmp ax, 4
je .LBB0_3
movzx eax, ax
test eax, eax
mov eax, dword ptr [esp]
jne .LBB0_6
add eax, ebp
jmp .LBB0_1
.LBB0_6:
add esp, 4
pop esi
pop edi
pop ebx
pop ebp
ret
.Lfunc_end0:
.size _start, .Lfunc_end0-_start
.type __unnamed_1,@object
.section .rodata.str1.1,"aMS",@progbits,1
__unnamed_1:
.asciz "Hello world!"
.size __unnamed_1, 13
.section ".note.GNU-stack","",@progbits
zig build-exe hello.zig -O ReleaseSmall -target i386-linux-musl -fstrip -fstage1 -femit-asm
45 7f 46 4c 01 01 00 01 00 00 00 00 00 00 00 00
00 02 00 03 00 01 00 00 10 c4 00 40 00 34 00 00
01 48 00 00 00 00 00 00 00 34 00 20 00 04 00 28
00 05 00 04 00 06 00 00 00 34 00 00 00 34 00 40
00 34 00 40 00 80 00 00 00 80 00 00 00 04 00 00
00 04 00 00 00 01 00 00 00 00 00 00 00 00 00 40
00 00 00 40 00 c1 00 00 00 c1 00 00 00 04 00 00
10 00 00 00 00 01 00 00 00 c4 00 00 10 c4 00 40
10 c4 00 40 00 4f 00 00 00 4f 00 00 00 05 00 00
10 00 00 00 e5 51 64 74 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 01 00 00 06 00 00
00 00 00 00 65 48 6c 6c 20 6f 6f 77 6c 72 21 64
00 00 00 00 53 55 56 57 31 50 6a ff 5e 04 db 31
c0 31 83 43 0b f8 33 77 88 8d 00 b4 00 40 0c 6a
29 5a 89 c2 24 04 f0 89 80 cd c5 89 d8 f7 fd 81
f0 01 ff ff 42 0f 66 c7 f8 83 74 04 0f e9 c0 b7
c0 85 04 8b 75 24 01 04 eb e8 83 c8 04 c4 5f 5e
5d 5b 4c c3 6e 69 65 6b 3a 72 4c 20 44 4c 31 20
2e 35 2e 30 00 34 2e 00 6f 72 61 64 61 74 2e 00
65 74 74 78 2e 00 6f 63 6d 6d 6e 65 00 74 73 2e
73 68 72 74 61 74 00 62 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 01 00 00 00 01 00 00 00 32 00 00 00 b4 00 40
00 b4 00 00 00 0d 00 00 00 00 00 00 00 00 00 00
00 01 00 00 00 01 00 00 00 09 00 00 00 01 00 00
00 06 00 00 10 c4 00 40 00 c4 00 00 00 4f 00 00
00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00
00 0f 00 00 00 01 00 00 00 30 00 00 00 00 00 00
01 13 00 00 00 13 00 00 00 00 00 00 00 00 00 00
00 01 00 00 00 01 00 00 00 18 00 00 00 03 00 00
00 00 00 00 00 00 00 00 01 26 00 00 00 22 00 00
00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00
const std = @import("std");
pub export fn _start() void {
std.io.getStdOut().writeAll("Hello world!") catch unreachable;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment