gpt4 book ai didi

c - 如何使用内联汇编从堆栈中获取信息以在 C 中编程?

转载 作者:太空宇宙 更新时间:2023-11-04 04:50:34 25 4
gpt4 key购买 nike

我有任务要做,我正在寻求帮助。 (在简单的 c 语言上)

我需要做什么?我需要检查主 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 中保存特定过程( sleep )的指针地址。然后从堆栈中获取信息(每个下一个命令的地址)到 volatile next_command,然后最终返回到 c 并每次进行比较。如果两个变量上的值(地址)相同,则打印特定消息。希望我清楚..

10 倍,

尼尔B

最佳答案

Answered as a comment by the OP

我得到了我想要的答案:

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);

关于c - 如何使用内联汇编从堆栈中获取信息以在 C 中编程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15843044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com