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. java string,需要进行首字母大写改写

    java string,需要进行首字母大写改写,网上大家的思路基本一致,就是将首字母截取,转化成大写然后再串上后面的,类似如下代码 //首字母大写     public static String c ...

  2. jquery的extend和fn.extend的使用说明

    jQuery.fn.extend(object); 对jQuery.prototype进得扩展,就是为jQuery类添加“成员函数”.jQuery类的实例可以使用这个“成员函数”. jQuery为开发 ...

  3. tomcat manager app 和 host maganger

    当你以为你了解某个东西时,其实你不了解它.比如tomcat也可以像jboss一样有用户名和密码 就在apache-tomcat-8.0.21\conf\tomcat-users.xml里配置用户名和密 ...

  4. 【CCS仿真】用matlab把CCS保存的32位16进制的数据转换为十进制的数

    2013-12-04 16:37:28 使用fscanf函数即可完成. 例如,CCS保存的.dat文件Copy_of_forward_i_f.dat如下: 1651 1 81008800 0 4000 ...

  5. Mtk Android编译命令

    一.输入命令: cbk@YCS:~/work/k6/alps$ ./mk help Usage: (makeMtk|mk) [options] project actions [modules] Op ...

  6. 数据库系统中事务的ACID原则

    事务的原子性.一致性.独立性及持久性 事务的原子性是指一个事务要么全部执行,要么不执行.也就是说一个事务不可能只执行了一半就停止了.比如你从取款机取钱,这个事务可以分成两个步骤:1划卡,2出钱.不可能 ...

  7. 【转载】Javascript原型继承-学习笔记

    阮一峰这篇文章写的很好 http://www.ruanyifeng.com/blog/2011/06/designing_ideas_of_inheritance_mechanism_in_javas ...

  8. 51nod1225 余数之和

    打表可以看出规律.分块求就可以了. #include<cstdio> #include<cstring> #include<cctype> #include< ...

  9. Asp.net中的HttpModule和HttpHandler的简单用法

    在Asp.net中,HttpModule和HttpHandler均可以截取IIS消息进行处理,这使得我们制作人员能够非常方便的进行诸如图片水印添加,图片盗链检查等功能. 下面先就HttpModule的 ...

  10. C语言之字节对齐

    在C语言编程中,有时为了达到减少运行的时间的目的,需要浪费一些空间:而有时为了节省空间,使它的运行时间增长.而字节对齐则是为了访问效率,用空间换取时间. 要掌握字节对齐,首先得明确一下四个概念: 1. ...