Curry_warrior 2018-10-31 03:29 采纳率: 50%
浏览 422
已结题

求大佬帮我分析一下我的汇编程序出现的问题

#include "pch.h"
#include
int main() {
 char message1[] = "\nGive me  a character or number%d:\n ";
 char message2[] = "\nIt is an even number\n";
 char message3[] = "\nIt is an odd number\n";
 char message4[] = "\nThe program now ends\n ";
 char message5[] = "\nPlease give me a positive number\n";
 char message6[] = "\nPlease give me a number for loop";
 char message7[] = "\nIt is an upper case\n";
 char message8[] = "\nIt is a lower case\n";
 char message9[] = "\nPlease give me a number for loop\n";
 char message10[] = "\nNumber of entries is %d:\n";
 char message11[]="\nNumber of uppercase character is %d:\n";
 char message12[] = "\nNumber of lowercase character is %d:\n";
 char message13[] = "\nNumber of even number is %d:\n";
 char message14[] = "\nNumber of odd number is %d:\n";
 char format2[] = "\n%c";
 char format1[] = "\n%d";
 int  second;
 int first;
 char third;
 int fourth=1;
 int count1 = 0;
 int count2 = 0;
 int count3 = 0;
 int count4 = 0;
 int count5 = 0; 

_asm {
     screen:
  lea  eax, message9   /* 打印message9:
                                      Please give me a number for loop
  push eax
  call printf
  add esp, 4                /
  
 lea eax, first       /
将整数first放入堆栈中并做到使用户输入一个数字
  push eax
  lea eax, format1
  push eax
  call scanf_s
  add esp, 8          /
  
  mov ecx, first      /
将first赋值给ecx寄存器并将first和0比较,如果小于等于0,跳到rety p e1,否则跳到start
  cmp ecx, 0
  jle retype1
  jmp start             */  

retype1 :           /*打印message5:Please give me a positive number并跳到screen(一开始)
  lea eax, message5
  push eax
  call printf
  jmp screen            /
 
 finish1 :               /
中转站,所有判断条件完成后跳到这进行循环
  pop ecx
   loop start
   jmp finish       /
 
  start :
  push ecx               ;将ecx送入堆栈,开始计数
  
  mov eax,fourth         /
将fourth赋值给eax,并将fourth加1
  add fourth,1
  push eax                 /
  
  lea  eax, message1         /
打印message1:Give me  a character or number
  push eax
   call printf
   add esp, 8           /   
  
   lea eax, third      /
使用户输入一个字母或数字
   push eax
   lea eax, format2
   push eax
   call scanf_s
   add esp, 8            /  
  
   mov ah, third      /
跟ASCII表中的2a进行比较(*)
   cmp ah, 2ah          即如果输入的是*就跳到finish
   je  finish          */
   

  cmp ah, 39h       /*跟ASCII表中的39h比较,如果大于则跳到string标签
   jg  string          */   

  number :
  mov ah, third           /*跟2Dh比较,即如果检测到‘-’就跳到retype
   cmp ah, 2Dh
   je retype          /  
  
   test ah, 01h   /
判断数字是否含有01,即判断奇数还是偶数
   jz   even1     如果为0,则跳到even1*/
  

 odd :
  lea  eax, message3   /*否则打印出它是一个奇数
   push eax
   call printf;
  add  esp, 4           */
 

 add  count1,1           /*对输入总次数和奇数个数进行计数
  add  count5,1             并跳到finish1
   jmp finish1      */   

  even1 :
  lea  eax, message2     /*打印它是一个偶数
   push eax
   call printf;
  add  esp, 4               /
  
  add count2,1      /
对输入偶数个数和输入总次数进行计数,
  add count5,1                   并跳到finish
   jmp finish1              */   

   retype :
  lea   eax, message5           /*如果输入的是负数,则会打印message5:Please give me a positive number
   push  eax
   call printf
   add esp, 4               */
   jmp start
   

  String :
  mov ah, third                  /*将输入的数与5Ah进行比较(‘Z’)
   cmp  ah, 5Ah            如果大于则跳入lower
   jg    lower              */
   

   lea  eax, message7    /*否则打印出它是大写
   push eax
   call printf
   add esp, 4                */
  

   add count3,1         /*对输入总次数和大写个数进行技术并跳到finish1
   add count5,1
   jmp finish1            /  
 
  lower :
  lea eax, message8        /
打印它是小写
   push eax
   call printf
   add esp, 4       */
   

   add count4,1   /*计数
   add count5,1
   jmp finish1      */
 

   finish:
  mov eax,count5      /*打印一共输入了多少次
  push eax
  lea eax,message10
  push eax
  call printf
  add esp,8             */  
 

 mov eax,count3        /*打印输入大写个数为多少次
  push eax
  lea eax,message11
  push eax
  call printf
  add esp,8               */  

  mov eax,count4         /*打印小写个数为多少次
  push eax
  lea eax,message12
  push eax
  call printf
  add esp,8               */  

  mov eax,count2         /*打印输入偶数多少次
  push eax
  lea eax,message13
  push eax
  call printf
  add esp,8                   */  

  mov eax,count1        /*打印输入奇数多少次
  push eax
  lea eax,message14
  push eax
  call printf
  add esp,8                           */

  lea   eax, message4             /*打印:程序已经结束
   push eax
   call printf
   add  esp, 4                                 */ 
}
 return 0;
}

我现在的问题是:
1.如果在循环进行中,即手动输入了循环数后,如果输入一个负数,虽然程序会提示请给我一个正数,但是循环无法停下来。

2.程序一次只能判断一个数字或字母,因为我输入的格式是%c,但是如果输入的是%s,可以判断两位数,但是最后一个无论输入什么都会打印它是偶数

3.当输入”*"想让程序停止时,程序会打出程序结束,但是是异常结束

求求大佬教我一下解决方案,万分感激。

  • 写回答

2条回答 默认 最新

  • 佐菲 2018-10-31 04:59
    关注

    1.循环无法停下来指的是什么?看代码应该是跳去重新要求输入一个循环数吧?
    2.想判断多位数需要再内建一个循环处理输入数组数据。scanf_s的%s入参好像是两个,第二个数字是长度,没输入估计默认0,那肯定当成0长字符串,输入变成\0,所以结果必定打印偶数?
    3._不太熟汇编,检讨一下是不是有越界操作

    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧