Home > Back-end >  GCC inline assembler stack calculation error
GCC inline assembler stack calculation error

Time:10-25

Today try to write under 16 c use nasm + GCC
Link to successful into the C language is also
But in a child function embedded inside the assembly calculation error stack when
The red part is the problem
The code push ebx
Push edi
But access is ebp + 8
Should be the ebp + 16
# define putw_gs (offset, num) __asm__ (" movw % 0, % % % gs: (1) ": :" b "(num)," D "(offset) :)
Int the start ()
{
Int k, g=0;
Char parr []="qwertyuiop []; LKJ ";
Char * KSP;
The printf (parr);
While (1);



}


Int printf (char * I)
{
Unsigned short int p;
Unsigned int short MB;
Unsigned int short dda=0;
Char * ope.
P=0;
Ope=I;

Dda=* ope + 256;
Putw_gs (p, dda);
Ope++;

Dda=* ope + 256;
Putw_gs (p, dda);
Ope++;

Dda=* ope + 256;
Putw_gs (p, dda);
Ope++;


}


The file "code16. CPP
"/APP
. Code16


/NO_APP
. Globl _fff
.data
_fff:
The ASCII "1234567890123 ABC \ 0
"The text
. Globl __Z5startv
.def __Z5startv; SCL 2; The 32; . Endef
__Z5startv:
Pushl % ebp
Esp movl %, % ebp
Subl $56, % esp
Movl $0-12 (% ebp)
Movl at $1919252337, 29 (% ebp)
-Movl at $1769306484, 25 (% ebp)
Movl at $1566273647, 21 (% ebp)
-Movl at $1785424955, 17 (% ebp)
-Movb $0, 13 (% ebp)
Leal - 29 (% ebp), % eax
Movl % eax and % (esp)
Call __Z6printfPc
L2:
JMP L2
. Globl __Z6printfPc
.def __Z6printfPc; SCL 2; The 32; . Endef
__Z6printfPc:
Pushl % ebp
Esp movl %, % ebp
Pushl % edi
Pushl % ebx
Subl $16, % esp
Movw $0, 10 (% ebp)
-Movw $0-12 (% ebp)
movl 8 (% ebp), % eax
Movl % eax, 16 (% ebp)
-Movl - 16 (% ebp), % eax
Movzbl (% eax), % eax
CBTW
Addw $256, % ax
Movw % ax - 10 (% ebp)
Movzwl - 10 (% ebp), % eax
Movzwl - 12 (% ebp), % edx
Movl % eax and % ebx
Movl % edx, % edi
/APP
# 33 "code16. CPP" 1
Gs: (bx, movw % % % di)
# 0 2
""/NO_APP
Addl $1-16 (% ebp)
Movl - 16 (% ebp), % eax
Movzbl (% eax), % eax
CBTW
Addw $256, % ax
Movw % ax - 10 (% ebp)
Movzwl - 10 (% ebp), % eax
Movzwl - 12 (% ebp), % edx
Movl % eax and % ebx
Movl % edx, % edi
/APP
# 37 "code16. CPP" 1
Gs: (bx, movw % % % di)
# 0 2
""/NO_APP
Addl $1-16 (% ebp)
Movl - 16 (% ebp), % eax
Movzbl (% eax), % eax
CBTW
Addw $256, % ax
Movw % ax - 10 (% ebp)
Movzwl - 10 (% ebp), % eax
Movzwl - 12 (% ebp), % edx
Movl % eax and % ebx
Movl % edx, % edi
/APP
# 41 "code16. CPP" 1
Gs: (bx, movw % % % di)
# 0 2
""/NO_APP
Addl $1-16 (% ebp)
Addl $16, % esp
Popl % ebx
Popl % edi
Popl % ebp
Ret
. Globl __Z5testrv
.def __Z5testrv; SCL 2; The 32; . Endef
__Z5testrv:
Pushl % ebp
Esp movl %, % ebp
Subl $16, % esp
Movl $81-4 (% ebp)
Movl - 4 (% ebp), % eax
Leave
Ret
The ident "GCC: (tdm64-2) 4.8.1"

CodePudding user response:

Under 16 can visit 32 to register??

CodePudding user response:

You in your compiled C plus __asm__ (" code16 \ r \ n ");

CodePudding user response:

Add me to write the wrong should be under the ebp + 6 for 16 IP is not the eip IP + 2 bytes push ebp 4 bytes should visit the ebp + 6
  • Related