这是作业:
写一个"菜单驱动"从键盘读取段落并按以下方式处理它的程序:
计算段落中的字符数, 计算单词数量, 计算与姓氏的第三个字母相同的字母数, 计算大写字母数。
使用特殊字符终止段落:
如果你的姓氏以A,B,C,D,E,F,G开头,H用#终止段落,
如果您的姓氏以I,J,K,L,M,N,O,P开头,则以%结束段落,
如果您的姓氏以R,S,T,U,V,W,X,Y,Z开头,则用&amp ;,
终止该段落在本练习中,您需要使用子程序。阅读主程序中的段落;
子程序中的处理段落(每个计数的单独程序)。
这是我的代码,我在最后一行收到A1010错误(无法匹配的嵌套:main),我无法找出原因,请帮忙。我正在使用Visual Studio 2015:
include Irvine32.inc
displayMSG MACRO MSG
MOV AH, 09H
LEA DX, MSG
INT 21H
ENDM
.DATA
para DB 100 , ? , 100 DUP('$')
;messages for menu
mes1 DB 0AH, 0DH, 'MENU $'
mes21 DB 0AH, 0DH, '1.COUNT CHARACTERS $'
mes22 DB 0AH, 0DH, '2.COUNT WORDS $'
mes23 DB 0AH, 0DH, '3.COUNT CAPITAL LETTERS $'
mes24 DB 0AH, 0DH, '4.COUNT THIRD LETTER $'
mes25 DB 0AH, 0DH, '5.EXIT $'
mes3 DB 0AH, 0DH, 'ENTER YOUR CHOICE : $'
mes4 DB 0AH, 0DH, 'WRONG CHOICE $'
mes5 DB 0AH, 0DH, 'ENTER THE PARAGRAPH : $'
mes6 DB 0AH, 0DH, 'NUMBER OF CHARACTERS IS : $'
mes7 DB 0AH, 0DH, 'NUMBER OF WORDS $'
mes8 DB 0AH, 0DH, 'NUMBER OF CAPITAL LETTERS $'
mes9 DB 0AH, 0DH, 'NUMBER OF THIRD LETTER $'
.CODE
main PROC
start:
mov ax, @data
mov ds, ax
mov es, ax
displayMSG mes5 ;PROMPT THE USER TO ENTER A PARAGRAPH
mov ah, 0ah ; Accept PARAGRAPH
lea dx, para
int 21h
;DISPLAY MENU TO THE USER
menu :
displayMSG mes1
displayMSG mes21
displayMSG mes22
displayMSG mes23
displayMSG mes24
displayMSG mes25
displayMSG mes3 ; accept choice
mov ah, 01h
int 21h
mov bl, al ; userChoice BL
cmp bl, 31h ; if userChoice=1
je FINDCHAR ; Find NUMBER OF CHARACTERS IN THE STRING
cmp bl, 32h ; if userChoice=2
je FINDWORDS ; FIND NUMBER OF WORDS
cmp bl, 33h ; if userChoice=3
je FINDCAPITAL ; FIND NUMBER OF CAPITAL LETTERS
cmp bl, 34h ; if userChoice=4
je FINDLETTER
cmp bl, 35h ; if userChoice=5
je L1 ; exit
displayMSG mes4 ; Wrong Choice
jmp menu
FINDCHAR:
call FINDCHARPROC
jmp menu
FINDWORDS :
call FINDWORDSPROC
jmp menu
FINDCAPITAL:
call FINDCAPITALSPROC
jmp menu
FINDLETTER :
call FINDTHIRDPROC
jmp menu
L1:
end start
exit
exit
main ENDP
;procedure THAT FINDS NUMBER OF CHARACTERS
FINDCHARPROC proc
displayMSG mes6
mov dl, para+1 ; NUMBER OF CHARACTERS IN THE PARAGRAPH
or dl, 30h
mov ah, 02h ; DISPLAY THE CHARACTERS COUNT
int 21h
ret
FINDCHARPROC ENDP
;find number of WORDS in the paragraph
FINDWORDSPROC proc
mov dl,00h
mov ch, 00h
lea esi, para+2
mov cl, para+1
mov bl,20h ;ASCII value of space
loopAn:
dec cl
cmp cl, 00h
je printWordCount
cmp bl, [esi] ;check if character is space
je incWordCnt
inc esi
jne loopAn
incWordCnt:
inc dl
inc esi
jmp loopAn
printWordCount:
displayMSG mes7
or dl,30h
mov ah,02h
int 21h
ret
FINDWORDSPROC ENDP
;find number of CAPITAL letters in the paragraph
FINDCAPITALSPROC proc
mov dl,00h
mov ch, 00h
lea esi, para+2 ; USER INPUTTED PARAGRAPH
mov cl, para+1
loopAgn:
dec cl
cmp cl, 00h
je printcapitalCount
mov al, byte ptr[esi]
cmp al,"A" ;check if character is capital
jb nextChar
cmp al,"Z" ;check if character is capital
ja nextChar
inc esi
inc dl
jne loopAgn
nextChar:
inc esi
jmp loopAgn
printcapitalCount :
displayMSG mes8
or dl,30h
mov ah,02h
int 21h
ret
FINDCAPITALSPROC ENDP
;count the number of third letter present in the paragraph
FINDTHIRDPROC proc
mov dl,00h
mov ch, 00h
lea esi, para+2 ; DESTINATION STRING
mov cl, para+1
call ReadChar ;get THIRD letter of your name
loopTemp:
dec cl
cmp cl, 00h
je printCount
cmp al, [esi] ;check if character is your third letter
je incCnt
inc esi
jne loopTemp
incCnt:
inc dl
inc esi
jmp loopTemp
printCount :
displayMSG mes9
or dl,30h
mov ah,02h
int 21h
ret
FINDTHIRDPROC ENDP
END main
答案 0 :(得分:2)
除了多余的end start
pointed out by commenter Jester之外,我认为你正在尝试使用32位汇编程序编译16位汇编程序,这是行不通的。 (与此相关,我猜在开头的包含文件也应该是Irvine16.inc
而不是Irvine32.inc
。)
您必须使用16位汇编程序项目,请参阅http://kipirvine.com/asm/gettingStartedVS2015/index.htm#16-bit
但是,如果您使用的是64位版本的Windows,则无法本机运行程序。您需要使用虚拟机或DOSBox来运行和测试您的程序。