该程序采用汇编语言[MASM],并基于 Kirrvine的第5章。 x86处理器的汇编语言,第七版。培生教育,2015 。 当我尝试在提示符下不输入名称时,名称的cmp&je指令不起作用。如果按Enter,它将显示“按任意键继续”,但它下方还会显示一些垃圾。
TITLE MASM Template (main.asm)
INCLUDE Irvine32.inc
NAMEGRADE STRUCT ;structure storing the name & grade
personName BYTE 26 DUP (?)
personGrade BYTE 2 DUP (?)
NAMEGRADE ENDS
.data
str1 BYTE "Please enter student's name",0dh,0ah,0 ;Prompt1
str2 BYTE "Please enter ",0 ;Prompt2
str3 BYTE "'s grade",0dh,0ah,0 ;Prompt3
CounterOne BYTE 00H ;counter 1 used for inputting array
CounterTwo BYTE 00H ;counter 2 used for outputting array
MyTable NAMEGRADE 20 DUP (<>) ;table storing the arrays with structure initialized variables
personName BYTE 26 DUP (?) ;Name unitnitialized currently
.code
main PROC
Startover: ;Label used for jumping back after successful output and after 1 successful array input
call Clrscr ;Clears the screen
mov edx, OFFSET str1
call WriteString ;Prompt1 diplayed
mov edx,OFFSET personName
mov ecx,26 ;26 characters allowed for the name
call ReadString ;inputs name
cmp personName, 0 ;No name entered, then display table else exit
je ArrayOut
mov eax,SIZEOF NAMEGRADE ;Calculate offset in structure
mul CounterOne ;sets counter
mov edi,eax
mov esi, OFFSET personName ;Offset of the source for the move
add edi, OFFSET MyTable.personName ;adds it to the table elements
mov ecx, SIZEOF personName ;Number of characters to move
rep movsb
;Input data into array
ArrayWork: ;label that has the 20 strings for array
inc CounterOne ;increments counter
cmp CounterOne, 20 ;checks if counter is less than or equal to 20
jbe ArrayOut ;once 20 names & grades entered, display them
;Output of table being calculated
ArrayOut:
call clrscr
mov esi,0
mov row, 3
ArrayLoop:
mov dh, row
mov dl, 5 ;assigns name in column 5
call Gotoxy ;locate cursor
mov eax, SIZEOF NAMEGRADE
mul CounterTwo
mov esi, eax
lea edx, (MyTable[esi]).personName
;cmp edx, 0 ;No name then exit
;je ProgramEnds
call WriteString ;Displays the student's name
;Table output must be set & looped
inc CounterTwo
inc row
mov al, CounterOne
cmp CounterTwo, al
jne ArrayLoop
;The WaitMsg part
Waiting:
mov dh,24 ;or use row instead of 24
mov dl,1
call Gotoxy
mov eax, white + (black * 16) ;sets the color to WaitMsg
call SetTextColor
call WaitMsg ;displays Press any key to continue
call Clrscr
jmp Startover ;Jumps to restart the program after successful output
ProgramEnds: ;Program must exit if no name entered
exit
main ENDP
END main ;end of program
如果没有输入名称,我希望输出只是“按任意键继续”。使用Visual Studio 2017编译 调试如下:
Press any key to continue...
ABCDEF CDEF
x offset
ffset ------------
----------
EAX= =
ESI= =
EIP=
ZF=
verflow>
rflow>
â sK'MtM&HìH(PæP!IäI"QvQ$GwG#OuO-RÆR.SôSkNÉNmJÄJzààà{ååå╜é╗
â 'MtM&HìH(PæP!IäI"QvQ$GwG#OuuO-RÆR.SôSkNÉNmJÄJzààà{ååå╜é╗
â -RÆR.SôSkNÉNmJÄJzààà{ååå╜é╗
â ╗ continue...
ntinue...
ame
e
(saved ebp) <--- ebp ed register)
register) e)
sp
lid
d
按任意键继续后,垃圾是什么?