From my previous question double pointer vs pointer to array, incompatible pointer type, I use a fixed pointer (pointer to array) instead of modifiable pointer (double pointer), So I thinking if there is a way to cast and so change to compatible pointer type from one to another. (I won't post the source, since it could be seemed as duplicating, but my concern is in asm solution of that, so see the link first please).
As I saw a compiled assembly with -S
flag, the string org
is passed on stack (starting at address -64(%rbp)
) and then passing that address to function strsep
by leaq -64(%rbp), %rax
. So everything looks good. here's asm snippet:
main:
pushq %rbp #
movq %rsp, %rbp #,
subq $64, %rsp #,
# a.c:6: char *token, org[] = "Cats,Dogs,Mice,,,Dwarves,Elves:High,Elves:Wood";
movabsq $7453250866027716931, %rax #, tmp93
movabsq $3183030514286931059, %rdx #,
movq %rax, -64(%rbp) # tmp93, org
movq %rdx, -56(%rbp) #, org
movabsq $8315182520643044396, %rax #, tmp94
movabsq $5204599198995727660, %rdx #,
movq %rax, -48(%rbp) # tmp94, org
movq %rdx, -40(%rbp) #, org
movabsq $7311150089436161897, %rax #, tmp95
movq %rax, -32(%rbp) # tmp95, org
movl $1867987571, -24(%rbp) #, org
movw $25711, -20(%rbp) #, org
movb $0, -18(%rbp) #, org
# a.c:7: while((token=strsep((char**)&org,",")))
jmp .L2 #
.L3:
# a.c:8: printf("Token: %s\n",token);
movq -8(%rbp), %rax # token, tmp89
movq %rax, %rsi # tmp89,
leaq .LC0(%rip), %rdi #,
movl $0, %eax #,
call printf@PLT #
.L2:
# a.c:7: while((token=strsep((char**)&org,",")))
leaq -64(%rbp), %rax #, tmp90
leaq .LC1(%rip), %rsi #,
movq %rax, %rdi # tmp90,
call strsep@PLT #
movq %rax, -8(%rbp) # tmp91, token
# a.c:7: while((token=strsep((char**)&org,",")))
...
But in the end, it gets sigint. I know the strsep
wants a type (char**), a address of pointer but I am giving it address of -64(%rbp)
which should contain the same. So why the sigint? 2. How to properly cast incompatible pointer types to their compatible equivalents?
EDIT: This is not the same question. In the link, I asked about the intepretation in c. Now I ask about the solution in asm. It may look misleading, but I like to dissasembly c I do not understand. For those how thinks I am asking the same problem, I am not. Please for asnweres, look at the link first, I want assemblt solution here