对于我学校的任务,我需要编写一个C程序,它使用汇编程序进行16位加法.除了结果,EFLAGS也将被退回.
这是我的C程序:
int add(int a, int b, unsigned short* flags);//function must be used this way
int main(void){
unsigned short* flags = NULL;
printf("%d\n",add(30000, 36000, flags);// printing just the result
return 0;
}
Run Code Online (Sandbox Code Playgroud)
目前程序只打印出结果而不是标志,因为我无法得到它们.
这是我使用NASM的汇编程序:
global add
section .text
add:
push ebp
mov ebp,esp
mov ax,[ebp+8]
mov bx,[ebp+12]
add ax,bx
mov esp,ebp
pop ebp
ret
Run Code Online (Sandbox Code Playgroud)
现在一切顺利.但我不知道如何获得必须[ebp+16]指向标志寄存器的指针.教授说我们将不得不使用这个pushfd命令.
我的问题只在于汇编代码.在得到标志的解决方案后,我将修改C程序以发出标志.