yield汇编实现
yield汇编实现.
#include <stdio.h
#include <conio.h
#include <iostream.h //
// marks a location in the program for resume
// does not return control, exits function from inside macro
//
// yield( x, ret )
// x : the 'name' of the yield, cannot be ambiguous in the
// function namespace
// ret : the return value for when yield() exits the function; // must match function return type (leave blank for no return type) #define yield(x,ret) \
{ \
/* store the resume location */ \
__asm { \
mov _myStaticMkr,offset label_##x \
} \
\
/* return the supplied value */ \
return ret; \
} \
/* our offset in the function */ \
label_##x: //
// resumes function from the stored offset, or
// continues without notice if there's not one
// stored
//
// resume()
// <void #define resume() \
/* our stored offset */ \
static _myStaticMkr=; \
\
/* test for no offset */ \
if( _myStaticMkr ) \
{ \
/* resume from offset */ \
__asm \
{ \
jmp _myStaticMkr \
} \
} // example demonstrating a function with an int return type
// using the yield() and resume() macros
//
// myFunc()
// <void int myFunc()
{
resume(); cout << "1\n"; yield(,); cout << "2\n"; yield(,); cout << "3\n"; yield(,); cout << "4\n"; return ;
} // main function
//
// main()
// <void void main( void )
{
cout << "Yield in C++\n";
cout << "Chris Pergrossi\n\n"; myFunc(); do {
cout << "main()\n";
cout.flush();
} while( myFunc() ); cout.flush(); getch();
} /* // example demonstrating a function with no return type
// using the yield() and resume() macros
//
// myFunc()
// <void void myFunc()
{
resume(); cout << "1\n"; yield(1); cout << "2\n"; yield(2); cout << "3\n"; yield(3); cout << "4\n"; return;
} // main function
//
// main()
// <void void main( void )
{
cout << "Yield in C++\n";
cout << "Chris Pergrossi\n\n"; myFunc(); for( int k = 0; k < 4; k ++ )
{
cout << "main()\n";
cout.flush(); myFunc();
} cout.flush(); getch();
} */
yield汇编实现的更多相关文章
- u-boot源码汇编段简要分析
Hi,大家好!我是CrazyCatJack,你们可以叫我CCJ或者疯猫.今天我给大家带来的是u-boot的源代码汇编段分析,以后还会给大家讲解后续的C代码,请持续关注哦^_^ 先简单说一下u-boot ...
- Python 生成器与迭代器 yield 案例分析
前几天刚开始看 Python ,后因为项目突然到来,导致Python的学习搁置了几天.然后今天看回Python 发现 Yield 这个忽然想不起是干嘛用的了(所以,好记性不如烂笔头.).然后只能 花点 ...
- GCC 预处理、编译、汇编、链接..
1简介 GCC 的意思也只是 GNU C Compiler 而已.经过了这么多年的发展,GCC 已经不仅仅能支持 C 语言:它现在还支持 Ada 语言.C++ 语言.Java 语言.Objective ...
- node 异步回调解决方法之yield
先看如何使用 使用的npm包为genny,npm 安装genny,使用 node -harmony 文件(-harmony 为使用es6属性启动参数) 启动项目 var genny= require( ...
- GDB调试汇编堆栈过程分析
GDB调试汇编堆栈过程分析 分析过程 这是我的C源文件:click here 使用gcc - g example.c -o example -m32指令在64位的机器上产生32位汇编,然后使用gdb ...
- Beennan的内嵌汇编指导(译)Brennan's Guide to Inline Assembly
注:写在前面,这是一篇翻译文章,本人的英文水平很有限,但内嵌汇编是学习操作系统不可少的知识,本人也常去查看这方面的内容,本文是在做mit的jos实验中的一篇关于内嵌汇编的介绍.关于常用的内嵌汇编(AT ...
- 从linux0.11中起动部分代码看汇编调用c语言函数
上一篇分析了c语言的函数调用栈情况,知道了c语言的函数调用机制后,我们来看一下,linux0.11中起动部分的代码是如何从汇编跳入c语言函数的.在LINUX 0.11中的head.s文件中会看到如下一 ...
- C内嵌汇编-格式
C内嵌汇编-格式: __asm__(汇编语句部分:输出部分:输入部分破坏描述部分);C内嵌汇编以关键字"__asm__"或"asm"开始, 下辖四个部分, 各部 ...
- 20145212——GDB调试汇编堆栈过程分析
GDB调试汇编堆栈过程分析 测试代码 #include <stdio.h> short val = 1; int vv = 2; int g(int xxx) { return xxx + ...
随机推荐
- python流程控制语句 for循环 - 1
Python中for循环语句是通过遍历某一序列对象(元组.列表.字典等)来构建循环,循环结束的条件就是遍历对象完成. 语法形式: for <循环变量> in <遍历对象>: & ...
- linux环境下,利用tc限制两台服务器间的网速,非常简单。
最近再搞postgres的数据同步,需要模拟异地机房有带宽限制时的同步效果,所以想要限制一下两台机器之间的网速. ts命令功能很强,同时也好难理解和使用,经常浪费了好半天还是搞不定. 这里分享一个简单 ...
- !! Android developer 最新国内镜像
Android developer 最新国内镜像: http://wear.techbrood.com, 包含Android最新文档以及Android Wear,Android TV,Android ...
- adobeMediaServer
参考地址: http://www.piis.cn/news/new519.asp http://www.cuplayer.com/player/PlayerCode/RTMP/2012/0918427 ...
- NDK(7)NDK debugging without root access
from : http://ian-ni-lewis.blogspot.com/2011/05/ndk-debugging-without-root-access.html NDK debugging ...
- 【AStar】初赛第一场
1. All X1.1 基本思路k和c的范围都不大,因此可以考虑迭代找循环节,然后求余数,判定是否相等.这题还是挺简单的.1.2 代码 /* 5690 */ #include <iostream ...
- DBContext
http://www.entityframeworktutorial.net/EntityFramework4.3/dbcontext-vs-objectcontext.aspx As you hav ...
- Oracle PO - 模块一揽子采购协议小结
本文总结oracle ebs采购订单(po)模块一揽子采购协议的相关知识,总结如下: 1.理论介绍 (1)名词术语 一揽子采购协议(Blanket Purchase Agreement,BPA)是指某 ...
- 函数buf_pool_init
/********************************************************************//** Creates the buffer pool. @ ...
- 函数fsp_fill_free_list
/**********************************************************************//** Puts new extents to the ...