2016-06-10 6 views
1

Ich bin neu in Assembler-Programmierung und brauchen Verständnis helfen und einige Code Festsetzung ich mit gekämpft haben: Ich möchte Eingangs Benutzer zur Verfügung zu stellen:Assembly Language: Zweiaufforderung Benutzereingabe (Mischungs char und int)

Prompt 1: Ziel eingeben Wert lesen Prompt 2: Ziel eingeben Wert lesen Anzeige Entfernung und Ziel.

Ich verwende VS2012 mit Irvine32-Bibliotheken auf einer x64-Hardware. Ich kompiliere als x32.

Das Problem Der Code kompiliert und erstellt. Aber die Ausgabe ist nicht korrekt. Die erste Eingabeaufforderung wird nur ohne Eingabe angezeigt. Die zweite Aufforderung "Distance" wird mit dem erlaubten Eintrag angezeigt. Wenn ich die erste Aufforderung ändere, eine "readInt" anstelle von "readString" zu haben, bekomme ich Aufforderungen in beiden, aber ich würde "Ungültige Integer" -Fehler bekommen. Warum ist das? Wie behebe ich das und zeige auch die Eingabewerte an.

Mein Code

INCLUDE irvine32.inc 

;*************************************************************************  
.data 
    queryDest byte "Destination", 0 
    queryDist byte "Distance", 0 

    destination  dword ? 
    distance  dword ? 

.code 
main proc 
     call clrscr 

     mov edx, offset queryDest 
     call writeString 
     call readString 
     mov destination, eax 

     call crlf 
     mov edx, offset queryDist 
     call writeString 
     call readInt 
     mov distance, eax 

     call crlf 
     Call WaitMsg  ;causes a wait for a key to be pressed 
     exit 
main endp 
end main 

Stromausgang

Destination

Distance50

Drücken Sie eine beliebige Taste, um fortzufahren ...

+0

@ JoseManuelAbarcaRodríguez Ich bin neu in Aseembly. Ich versuche zu verstehen, was Sie vorschlagen. – Sylvester

Antwort

0

Nicht getestet, weil mein VS 2012 nicht funktioniert (arbeitet daran). Ihr Hauptproblem ist, dass destination muss ein String sein, nicht eine Zahl:

INCLUDE irvine32.inc 

;*************************************************************************  
.data 
    queryDest byte "Destination=", 0 
    queryDist byte "Distance=", 0 

    destination byte "      " ; LENGTH 21. 
    distance dword ? 

.code 
main proc 
     call clrscr 
;READ DESTINATION.  
     mov edx, offset queryDest 
     call writeString    ;DISPLAY MESSAGE. 

     mov edx, offset destination ;STORE STRING HERE (ZERO TERMINATED). 
     mov ecx, 20     ;MAX CHARS TO READ. 
     call readString    ;STORES STRING WHERE EDX POINTS. 

     call crlf 
;READ DISTANCE. 
     mov edx, offset queryDist 
     call writeString    ;DISPLAY MESSAGE. 
     call readInt 
     mov distance, eax 

;DISPLAY DESTINATION AND DISTANCE. 
     call crlf 
     call crlf 
     mov edx, offset destination ;EDX POINTS TO STRING TO DISPLAY. 
     call writeString    ;DISPLAY DESTINATION. 
     call crlf 
     mov eax, distance    ;NUMBER TO DISPLAY. 
     call writeInt     ;DISPLAY DISTANCE. 

     call crlf 
     Call WaitMsg  ;causes a wait for a key to be pressed 
     exit 
main endp 
end main 

Bibliography

+0

Es klagt über "Fehler A2084: konstanter Wert zu groß" auf "Zielbyte" "// LÄNGE 21." – Sylvester

+0

Am hilfreichsten. Danke @jose – Sylvester

+0

@Sylvester, Entschuldigung, ich habe an PHP gearbeitet, wo Kommentare sind '//' (oops!). –