Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

Ich habe ein (kleineres) Problemchen:

Ich möchte einen Compiler basteln, welcher mir zunächst in einer Schleife die einzelnen Zeilen die "remarked" Inhalte herausschneiden soll.

Das Ganze soll ein Assembler werden.

Das "Remark" Zeichen ist also in diesem Fall das Semikolon ;

Nun versuche ich also, jede Zeile um den Text hinter diesem Semikolon herauszuschneiden. (Inkl. dem Semikolon natürlich)

Mein "Versuch" scheitert leider noch:

        for (int p = 0; p < line; p++){

            for (int i = 0; i < compiledLine[p].length(); i++){

                if (compiledLine[p].charAt(i) == 0x03B){

                    compiledLine[p] = compiledLine[p].substring(compiledLine[p].length()-i,compiledLine[p].length());

                    break;

                }

            }

        }
Was mache ich hier falsch? Beispiel: disass.png Dieses soll mein Assembler werden. Die gewünschte Ausgabe in den Compiler soll nun also wie folgt aussehen:
                




                ORG     &4000


                LD      DE,&1111                

                LD      DE,&1111                

                LD      DE,&1111                

                LD      DE,&0001                

  • Autor

Ja, Du hast Recht!

Wieso habe ich nicht gleich dran gedacht? *andiestirnpatsch*

So "zerstückel" ich nun meinen Code:

        for (int p = 0; p < line; p++) {

            compiledLine[p] = removeSpaces(compiledLine[p]);

            for (int i = 0; i < compiledLine[p].length(); i++) {

                if (compiledLine[p].charAt(i) == 0x03B) {

                    compiledLine[p] = compiledLine[p].substring(0, compiledLine[p].indexOf(";"));

                    break;

                }

            }

        }


        for (int p = 0; p < line; p++) {

            System.out.println("# " + compiledLine[p]);

        }
(Der letzte Loop ist nur zum Test. Das muss noch gegen den eigentlichen Compiler getauscht werden) Ausgabe:
# 

# 

# 

# 

# ORG &4000 

# 

# LD DE,&1111 

# LD DE,&1111 

# LD DE,&1111 

# LD DE,&0001 

.....

Denk mal über Deine For-Schleife mit charAt nach !

Returns the index within this string of the first occurrence of the specified character. If a character with value ch occurs in the character sequence represented by this String object, then the index of the first such occurrence is returned -- that is, the smallest value k such that:

this.charAt(k) == ch

is true. If no such character occurs in this string, then -1 is returned.

  • Autor

Habe es nun so:

        for (int p = 0; p < line; p++) {

            compiledLine[p] = removeSpaces(compiledLine[p]);

            int check = compiledLine[p].indexOf(";");

            if (check != -1)

                compiledLine[p] = compiledLine[p].substring(0, check);

        }

Ergebnis:

http://cpc-live.com/disass2.png

Man kann hier nun im unteren Fenster sehen, welcher Code an den eigentlichen Kompiler gesendet wird.

(Alle überflüssigen SPACE entfernt, ';' Remarks entfernt, Upper-Case usw...)

Bearbeitet von Devilmarkus

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.