Skip to main content
Added a little clarity
Source Link
Shade
  • 121
  • 4

Heres some assembly

[BITS 64]

global main

main:
    xor rax, rax    ; Set to zero
    xor rcx, rcx    ; Set to zero
    inc rax         ; increment to 1
    cmp rax, rcx
    je done         ; If they are equal, go to done

; Some function
unused_function:
    inc rcx
    cmp rax, rcx
    je main
ret             ; return from function being called

done:
ret             ; return from program

This can be compiled and run like so:

nasm -f elf64 -o file.o file.asm
gcc file.o -o file
./file

It ends up running an infinite loop. After the first cmp rax, rcx, they are not equal, and thus the program doesn't jump to donedone. Execution runs through to the function, which is declared below.

Heres some assembly

[BITS 64]

global main

main:
    xor rax, rax    ; Set to zero
    xor rcx, rcx    ; Set to zero
    inc rax         ; increment to 1
    cmp rax, rcx
    je done         ; If they are equal, go to done

; Some function
unused_function:
    inc rcx
    cmp rax, rcx
    je main
ret             ; return from function being called

done:
ret             ; return from program

This can be compiled and run like so:

nasm -f elf64 -o file.o file.asm
gcc file.o -o file
./file

It ends up running an infinite loop. After the first cmp rax, rcx, they are not equal, and thus the program doesn't jump to done. Execution runs through to the function, which is declared below.

Heres some assembly

[BITS 64]

global main

main:
    xor rax, rax    ; Set to zero
    xor rcx, rcx    ; Set to zero
    inc rax         ; increment to 1
    cmp rax, rcx
    je done         ; If they are equal, go to done

; Some function
unused_function:
    inc rcx
    cmp rax, rcx
    je main
ret             ; return from function being called

done:
ret             ; return from program

This can be compiled and run like so:

nasm -f elf64 -o file.o file.asm
gcc file.o -o file
./file

It ends up running an infinite loop. After the first cmp rax, rcx, they are not equal, and thus the program doesn't jump to done. Execution runs through to the function, which is declared below.

Source Link
Shade
  • 121
  • 4

Heres some assembly

[BITS 64]

global main

main:
    xor rax, rax    ; Set to zero
    xor rcx, rcx    ; Set to zero
    inc rax         ; increment to 1
    cmp rax, rcx
    je done         ; If they are equal, go to done

; Some function
unused_function:
    inc rcx
    cmp rax, rcx
    je main
ret             ; return from function being called

done:
ret             ; return from program

This can be compiled and run like so:

nasm -f elf64 -o file.o file.asm
gcc file.o -o file
./file

It ends up running an infinite loop. After the first cmp rax, rcx, they are not equal, and thus the program doesn't jump to done. Execution runs through to the function, which is declared below.