“first assembly code in which a language is used to represent machine code instructions is found in Kathleen and Andrew Donald Booth‘s 1947 work, Coding for A.R.C..[8] Assembly code is converted into executable machine code by a utility program referred to as an assembler” (src)

fingers crossed, that wordpress won’t fuck up this C example: (it really fucks up a lot of special chars, no matter in what mode they are pasted)

vim enum_2.c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef enum {false, true} bool; // C++ can not do that

int main(void)
{
	int zahl;
	printf("enter a number from 0 to 9:");
	if( (scanf("%d", &zahl)) == false)
		printf("that is no number");
	else
		printf("thanks\n");

	if((zahl == 7) == true)
		printf("you entered the magic number 7\n");

	return EXIT_SUCCESS;
}
how to get this C into assembly?
that is rather easy:
gcc -S -o enum_2.asm enum_2.c

now open the file and check it out:

vim enum_2.asm
	.file	"enum_2.c"
	.text
	.section	.rodata
.LC0:
	.string	"enter a number from 0 to 9:"
.LC1:
	.string	"%d"
.LC2:
	.string	"that is no number"
.LC3:
	.string	"thanks"
	.align 8
.LC4:
	.string	"you entered the magic number 7"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	leaq	-4(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	testl	%eax, %eax
	jne	.L2
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L3
.L2:
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
.L3:
	movl	-4(%rbp), %eax
	cmpl	$7, %eax
	jne	.L4
	leaq	.LC4(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
.L4:
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	main, .-main
	.ident	"GCC: (Debian 14.2.0-16) 14.2.0"
	.section	.note.GNU-stack,"",@progbits
fascinating isn’t it?
Q: is assembly used by gcc compiler as itermediary step or not?

A: Yes, assembly is used as an intermediary step by the GCC compiler, but it is not always explicitly generated as a file unless requested.

how to compile this assembly to a binary?

as -v
GNU assembler version 2.44 (x86_64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.44

as --version
GNU assembler (GNU Binutils for Debian) 2.44
Copyright (C) 2025 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `x86_64-linux-gnu'

# this works
gcc -o enum_2.asm.bin enum_2.asm.o -no-pie

# -no-pie = Don't produce a dynamically linked position independent executable.

# this kind of fails
as -o enum_2.asm.o enum_2.asm
ld -o enum_2.asm.bin enum_2.asm.o -lc --dynamic-linker /lib64/ld-linux-x86-64.so.2
ld: warning: cannot find entry symbol _start; defaulting to 0000000000401040

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin