Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <stdio.h> void hanoi(int n, char *from, char *to, char *temp); //Call t

ID: 3631269 • Letter: #

Question

#include <stdio.h>

void hanoi(int n, char *from, char *to, char *temp);

//Call this procedure from assembly. It's here
//because calling _printf from assembly is a bit
//complicated on the Mac.
void my_print(char *s, char *first, char *second)
{
printf(s,first,second);
}

/*
void hanoi(int n, char *from, char *to, char *temp)
{
if (n == 0)
return;
else {
hanoi(n-1,from,temp,to);
my_print("Moving a disk from %s to %s ", from, to);
hanoi(n-1,temp, to, from);
}
}
*/

main()
{
hanoi(5, "peg A", "peg B", "peg C");
}

Turn this equivalent C code to x86 At&t syntax compatible with carbon emacs in Mac OS x

Explanation / Answer

file "han.c" .section .rodata .LC0: .string "Moving a disk from %s to %s " .text .globl hanoi .type hanoi, @function hanoi: pushl %ebp movl %esp, %ebp subl $24, %esp cmpl $0, 8(%ebp) je .L5 .L2: movl 8(%ebp), %eax leal -1(%eax), %edx movl 16(%ebp), %eax movl %eax, 12(%esp) movl 20(%ebp), %eax movl %eax, 8(%esp) movl 12(%ebp), %eax movl %eax, 4(%esp) movl %edx, (%esp) call hanoi mov ebp, esp and esp, -16 sub esp, 48 mov DWORD PTR [esp+32], 3 mov DWORD PTR [esp+36], 4 mov DWORD PTR [esp+40], 5 mov DWORD PTR [esp+44], 6 mov DWORD PTR [esp+16], 1 mov DWORD PTR [esp+20], 2 mov DWORD PTR [esp+24], 3 mov DWORD PTR [esp+28], 4 mov DWORD PTR [esp+8], 4 lea eax, [esp+16] mov DWORD PTR [esp+4], eax lea eax, [esp+32] mov DWORD PTR [esp], eax call inner_prod mov edx, OFFSET FLAT:.LC0 mov eax, DWORD PTR [ebp-4] cmp eax, DWORD PTR [ebp+16] jl .L5 mov eax, DWORD PTR [ebp-8] leave ret .size inner_prod, .-inner_prod .ident "GCC: (Ubuntu 4.4.3-4ubuntu5) 4.4.3" .section .note.GNU-stack,"",@progbits