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. CentOS开机自动运行程序的脚本

    有些时候我们需要在服务器里设置一个脚本,让他一开机就自己启动.方法如下: cd /etc/init.dvi youshell.sh   #将youshell.sh修改为你自己的脚本名编写自己的脚本后保 ...

  2. 两则C++知识点

    返回引用遵守的两条准则: 1. 不能返回局部变量: 2. 不能返回new出的量,因为可能是临时对象. const的用法: 1. 基本数据类型的写限制: 2. 函数的传入以及返回参数: 3. 类内的数据 ...

  3. Backbone Backbone-localStorage demo

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. MV、MVC、MVP、MVVM简介,对MVC不确定了。

    参考: http://www.cnblogs.com/changxiangyi/archive/2012/07/16/2594297.html http://www.jcodecraeer.com/a ...

  5. ORACLE EBS R12 - 寄售功能知多少

    材料以寄售方式供应,是制造业实现零库存管理的一种方式.东西放在我这里,不用的时候,东西还是供应商的,用的时候,按"装机"数量进行付款.这种业务模式,对于竞争日趋白热化的家电行业,非 ...

  6. leetcode:Multiply Strings

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  7. java socket编程基础

    1. [代码]读操作Runable 1 package com.hrd.test.socket; import java.io.BufferedReader; import java.io.IOExc ...

  8. SCSS(SASS、CSS)学习

    看的这篇文章 http://www.frostsky.com/2014/07/sass-scss/ 写的还比较清晰 SASS是CSS3的一个扩展,增加了规则嵌套.变量.混合.选择器继承等等.通过使用命 ...

  9. delete-node-in-a-bst

    https://leetcode.com/problems/delete-node-in-a-bst/ /** * Definition for a binary tree node. * struc ...

  10. CSS控制超链接

    一.伪类 CSS控制元素的某种状态---偽类(用于向某些选择器添加特殊的效果)    偽类的语法:元素标签 偽类名称{属性:属性值;} 二.超链接        a:link:未访问的链接       ...