注册 登录
编程论坛 汇编论坛

求助--------为什么会这样?

mjkbmykwolf 发布于 2008-10-31 14:40, 1004 次点击
我编的一个分类统计字符个数的汇编程序,代码如下:
  ; Assembly  language  program-
; Author:
; Data:


.386
.MODEL FLAT


ExitProcess  PROTO  NEAR32  stdcall, dwExitCode:DWORD

INCLUDE io.h                            ;header   file  for  input/out

cr          EQU       0dh                ;carriage  return  character
LF         EQU       0Ah                ;line  feed

.STACK     4096                         ;reserve   4096-byte stack

.DATA                                      ;reserve   storage  for  data
;**************************************************
prompt1   byte   cr,Lf,"Please input the string(less than eighty) :"
string    byte   80 dup(?)
prompt2   byte   cr,Lf,"The sum of the letter is :"
letterof  byte   ?
          byte   cr,Lf,0
prompt3   byte   cr,Lf,"The sum of the number is :"
numof     byte   ?
          byte   cr,Lf,0
prompt4   byte   cr,Lf,"The sum of the other is :"
otherof   byte   ?
          byte   cr,Lf,0



;**************************************************
.CODE
_start:                                     ;start  of main  program  code
;**************************************************
startofall:
   output   prompt1           ;输出提示语句
   mov      letterof,0
   mov      numof,0
   mov      otherof,0
   input    string,78
   mov      esi,0
numberif:
   mov      eax,string[esi]
   cmp      esi,78
   je       endfile
   cmp      eax,00h
   je       endfile
   cmp      eax,30h
   jl       otherof
   cmp      eax,39h
   jg       letterif1
   inc      numof
   jmp      numberif
letterif1:
   cmp      eax,41h
   jl       otherif
   cmp      eax,5Ah
   jg       letterif2
   inc      letterof
   jmp      numberif
letterif2:
   cmp      eax,61h
   jl       otherif
   cmp      eax,7Ah
   jg       otherif
   inc      letterif
   jmp      numberif
otherif:
   inc      otherof
   jmp      numberif
endfile:   
   output   prompt2
   output   prompt3
   output   ptompt4
   
   

endof:  invoke   exitprocess,0              ;come out
;**************************************************
PUBLIC _start                         ;make entry point public  

END                                       ;end  of  source  code

但是当我运行的时候怎么老是弹出一个对话框说:
     0x00401083指令饮用的0x0080805a内存。该内存不能为read。
     不调试请按确定,调试请按取消

到底是哪里的问题呀?
希望大家多多指点。  
谢谢了。
9 回复
#2
ONEPROBLEM2008-10-31 15:52
请用反汇编工具,查找对应的指令.
#3
mjkbmykwolf2008-10-31 23:16
回复 2# 的帖子
谢谢
#4
cnhanxiao2008-11-01 00:29
output函数语法是?
对这种“高级”汇编语言不熟悉,感觉output函数使用上有问题,再有,一般字符串应该有结束标识,如DOS下用“$”,win32下用“0”,试试:
prompt1   byte   cr,Lf,"Please input the string(less than eighty) :",0
...
#5
zklhp2008-11-01 09:45
程序代码:

;MASMPlus 代码模板 - 控制台程序

.586
.model flat, stdcall
option casemap :none

include windows.inc
include user32.inc
include kernel32.inc
include masm32.inc
include gdi32.inc


includelib gdi32.lib
includelib user32.lib
includelib kernel32.lib
includelib masm32.lib
include macro.asm


.data
    ;lpMsg        db "Hello World!",0
    prompt1 db 0dh,0ah,'Please input the string(less than eighty) :',0
    string db 80 dup(?)
    prompt2 db 0dh,0ah,'The sum of the letter is :0',0
    prompt3 db 0dh,0ah,'The sum of the number is :0',0
    prompt4 db 0dh,0ah,'The sum of the other is :0',0
    letterof dd [prompt2+28]
    numberof dd [prompt3+28]
    otherof dd [prompt4+27]

.data?
    buffer    db MAX_PATH dup(?)
    
.CODE
START:
    invoke StdOut,offset prompt1        ;输出提示语句
    invoke StdIn,offset string,78d
    dec eax
    dec eax
    dec eax
    mov ecx,eax
numberif:
    mov al,BYTE ptr [string+ecx]
    inc ecx
    je endfile
    dec ecx
    cmp al,00h
    je  endfile
    cmp al,30h
    jl  otherif
    cmp al,39h
    jg  letterif1
    mov esi,DWORD ptr [numberof]
    inc BYTE ptr [esi]
    dec ecx
    jmp numberif
letterif1:
    cmp al,41h
    jl  otherif
    cmp al,5Ah
    jg  letterif2
    mov esi,DWORD ptr [letterof]
    inc BYTE ptr [esi]
    dec ecx
    jmp numberif
letterif2:
    cmp al,61h
    jl  otherif
    cmp al,7Ah
    jg  otherif
    mov esi,DWORD ptr [letterof]
    inc BYTE ptr [esi]
    dec ecx
    jmp numberif
otherif:
    mov esi,DWORD ptr [otherof]
    inc BYTE ptr [esi]
    dec ecx
    jmp numberif
endfile:    
    invoke StdOut,offset prompt2
    invoke StdOut,CTXT(0dh,0ah)
    invoke StdOut,offset prompt3
    invoke StdOut,CTXT(0dh,0ah)
    invoke StdOut,offset prompt4
    invoke StdOut,CTXT(0dh,0ah)

    ;invoke locate,2,2            ;设定输出文本的坐标
    ;invoke StdOut,offset lpMsg
    
    ;暂停显示,回车键关闭
    invoke StdIn,addr buffer,sizeof buffer
    invoke ExitProcess,0
    
end START
#6
zklhp2008-11-01 09:47
本来很简单的程序 让我改来改去改的这么复杂……

算法有点问题 数大了就不行了

用到了指针……

改程序比写难多了
#7
mjkbmykwolf2008-11-01 17:24
回复 4# 的帖子
output  变量名   
 这个应该是没有问题的
#8
mjkbmykwolf2008-11-01 17:27
回复 6# 的帖子
呵呵,我用的是386的.386和586的语法应该是一样的吧!貌似,但好多东西还没有学到.
#9
cnhanxiao2008-11-01 17:31
回复 8# 的帖子
不知你的编译系统。
你先试试在数据段每行字符串后加上—— ,0
试试。不然output不知道在哪里停顿。
#10
mjkbmykwolf2008-11-01 17:45
我试了一下,是在prompt1后面少加了一个  ,和 0 .谢谢大家的支持.
1