69,381
社区成员
发帖
与我相关
我的任务
分享
page ,132
title chkstk - C stack checking routine
;***
;chkstk.asm - C stack checking routine
;
; Copyright (c) Microsoft Corporation. All rights reserved.
;
;Purpose:
; Provides support for automatic stack checking in C procedures
; when stack checking is enabled.
;
;*******************************************************************************
.xlist
include cruntime.inc
.list
; size of a page of memory
_PAGESIZE_ equ 1000h
CODESEG
page
;***
;_chkstk - check stack upon procedure entry
;
;Purpose:
; Provide stack checking on procedure entry. Method is to simply probe
; each page of memory required for the stack in descending order. This
; causes the necessary pages of memory to be allocated via the guard
; page scheme, if possible. In the event of failure, the OS raises the
; _XCPT_UNABLE_TO_GROW_STACK exception.
;
; NOTE: Currently, the (EAX < _PAGESIZE_) code path falls through
; to the "lastpage" label of the (EAX >= _PAGESIZE_) code path. This
; is small; a minor speed optimization would be to special case
; this up top. This would avoid the painful save/restore of
; ecx and would shorten the code path by 4-6 instructions.
;
;Entry:
; EAX = size of local frame
;
;Exit:
; ESP = new stackframe, if successful
;
;Uses:
; EAX
;
;Exceptions:
; _XCPT_GUARD_PAGE_VIOLATION - May be raised on a page probe. NEVER TRAP
; THIS!!!! It is used by the OS to grow the
; stack on demand.
; _XCPT_UNABLE_TO_GROW_STACK - The stack cannot be grown. More precisely,
; the attempt by the OS memory manager to
; allocate another guard page in response
; to a _XCPT_GUARD_PAGE_VIOLATION has
; failed.
;
;*******************************************************************************
public _alloca_probe
_chkstk proc
_alloca_probe = _chkstk
push ecx
; Calculate new TOS.
lea ecx, [esp] + 8 - 4 ; TOS before entering function + size for ret value
sub ecx, eax ; new TOS
; Handle allocation size that results in wraparound.
; Wraparound will result in StackOverflow exception.
sbb eax, eax ; 0 if CF==0, ~0 if CF==1
not eax ; ~0 if TOS did not wrapped around, 0 otherwise
and ecx, eax ; set to 0 if wraparound
mov eax, esp ; current TOS
and eax, not ( _PAGESIZE_ - 1) ; Round down to current page boundary
cs10:
cmp ecx, eax ; Is new TOS
jb short cs20 ; in probed page?
mov eax, ecx ; yes.
pop ecx
xchg esp, eax ; update esp
mov eax, dword ptr [eax] ; get return address
mov dword ptr [esp], eax ; and put it at new TOS
ret
; Find next lower page and probe
cs20:
sub eax, _PAGESIZE_ ; decrease by PAGESIZE
test dword ptr [eax],eax ; probe page.
jmp short cs10
_chkstk endp
end
#include<stdio.h>//定义输入/输出函数
#include<stdlib.h>//定义杂项函数及内存分配函数
#include<string.h>//字符串处理
#include<math.h>//定义数学函数
#define N 2 //2列
#define L 1000 //100行
int main(int argc, char *argv[])
{
int i,j,t,c,p,q;
static int zm[40][36]={0};//初水位
static int zn[40][36]={0};//末水位
//int cq[p][c];//水位库容
// double E[80][36];//余留期效益值
// double n[i][t];//t-1到t阶段的最优出力期望
const char file_name[50] = "data.txt";
FILE *fp;
int data[N][L] = {0}; //二维数组
int index[N] = {0}; //二维数组列下标
double temp;
int v, u;
int count = 0; //计数器,记录已读出的浮点数
if((fp=fopen(file_name, "r")) == NULL) {
//printf("请确认文件(%s)是否存在!\n", file_name);
exit(1);
}
while(1==fscanf(fp, "%lf", &temp)) {
data[count%N][(index[count%N])++] = temp;
count++;
}
for(v = 0; v < N; v++) {
for(u = 0; u < index[v]; u++) {
// printf("%d",data[v][u]) ; //data[v][u];
}
// printf("\n");
}
fclose(fp);
const char file[50] = "xiayou.txt";
FILE* lfp;
if((lfp=fopen(file, "r")) == NULL)
{
printf("Cannot open this filefp1\n");
exit(0);
}
int res=0;
static double Y[2][851];
for (i = 0; i < 2; i++)
{
for (j = 0; j < 851; j++)
{
res = fscanf(lfp, "%lf", &Y[i][j]);
// printf("%lf \n", Y[i][j]);
}
}
fclose(lfp);
int a=0,num[36]={0};
for(u = 0; u < 36; u++) {
// printf("%d\t",data[0][u]);
//printf("%d\t",data[1][u]);
//printf("\n");
num[a]=data[0][u]-data[1][u];
a++;
}
// for(a= 0; a < 36; a++)
//printf("%d\n",num[a]);
for(t= 0; t < 36; t++){
for(i=0;i <=num[t] ;i++){
zn[i][t] =data[0][t];
data[0][t]--;
// printf("%d\t",zn[i][t]);
// printf("%d\t",data[0][t]);
// printf("\n");
}
// printf("\n");
}
// for(t= 0; t < 36; t++){
// for(i=0;i <=num[t] ;i++){
// printf("%d\t",zn[i][t]);
// }
// printf("\n");
// }
zm[0][0]=175;
for(t= 1; t < 36; t++){
// printf("%d\t",num[t]);
//printf("%d\t",data[0][t]);
// printf("\n");
for(i=0;i <=num[t-1] ;i++){
zm[i][t] =zn[i][t-1];
// printf("%d\t",zn[i][t]);
// printf("%d\t",zm[i][t]);
// printf("%d\t",data[0][t]);
// printf("\n");
}
// printf("\n");
}
// for(t= 0; t < 36; t++){
// for(i=0;i <40 ;i++){
// printf("%d\t",zm[i][t]);
// }
// printf("\n");
// }
int cq[2][31]={0};
for(v=0;v<2;v++){
for(c=0;c<31;c++){
cq[v][c]=data[v][36+c];
//printf("%d\t",data[p][36+c]);
//printf("%d\t",cq[p][c]);
}
// printf("\n");
}
static int vm[40][36]={0};
static int vn[40][36]={0}; //t阶段的初始库容和末库容
double Q[36]={5490.99,5167.74,4979.09,4479.39,4215.9,4972.32,5394.8,5715.45,5782.01,6036.54,8384.3,7269.1,10933.5,11231.05,15756.86,21060.24,16434.75,15703.82,22083.76,30670.07,29849.66,26963.16,37566.78,37049.67,31318.89,21285.04,16822.32,25209.31,17203.41,15313.36,12055.05,8785.44,8863.48,6668.28,6108.31,5249.94};
static double R[40][40][36]={0.0};//下泄流量
static double Rr[40][40][36]={0.0};
for(t= 0; t < 36; t++){
for(i=0;i <40 ;i++){
for(q=0;q<31;q++){
if(zm[i][t] == cq[0][q]){
vm[i][t]=cq[1][q];
// printf("%d\t",vm[i][t]);
}
continue;
}
}
// printf("\n");
}
for(t= 0; t < 36; t++){
for(i=0;i <40 ;i++){
for(q=0;q<31;q++){
if(zn[i][t] == cq[0][q]){
vn[i][t]=cq[1][q];
// printf("%d\t",vn[i][t]);
}
continue;
}
}
// printf("\n");
}
// double y[40][40][36]={0.0};//弃水
// double ***y;
double ***y = (double***)malloc(40* sizeof(double**));
for(i=0; i<40; i++)
{
y[i] = (double**)malloc(40*sizeof(double*));
for(j=0; j<40; j++)
{
y[i][j] = (double*)malloc(36*sizeof(double));
}
}
//finish creating use p[i][j][k] to access the data
//free the memory
// double *Qse=(double*)malloc(sizeof(double)*57600);
for(t= 0; t < 36; t++){
for(i=0;i <40 ;i++){
for(c=0;c<40;c++){
R[c][i][t]=vm[i][t]/10.0-vn[c][t]/10.0+Q[t];
if( 98800.0-R[c][i][t]<0.0){
// Qse[c]= R[c][i][t]-98800.0;
Rr[c][i][t]=90000.0;
}
else if(R[c][i][t]-5000.0>=0.0 &&98800.0-R[c][i][t]>=0.0)Rr[c][i][t]=R[c][i][t];
else continue;
// n[c][i][t]=8.8*Rr[c][i][t];
// printf("%.2f\t",R[c][i][0]);
// printf("%.2f\t",Qse[c] );
}
// printf("\n");
}
// printf("\n");
}
// for(c=0;c<40;c++)
// {
// printf("%d\t",vm[0][0]);
// printf("%d\t",vn[c][0]);
// printf("%.2f\n",R[c][0][0]);}
for(t= 0; t < 36; t++){
for(i=0;i <40 ;i++){
for(c=0;c<40;c++){
for(j=0;j<851;j++){
if((int)Rr[c][i][t]==Y[0][j])y[c][i][t]=Y[1][t];
else continue;}
}
}
}
static double n[40][40][36]={0.0};
static double nr[40][40][36]={0.0};
for(t= 0; t < 36; t++){
for(i=0;i <=num[t] ;i++){
for(c=0;c<=num[t];c++){
n[c][i][t]=8.8*Rr[c][i][t]*((zm[i][t]+zn[c][t])/2-y[c][i][t])*0.0001;
// printf("%.2f\t",nr[c][i][t] );
// printf("%.2f\t",n[c][i][t] );
}
// printf("\n");
}
// printf("\n");
}
// printf("%.2f\t",n[c][i][0] );
for(i=0; i<40; i++)
{
for(j=0; j<40; j++)
{
free(y[i][j]);
}
}
for(i=0; i<40; i++)
{
free(y[i]);
}
free(y);
int w,e,r,o,s,d,f,l,m,k,qw,we,er,rt,ty,yu,ui,io,op,pa;
int QQ=0,W=0,E=0,RR=0,T=0,YY=0,U=0,I=0,O=0,P=0,A=0,S=0,D=0,F=0,LL=0,M=0,QW=0,WE=0,ER=0,RT=0,TY=0,YU=0,UI=0,IO=0,OP=0,PA=0;
double val,valu;
double max1=0;
double max2=0;
double max;
for(pa=0;pa<=num[35];pa++){
for(op=0;op <=num[34]; op++){
for( io=0; io<=num[33]; io++){
for(ui =0;ui <=num[32]; ui++){
for(yu =0; yu<=num[31];yu ++){
for( ty=0;ty <=num[30];ty ++){
for(rt =0;rt <=num[29];rt ++){
for(er =0;er <=num[28]; er++){
for( we=0;we <=num[27]; we++){
for(qw =0;qw <=num[26];qw ++){
for(m =0;m <=num[25]; m++){
val=n[m][0][25]+n[qw][m][26]+n[we][qw][27]+n[er][we][28]+n[rt][er][29]+n[ty][rt][30]+n[yu][ty][31]+n[ui][yu][32]+n[io][ui][33]+n[op][io][34]+n[pa][op][35];
if(val-max1>0.1){
max1=val;
M=m;
QW=qw;
WE=we;
ER=er;
RT=rt;
TY=ty;
YU=yu;
UI=ui;
IO=io;
OP=op;
PA=pa;
}
}
}
}
}
}
}
}
}
}
}
}
for(f=0;f<=num[14];f++){
for(d=0;d<=num[13];d++){
for(s=0;s<=num[12];s++){
for(a=0;a<=num[11];a++){
for(p=0;p<=num[10];p++){
for(o=0;o<=num[9];o++){
for(i=0;i<=num[8];i++){
for(u=0;u<=num[7];u++){
for(k=0;k<=num[6];k++){
for(t=0;t<=num[5];t++){
for(r=0;r<=num[4];r++){
for(e=0;e<=num[3];e++){
for(w=0;w<=num[2];w++){
for(q=0;q<=num[1];q++){
for(l=0;l<=num[0];l++){
valu=n[l][0][0]+n[q][l][1]+n[w][q][2]+n[e][w][3]+n[r][e][4]+n[t][r][5]+n[k][t][6]+n[u][k][7]+n[i][u][8]+n[o][i][9]+n[p][o][10]+n[a][p][11]+n[s][a][12]+n[d][s][13]+n[f][d][14];
if(valu-max2>0.1) {
max2=valu;
LL=l;
QQ=q;
W=w;
E=e;
RR=r;
T=t;
YY=k;
U=u;
I=i;
O=o;
P=p;
A=s;
S=s;
D=d;
F=f;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
max=max2+n[0][F][15]+n[0][0][16]+n[0][0][17]+n[0][0][18]+n[0][0][19]+n[0][0][20]+n[0][0][21]+n[0][0][22]+n[0][0][23]+n[0][0][24]+max1;
printf("%.2f\n",max);
printf("%d %d %d %d %d %d %d %d %d %d\n",LL,QQ,W,E,RR,T,YY,U,I,O);
printf("%d %d %d %d %d\n",P,A,S,D,F);
printf("%d %d %d %d %d %d %d %d %d %d\n",M,QW,WE,ER,RT,TY,YU,UI,IO,OP);
printf("%d\n",PA);
}
#include<stdio.h>//定义输入/输出函数
#include<stdlib.h>//定义杂项函数及内存分配函数
#include<string.h>//字符串处理
#include<math.h>//定义数学函数
#define N 2 //2列
#define L 1000 //100行
int main(int argc, char *argv[])
{
int i,j,t,c,p,q;
int zm[40][36]={0};//初水位
int zn[40][36]={0};//末水位
//int cq[p][c];//水位库容
// double E[80][36];//余留期效益值
// double n[i][t];//t-1到t阶段的最优出力期望
const char file_name[50] = "data.txt";
FILE *fp;
int data[N][L] = {0}; //二维数组
int index[N] = {0}; //二维数组列下标
double temp;
int v, u;
int count = 0; //计数器,记录已读出的浮点数
if((fp=fopen(file_name, "rb")) == NULL) {
//printf("请确认文件(%s)是否存在!\n", file_name);
exit(1);
}
while(1==fscanf(fp, "%lf", &temp)) {
data[count%N][(index[count%N])++] = temp;
count++;
}
for(v = 0; v < N; v++) {
for(u = 0; u < index[v]; u++) {
// printf("%d",data[v][u]) ; //data[v][u];
}
// printf("\n");
}
fclose(fp);
const char file[50] = "xiayou.txt";
FILE* lfp;
if((lfp=fopen(file, "rb")) == NULL)
{
printf("Cannot open this filefp1\n");
exit(0);
}
int res=0;
double Y[2][851];
for (i = 0; i < 2; i++)
{
for (j = 0; j < 851; j++)
{
res = fscanf_s(lfp, "%lf", &Y[i][j]);
// printf("%lf \n", Y[i][j]);
}
}
fclose(lfp);
int a=0,num[36]={0};
for(u = 0; u < 36; u++) {
// printf("%d\t",data[0][u]);
//printf("%d\t",data[1][u]);
//printf("\n");
num[a]=data[0][u]-data[1][u];
a++;
}
// for(a= 0; a < 36; a++)
//printf("%d\n",num[a]);
for(t= 0; t < 36; t++){
for(i=0;i <=num[t] ;i++){
zn[i][t] =data[0][t];
data[0][t]--;
// printf("%d\t",zn[i][t]);
// printf("%d\t",data[0][t]);
// printf("\n");
}
// printf("\n");
}
// for(t= 0; t < 36; t++){
// for(i=0;i <=num[t] ;i++){
// printf("%d\t",zn[i][t]);
// }
// printf("\n");
// }
zm[0][0]=175;
for(t= 1; t < 36; t++){
// printf("%d\t",num[t]);
//printf("%d\t",data[0][t]);
// printf("\n");
for(i=0;i <=num[t-1] ;i++){
zm[i][t] =zn[i][t-1];
// printf("%d\t",zn[i][t]);
// printf("%d\t",zm[i][t]);
// printf("%d\t",data[0][t]);
// printf("\n");
}
// printf("\n");
}
// for(t= 0; t < 36; t++){
// for(i=0;i <40 ;i++){
// printf("%d\t",zm[i][t]);
// }
// printf("\n");
// }
int cq[2][31]={0};
for(v=0;v<2;v++){
for(c=0;c<31;c++){
cq[v][c]=data[v][36+c];
//printf("%d\t",data[p][36+c]);
//printf("%d\t",cq[p][c]);
}
// printf("\n");
}
int vm[40][36]={0};
int vn[40][36]={0}; //t阶段的初始库容和末库容
double Q[36]={5490.99,5167.74,4979.09,4479.39,4215.9,4972.32,5394.8,5715.45,5782.01,6036.54,8384.3,7269.1,10933.5,11231.05,15756.86,21060.24,16434.75,15703.82,22083.76,30670.07,29849.66,26963.16,37566.78,37049.67,31318.89,21285.04,16822.32,25209.31,17203.41,15313.36,12055.05,8785.44,8863.48,6668.28,6108.31,5249.94};
double R[40][40][36]={0.0};//下泄流量
double Rr[40][40][36]={0.0};
for(t= 0; t < 36; t++){
for(i=0;i <40 ;i++){
for(q=0;q<31;q++){
if(zm[i][t] == cq[0][q]){
vm[i][t]=cq[1][q];
// printf("%d\t",vm[i][t]);
}
continue;
}
}
// printf("\n");
}
for(t= 0; t < 36; t++){
for(i=0;i <40 ;i++){
for(q=0;q<31;q++){
if(zn[i][t] == cq[0][q]){
vn[i][t]=cq[1][q];
// printf("%d\t",vn[i][t]);
}
continue;
}
}
// printf("\n");
}
// double y[40][40][36]={0.0};//弃水
// double ***y;
double ***y = (double***)malloc(40* sizeof(double**));
for(i=0; i<40; i++)
{
y[i] = (double**)malloc(40*sizeof(double*));
for(j=0; j<40; j++)
{
y[i][j] = (double*)malloc(36*sizeof(double));
}
}
//finish creating use p[i][j][k] to access the data
//free the memory
// double *Qse=(double*)malloc(sizeof(double)*57600);
for(t= 0; t < 36; t++){
for(i=0;i <40 ;i++){
for(c=0;c<40;c++){
R[c][i][t]=vm[i][t]/10.0-vn[c][t]/10.0+Q[t];
if( 98800.0-R[c][i][t]<0.0){
// Qse[c]= R[c][i][t]-98800.0;
Rr[c][i][t]=90000.0;
}
else if(R[c][i][t]-5000.0>=0.0 &&98800.0-R[c][i][t]>=0.0)Rr[c][i][t]=R[c][i][t];
else continue;
// n[c][i][t]=8.8*Rr[c][i][t];
// printf("%.2f\t",R[c][i][0]);
// printf("%.2f\t",Qse[c] );
}
// printf("\n");
}
// printf("\n");
}
// for(c=0;c<40;c++)
// {
// printf("%d\t",vm[0][0]);
// printf("%d\t",vn[c][0]);
// printf("%.2f\n",R[c][0][0]);}
for(t= 0; t < 36; t++){
for(i=0;i <40 ;i++){
for(c=0;c<40;c++){
for(j=0;j<851;j++){
if((int)Rr[c][i][t]==Y[0][j])y[c][i][t]=Y[1][t];
else continue;}
}
}
}
double n[40][40][36]={0.0};
double nr[40][40][36]={0.0};
for(t= 0; t < 36; t++){
for(i=0;i <=num[t] ;i++){
for(c=0;c<=num[t];c++){
n[c][i][t]=8.8*Rr[c][i][t]*((zm[i][t]+zn[c][t])/2-y[c][i][t])*0.0001;
// printf("%.2f\t",nr[c][i][t] );
// printf("%.2f\t",n[c][i][t] );
}
// printf("\n");
}
// printf("\n");
}
// printf("%.2f\t",n[c][i][0] );
for(i=0; i<40; i++)
{
for(j=0; j<40; j++)
{
free(y[i][j]);
}
}
for(i=0; i<40; i++)
{
free(y[i]);
}
free(y);
int w,e,r,o,s,d,f,l,m,k,qw,we,er,rt,ty,yu,ui,io,op,pa;
int QQ=0,W=0,E=0,RR=0,T=0,YY=0,U=0,I=0,O=0,P=0,A=0,S=0,D=0,F=0,LL=0,M=0,QW=0,WE=0,ER=0,RT=0,TY=0,YU=0,UI=0,IO=0,OP=0,PA=0;
double val,valu;
double max1=0;
double max2=0;
double max;
for(pa=0;pa<=num[35];pa++){
for(op=0;op <=num[34]; op++){
for( io=0; io<=num[33]; io++){
for(ui =0;ui <=num[32]; ui++){
for(yu =0; yu<=num[31];yu ++){
for( ty=0;ty <=num[30];ty ++){
for(rt =0;rt <=num[29];rt ++){
for(er =0;er <=num[28]; er++){
for( we=0;we <=num[27]; we++){
for(qw =0;qw <=num[26];qw ++){
for(m =0;m <=num[25]; m++){
val=n[m][0][25]+n[qw][m][26]+n[we][qw][27]+n[er][we][28]+n[rt][er][29]+n[ty][rt][30]+n[yu][ty][31]+n[ui][yu][32]+n[io][ui][33]+n[op][io][34]+n[pa][op][35];
if(val-max1>0.1){
max1=val;
M=m;
QW=qw;
WE=we;
ER=er;
RT=rt;
TY=ty;
YU=yu;
UI=ui;
IO=io;
OP=op;
PA=pa;
}
}
}
}
}
}
}
}
}
}
}
}
for(f=0;f<=num[14];f++){
for(d=0;d<=num[13];d++){
for(s=0;s<=num[12];s++){
for(a=0;a<=num[11];a++){
for(p=0;p<=num[10];p++){
for(o=0;o<=num[9];o++){
for(i=0;i<=num[8];i++){
for(u=0;u<=num[7];u++){
for(k=0;k<=num[6];k++){
for(t=0;t<=num[5];t++){
for(r=0;r<=num[4];r++){
for(e=0;e<=num[3];e++){
for(w=0;w<=num[2];w++){
for(q=0;q<=num[1];q++){
for(l=0;l<=num[0];l++){
valu=n[l][0][0]+n[q][l][1]+n[w][q][2]+n[e][w][3]+n[r][e][4]+n[t][r][5]+n[k][t][6]+n[u][k][7]+n[i][u][8]+n[o][i][9]+n[p][o][10]+n[a][p][11]+n[s][a][12]+n[d][s][13]+n[f][d][14];
if(valu-max2>0.1) {
max2=valu;
LL=l;
QQ=q;
W=w;
E=e;
RR=r;
T=t;
YY=k;
U=u;
I=i;
O=o;
P=p;
A=s;
S=s;
D=d;
F=f;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
max=max2+n[0][F][15]+n[0][0][16]+n[0][0][17]+n[0][0][18]+n[0][0][19]+n[0][0][20]+n[0][0][21]+n[0][0][22]+n[0][0][23]+n[0][0][24]+max1;
printf("%.2f\n",max);
printf("%d %d %d %d %d %d %d %d %d %d\n",LL,QQ,W,E,RR,T,YY,U,I,O);
printf("%d %d %d %d %d\n",P,A,S,D,F);
printf("%d %d %d %d %d %d %d %d %d %d\n",M,QW,WE,ER,RT,TY,YU,UI,IO,OP);
printf("%d\n",PA);
}
程序之前运行到259行都是正确的,可以输出n[][][]的值,但是加上后面两个循环以后就不能输出了