[英]How to get the size of a C function from inside a C program or with inline assembly?
[英]How do I get info from the stack, using inline assembly, to program in c?
我有一個任務要做,我正在尋求幫助。 (在簡單的lang上)
我需要做什么? 我需要檢查主c程序上的每個命令(使用中斷號1),並且僅在下一個命令與其他過程中先前發送到堆棧的過程相同時才打印一條消息。
我想做的事? 我想使用內聯匯編從堆棧中獲取信息,並將其放在可以返回到c之后可以在c程序自身上進行比較的變量上。 (易失)
這是程序:
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <stdlib.h>
typedef void (*FUN_PTR)(void);
void interrupt (*Int1Save) (void); //pointer to interrupt num 1//
volatile FUN_PTR our_func;
char *str2;
void interrupt my_inter (void) //New interrupt//
{volatile FUN_PTR next_command;
asm { PUSH BP
MOV BP,SP
PUSH AX
PUSH BX
PUSH ES
MOV ES,[BP+4]
MOV BX,[BP+2]
MOV AX,ES:[BX]
MOV word ptr next_command,AX
POP ES
POP BX
POP AX
pop BP}
if (our_func==next_command) printf("procedure %s has been called\n",str2);}
void animate(int *iptr,char str[],void (*funptr)(), char fstr[])
{
str2=fstr;
our_func=funptr;
Int1Save = getvect(1); // save old interrupt//
setvect(1,my_inter);
asm { pushf //TF is ON//
pop ax
or ax,100000000B
push ax
popf}}
void unanimate()
{asm { pushf //TF is OFF//
pop ax
and ax,1111111011111111B
push ax
popf}
setvect (1,Int1Save); //restore old interrupt//}
void main(void)
{int i;
int f1 = 1;
int f2 = 1;
int fibo = 1;
animate(&fibo, "fibo", sleep, "sleep");
for(i=0; i < 8; i++)
{
sleep(2);
f1 = f2;
f2 = fibo;
fibo = f1 + f2;} // for//
unanimate();} // main//
我的問題...當然,問題出在嵌入式程序集上的“我的內部”。 但無法弄清楚。 我究竟做錯了什么? (請看一下上面的代碼)我想將特定過程(睡眠)的指針地址保存在volatile our_func中。 然后從堆棧中獲取信息(每個下一個命令的地址)到volatile next_command中,然后最終返回到c並進行每次比較。 如果兩個變量的值(地址)相同,則打印一條特定的消息。 希望我清楚..
10倍
尼爾B
我得到了想要的答案:
asm { MOV SI,[BP+18] //Taking the address of each command//
MOV DI,[BP+20]
MOV word ptr next_command+2,DI
MOV word ptr next_command,SI}
if ((*our_func)==(*next_command)) //Making the next_command compare//
printf("procedure %s has been called\n",str2);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.