Understanding some assembly code? -
i need deciphering means, put comments of think i'm not entirely sure.
movl 12(%ebp), %eax //variable (x) moves eax register addl $4, %eax // add value 4 x movl (%eax), %eax //eax = *x; movl %eax, (%esp) //stack pointer = *x call strlen //calls gets length of string movl %eax, %edx //copy *x edx register, name *y movl %edx, %eax //copy *y eax sall $2, %eax //shift *x left 2 (eax) addl %edx, %eax //*x + *y = *x (x shifted 2, remember) movl %eax, (%esp) // move new *x string onto stack pointer call malloc // memory allocate string movl %eax, 28(%esp) //move string onto new variable, lets z movl $.lc1, %edx //move string in lc1 edx movl 12(%ebp), %eax //repeat @ top addl $4, %eax movl (%eax), %eax movl 28(%esp), %ecx // move z ecx register movl %ecx, 8(%esp) // move z closer stack pointer movl %edx, 4(%esp) // move y closest stack pointer movl %eax, (%esp) // set stack pointer x. stack goes: x, y, z call __isoc99_sscanf //return number of input items matched cmpl $1, %eax //if x == 1, je .l20 //jump l20 movl $.lc2, (%esp) //else, lc2 becomes stack pointer call puts //calls procedure, lc2 movl $1, %eax // makes x = 1 jmp .l19 // jump end
it's not quite correct. here's attempt:
movl 12(%ebp), %eax //[esp] = [[ebp+12]+4] addl $4, %eax movl (%eax), %eax movl %eax, (%esp) call strlen //eax = length of string movl %eax, %edx //edx = length of string movl %edx, %eax //useless instruction sall $2, %eax //eax = length x 4 addl %edx, %eax //eax = length x 5 movl %eax, (%esp) //allocate length x 5 bytes call malloc movl %eax, 28(%esp) //[ebp+28] = ptr allocated memory movl $.lc1, %edx //edx = offset .lc1 movl 12(%ebp), %eax //eax = [[ebp+12]+4] addl $4, %eax movl (%eax), %eax movl 28(%esp), %ecx //[esp+8] = ptr allocated memory movl %ecx, 8(%esp) movl %edx, 4(%esp) //[esp+4] = offset .lc1 movl %eax, (%esp) //[esp] = [[ebp+12]+4] call __isoc99_sscanf //return number of input items matched cmpl $1, %eax //if result == 1 je .l20 //jump l20 movl $.lc2, (%esp) //[esp] = offset .lc2 call puts //display .lc2 string movl $1, %eax //eax = 1 jmp .l19 //jump ???
Comments
Post a Comment