Skip to content

Instantly share code, notes, and snippets.

@leighklotz
Created April 10, 2023 01:30
Show Gist options
  • Select an option

  • Save leighklotz/57163db510b12edacf88d4bdbb095576 to your computer and use it in GitHub Desktop.

Select an option

Save leighklotz/57163db510b12edacf88d4bdbb095576 to your computer and use it in GitHub Desktop.
Codex Prompt was main function (interactively written) and first two comment lines; it generated the assembly
#include "main.h"
int main(int argc, char *argv[])
{
printf("Hello World: %d", argc);
for (int i = 0; i < argc; i++)
{
printf("%s", argv[i]);
}
return 0;
}
// cc -c main.c -S -o main.s
// cat main.s
.file "main.c"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl %edi, -4(%rbp)
leaq 8(%rbp), %rax
movq %rax, -16(%rbp)
movl $.LC0, %edi
call puts
movl -4(%rbp), %eax
movl %eax, -8(%rbp)
jmp .L2
.L3:
movl -8(%rbp), %eax
movl %eax, %esi
movl -16(%rbp), %edi
movl %esi, (%rdi,%rax,4)
addl $1, -8(%rbp)
.L2:
movl -8(%rbp), %eax
cmpl -4(%rbp), %eax
jle .L3
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.section .rodata
.LC0:
.string "Hello World: %d"
.text
.ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609"
.section .note.GNU-stack,"",@progbits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment