aboutsummaryrefslogtreecommitdiff
path: root/entries/nwoeanhinnogaehr/fib.asm
blob: 729958fc95bcdfdd6426df61aaa70f232eb06b6f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
; assembles with nasm to an 81-byte ELF binary that works on x86 Linux

bits 32
org $25430000
    db $7F,"ELF" ; e_ident
    dd 1 ; p_type
    dd 0 ; p_offset
    dd $$ ; p_vaddr
    dw 2 ; e_type, p_paddr
    dw 3 ; e_machine
    dd entry ; e_version, p_filesz
    dw (entry-$$)&0xffff ; e_entry, p_memsz

entry:
    inc ebx
    and eax,strict dword 4 ;nop
    inc esi ; 1
    inc edi ; 1
            ; 2
            ; 3
            ; 5
            ; 8
            ; ...

loop:
    mov eax,esi
    push 10
    mov ecx,esp
    jmp skip
    dw $20 ; e_phentsize
    dw 1 ; e_phnum
skip:
    pop ebp

format:
    cdq
    div ebp
    inc ebx
    dec ecx
    or edx,'0'
    mov [ecx],dl
    test eax,eax
    jnz format

print:
    mov al,4
    mov edx,ebx
    mov bl,1
    int 0x80

    ;update fibbo
    mov eax,edi
    add edi,esi
    xchg esi,eax

    ;exit on overflow
    jno loop
    xchg eax,ebx
    int 0x80