Ввод должен прекратиться после запроса 20 имен и оценок или когда пользователь нажимает «Enter» без ввода - PullRequest
0 голосов
/ 18 мая 2019

Программа написана на ассемблере [MASM] и основана на Глава 5 из Ирвин, Кип.Язык ассемблера для процессоров x86, седьмое издание.Образование Пирсона, 2015 .Инструкция cmp & je для имени не работает, когда я пытаюсь ввести имя без приглашения.При нажатии на кнопку ввода отображается «Нажмите любую клавишу для продолжения», а также под ней несколько нежелательных элементов.

    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

Что за мусор после Нажмите любую клавишу для продолжения?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...