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汇编实现的更多相关文章

  1. u-boot源码汇编段简要分析

    Hi,大家好!我是CrazyCatJack,你们可以叫我CCJ或者疯猫.今天我给大家带来的是u-boot的源代码汇编段分析,以后还会给大家讲解后续的C代码,请持续关注哦^_^ 先简单说一下u-boot ...

  2. Python 生成器与迭代器 yield 案例分析

    前几天刚开始看 Python ,后因为项目突然到来,导致Python的学习搁置了几天.然后今天看回Python 发现 Yield 这个忽然想不起是干嘛用的了(所以,好记性不如烂笔头.).然后只能 花点 ...

  3. GCC 预处理、编译、汇编、链接..

    1简介 GCC 的意思也只是 GNU C Compiler 而已.经过了这么多年的发展,GCC 已经不仅仅能支持 C 语言:它现在还支持 Ada 语言.C++ 语言.Java 语言.Objective ...

  4. node 异步回调解决方法之yield

    先看如何使用 使用的npm包为genny,npm 安装genny,使用 node -harmony 文件(-harmony 为使用es6属性启动参数) 启动项目 var genny= require( ...

  5. GDB调试汇编堆栈过程分析

    GDB调试汇编堆栈过程分析 分析过程 这是我的C源文件:click here 使用gcc - g example.c -o example -m32指令在64位的机器上产生32位汇编,然后使用gdb ...

  6. Beennan的内嵌汇编指导(译)Brennan's Guide to Inline Assembly

    注:写在前面,这是一篇翻译文章,本人的英文水平很有限,但内嵌汇编是学习操作系统不可少的知识,本人也常去查看这方面的内容,本文是在做mit的jos实验中的一篇关于内嵌汇编的介绍.关于常用的内嵌汇编(AT ...

  7. 从linux0.11中起动部分代码看汇编调用c语言函数

    上一篇分析了c语言的函数调用栈情况,知道了c语言的函数调用机制后,我们来看一下,linux0.11中起动部分的代码是如何从汇编跳入c语言函数的.在LINUX 0.11中的head.s文件中会看到如下一 ...

  8. C内嵌汇编-格式

    C内嵌汇编-格式: __asm__(汇编语句部分:输出部分:输入部分破坏描述部分);C内嵌汇编以关键字"__asm__"或"asm"开始, 下辖四个部分, 各部 ...

  9. 20145212——GDB调试汇编堆栈过程分析

    GDB调试汇编堆栈过程分析 测试代码 #include <stdio.h> short val = 1; int vv = 2; int g(int xxx) { return xxx + ...

随机推荐

  1. hibernate配置之<property name="hbm2ddl.auto">create</property>导致每次创建SessionFactory都清空数据库中的数据

    参考:http://stackoverflow.com/questions/6611437/how-to-make-hibernate-not-drop-tables 我遇到的问题就是: List l ...

  2. Echarts - js-20160611

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  3. wiremock之录制和回放

    Recording is done by starting the standalone runner like this: $ java -jar wiremock-1.50-standalone. ...

  4. Android Calander Event

    必须权限 <uses-permission android:name="android.permission.READ_CALENDAR" /> <uses-pe ...

  5. 自动化测试之python安装

    1.首先访问http://www.python.org/download/去下载最新的python版本. 2.安装下载包,一路next. 3.为计算机添加安装目录搭到环境变量,如图把python的安装 ...

  6. 第7篇 ORACLE EBS DEMO虚拟机环境的安装

    ERP信息系统的实施不仅要求懂得道理方面的知识,更要侧重于应用实践.为了有一个稳定的测试环境.初学者可以自己搭建一个EBS DEMO环境.本节介绍EBS DEMO环境虚拟机的安装.一. 安装前的准备( ...

  7. [LightOJ1004]Monkey Banana Problem(dp)

    题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1004 题意:数塔的变形,上面一个下面一个,看清楚 ...

  8. linux学习之centos(二):虚拟网络三种连接方式和SecureCRT的使用

    ---操作环境--- 虚拟机版本:VMware Workstation_10.0.3 Linux系统版本:CentOS_6.5(64位) 物理机系统版本:win10  一.虚拟网络三种连接方式 当在V ...

  9. Data.gov.uk电子政务云,牛津大学NIE金融大数据实验室王宁:数据治理的现状和实践

    牛津大学NIE金融大数据实验室王宁:数据治理的现状和实践 我是牛津互联网研究院的研究员,是英国开放互联网的一个主要的研究机构和相关政策制订的一个机构.今天主要给大家介绍一下英国数据治理的一些现状和实践 ...

  10. JS通用方法总结(一)

    /** * id数组转换为json字符串 */ function arrayTojson(arr) { var jsonIds = "["; for ( var i = 0; i ...