Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Sidetracking from 'Tabs vs. Spaces': Do you indent assembly code?

Sidetracking from 'Tabs vs. Spaces': Do you indent assembly code?

Scheduled Pinned Locked Moved The Lounge
visual-studioquestion
31 Posts 15 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

    OP was talking about if- and for-like structures... The only indentation here is labels vs code...

    "Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid." ― Albert Einstein

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #22

    I see no such specification.

    T 1 Reply Last reply
    0
    • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

      No. It mostly impossible to indent in the way we do in C-like languages, because the way assembly flow works... Like in this code... No indentation makes sense here... However I use blank lines to break the code...

      raster_irq: {
      lda flag
      and #popup_on
      bne bottom // popup is active

      lda $d012
      cmp #raster\_irq\_bottom\_line
      bcc top
      

      bottom:
      lda #charset2 // set secondary charset (for bottom half of the screen)
      sta $d018

      lda #raster\_irq\_top\_line
      sta $d012
      
      jmp end
      

      top:
      lda #charset1 // set primary charset (for top half of the screen)
      sta $d018

      lda #raster\_irq\_bottom\_line
      sta $d012
      

      end:
      asl $d019 // clear pending
      jmp $ea31 // finish interrupt
      }

      "Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid." ― Albert Einstein

      T Offline
      T Offline
      trønderen
      wrote on last edited by
      #23

      Kornfeld Eliyahu Peter wrote:

      because the way assembly flow works...

      No, I see no reason whatsoever why assembly flow works differently from flow in 'structured languages'. The advantages of while- and for-loops, function definitions, if/else, switch etc. lies not in the source language keywords, but in the structured nature of your solution, which is independent of implementation language. That includes assembler. In my student days, at a Tech University, some of the "hard engineering" departments stubbornly insisted that Fortran was The Only One Language for true engineers. This included the need for arbitrary GO TO jumps. E.g. indenting loops was meaningless, because a jump might break that loop structure. One of the professors wrote an article in the University newsletter were he fiercely attacked and ridiculed this silly idea of the Pascal programmers of moving code back and forth, right and left. That would only confuse the reader of the code, if code flow diverted from the indentation. I don't think I have ever programmed a goto in a block structured language; it has never appeared to provide any advantage whatsoever. I am thinking in terms of structured constructs even when programming in assembler. When I hear people arguing that assembler code "must" do it differently, my instinctive reaction is "So you want to program with GOTOs? What for??" It messes up program structure, makes maintenance more difficult, is error prone ... I, of course, use both conditional and unconditional when assembler coding. Some people reply: "Exactly! Look at yourself: A jump instruction is the same as a GOTO!" But no; I use the jumps in a structured way, the same way that a Pascal or C compiler would generate them, such as jumping back to the top of the loop for another iteration, jump past the loop when the termination condition is satisfied, or skipping over the if clause when the condition is false, or at the end of the if clause, skip over the else clause. Jumps are frequently required at block starts (opening brace, BEGIN in Pascal) and block ends (closing brace, END in Pascal), but never in the middle of a linear sequence. Short version: I strongly disagree that assembly program code flow differs from structured high level programming code flow. It is technically possible, as is goto-programming in Pascal or C, but you simply do not program that way,

      Kornfeld Eliyahu PeterK 1 Reply Last reply
      0
      • P PIEBALDconsult

        I see no such specification.

        T Offline
        T Offline
        trønderen
        wrote on last edited by
        #24

        Are you saying that you didn't see "do you assembler coders indent loop bodies, if-bodies / else-bodies etc. when you program such constructs in assembler?" If you didn't see that, there is nothing more I can do for you.

        1 Reply Last reply
        0
        • J jsc42

          OriginalGriff wrote:

          column zero starts were a label, column 7 started an opcode, column 15 was a parameter.

          Sounds like PLAN (ICL 1900 Assembler) which I spent several years writing. Col 1 = label, col 7 = op code, 13 = accumulator(s), 17 = operand, 36 = comment, 73 to 80 = sequence number The sequence numbers were vital. It was the only way of reconstructing a source program if you (or, more commonly, the computer operator) accidentally dropped the deck of cards and you (always the programmer) had to re-order them back into their original sequence.

          T Offline
          T Offline
          trønderen
          wrote on last edited by
          #25

          jsc42 wrote:

          if you (or, more commonly, the computer operator) accidentally dropped the deck of cards and you (always the programmer) had to re-order them back into their original sequence.

          That was the purpose of the sequence number. If you had punched the card deck with sequence number in col 73-80, on the Univac mainframes running Exec-8 (later renamed OS-1100), you could read in the cards in any order; the machine would sort them according to the sequence number. That was of course no viable (although theoretically possible!) option if all cards were punched manually on a 026 card punch. I never saw anyone punching sequence numbers manually.

          1 Reply Last reply
          0
          • T TNCaver

            OriginalGriff wrote:

            spaghetti code is a "feature" of much assembly code

            Yep. See my signature line. :-D

            If you think 'goto' is evil, try writing an Assembly program without JMP.

            T Offline
            T Offline
            trønderen
            wrote on last edited by
            #26

            Of course you need JMP in assembler! You need it to skip that else clause, or return to the top of the loop. You just use it at the boundaries of logical code blocks, to implement the same semantics as the opening and closing braces of the equivalent C program.

            1 Reply Last reply
            0
            • T TNCaver

              The FORTRAN I used back in the day had everything in specific columns. So yeah, no indentions.

              If you think 'goto' is evil, try writing an Assembly program without JMP.

              T Offline
              T Offline
              trønderen
              wrote on last edited by
              #27

              Lots of Fortran programmers never knew: In cols 7 to 72, all spaces were insignificant. You could write GOTO or GO TO, COMM ON and SUB ROUTINE. Furthermore, no tokens were reserved. You could name a SUBROUTINE FUNCTION or SUBROUTINE, to be called as "CALL FUNCTION(x)" or "CALL SUBROUTINE(y)". You could have a REAL variable named INTGEGER or REAL, and write statements such as "IF INTEGER.L T.REAL GOT 0123" The last Fortran I touched was a Fortran77 implementation. During the design discussions for Fortran77, with each proposed extension crazier than the other, one of the old gurus (Dijkstra?) remarked that "I do not know what programming languages will look like in year 2000, but they will be named Fortran!" When I stumbled across Fortran 2011, my immediate reaction was: "You were just so right, old Master!" I guess that Fortran of today both have significant spaces and reserved words. But I wouldn't be sure of it without checking the language specification. :-)

              G T 2 Replies Last reply
              0
              • T trønderen

                In the 'Surveys' section, there has been some assembler talk the last couple of days. It seems like we have fair share of developers not afraid of getting their fingers oily :-) I am curious: After more than 40 years of 'structured programming', do you assembler coders indent loop bodies, if-bodies / else-bodies etc. when you program such constructs in assembler? Or do you follow the tradition from 50 years ago, with every instruction/statement left justified?

                G Offline
                G Offline
                Gary R Wheeler
                wrote on last edited by
                #28

                Hmm. My last significant bit of assembly language was an OS/2 device driver written in Intel assembly language, flat memory model (yay!). There were a few places in the driver that implemented algorithms I originally (pseudo)coded in C. Those places tended to use indentation that resembled the original C. Indentation was not my practice throughout.

                Software Zen: delete this;

                1 Reply Last reply
                0
                • T trønderen

                  Lots of Fortran programmers never knew: In cols 7 to 72, all spaces were insignificant. You could write GOTO or GO TO, COMM ON and SUB ROUTINE. Furthermore, no tokens were reserved. You could name a SUBROUTINE FUNCTION or SUBROUTINE, to be called as "CALL FUNCTION(x)" or "CALL SUBROUTINE(y)". You could have a REAL variable named INTGEGER or REAL, and write statements such as "IF INTEGER.L T.REAL GOT 0123" The last Fortran I touched was a Fortran77 implementation. During the design discussions for Fortran77, with each proposed extension crazier than the other, one of the old gurus (Dijkstra?) remarked that "I do not know what programming languages will look like in year 2000, but they will be named Fortran!" When I stumbled across Fortran 2011, my immediate reaction was: "You were just so right, old Master!" I guess that Fortran of today both have significant spaces and reserved words. But I wouldn't be sure of it without checking the language specification. :-)

                  G Offline
                  G Offline
                  Gary R Wheeler
                  wrote on last edited by
                  #29

                  trønderen wrote:

                  no tokens were reserved. You could name a SUBROUTINE FUNCTION or SUBROUTINE, to be called as "CALL FUNCTION(x)" or "CALL SUBROUTINE(y)". You could have a REAL variable named INTGEGER or REAL, and write statements such as "IF INTEGER.L T.REAL GOT 0123"

                  Oh barf.

                  Software Zen: delete this;

                  1 Reply Last reply
                  0
                  • T trønderen

                    Kornfeld Eliyahu Peter wrote:

                    because the way assembly flow works...

                    No, I see no reason whatsoever why assembly flow works differently from flow in 'structured languages'. The advantages of while- and for-loops, function definitions, if/else, switch etc. lies not in the source language keywords, but in the structured nature of your solution, which is independent of implementation language. That includes assembler. In my student days, at a Tech University, some of the "hard engineering" departments stubbornly insisted that Fortran was The Only One Language for true engineers. This included the need for arbitrary GO TO jumps. E.g. indenting loops was meaningless, because a jump might break that loop structure. One of the professors wrote an article in the University newsletter were he fiercely attacked and ridiculed this silly idea of the Pascal programmers of moving code back and forth, right and left. That would only confuse the reader of the code, if code flow diverted from the indentation. I don't think I have ever programmed a goto in a block structured language; it has never appeared to provide any advantage whatsoever. I am thinking in terms of structured constructs even when programming in assembler. When I hear people arguing that assembler code "must" do it differently, my instinctive reaction is "So you want to program with GOTOs? What for??" It messes up program structure, makes maintenance more difficult, is error prone ... I, of course, use both conditional and unconditional when assembler coding. Some people reply: "Exactly! Look at yourself: A jump instruction is the same as a GOTO!" But no; I use the jumps in a structured way, the same way that a Pascal or C compiler would generate them, such as jumping back to the top of the loop for another iteration, jump past the loop when the termination condition is satisfied, or skipping over the if clause when the condition is false, or at the end of the if clause, skip over the else clause. Jumps are frequently required at block starts (opening brace, BEGIN in Pascal) and block ends (closing brace, END in Pascal), but never in the middle of a linear sequence. Short version: I strongly disagree that assembly program code flow differs from structured high level programming code flow. It is technically possible, as is goto-programming in Pascal or C, but you simply do not program that way,

                    Kornfeld Eliyahu PeterK Offline
                    Kornfeld Eliyahu PeterK Offline
                    Kornfeld Eliyahu Peter
                    wrote on last edited by
                    #30

                    I mostly agree with your view - JMP is not a GOTO equivalent, but most cases (in logically structured code) is the closing bracket of a block... However - in assembly indentation just makes less readable IMHO... Taking the same code sample, indentation makes it worst...

                    // if
                    lda $d012
                    cmp #raster_irq_bottom_line
                    bcc top

                    // true branch
                    bottom:
                    lda #charset2 // set secondary charset (for bottom half of the screen)
                    sta $d018

                    	lda #raster\_irq\_top\_line
                    	sta $d012
                    
                    jmp end
                    

                    // false branch
                    top:
                    lda #charset1 // set primary charset (for top half of the screen)
                    sta $d018

                    	lda #raster\_irq\_bottom\_line
                    	sta $d012
                    

                    // end if
                    end:

                    "Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid." ― Albert Einstein

                    "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

                    1 Reply Last reply
                    0
                    • T trønderen

                      Lots of Fortran programmers never knew: In cols 7 to 72, all spaces were insignificant. You could write GOTO or GO TO, COMM ON and SUB ROUTINE. Furthermore, no tokens were reserved. You could name a SUBROUTINE FUNCTION or SUBROUTINE, to be called as "CALL FUNCTION(x)" or "CALL SUBROUTINE(y)". You could have a REAL variable named INTGEGER or REAL, and write statements such as "IF INTEGER.L T.REAL GOT 0123" The last Fortran I touched was a Fortran77 implementation. During the design discussions for Fortran77, with each proposed extension crazier than the other, one of the old gurus (Dijkstra?) remarked that "I do not know what programming languages will look like in year 2000, but they will be named Fortran!" When I stumbled across Fortran 2011, my immediate reaction was: "You were just so right, old Master!" I guess that Fortran of today both have significant spaces and reserved words. But I wouldn't be sure of it without checking the language specification. :-)

                      T Offline
                      T Offline
                      TNCaver
                      wrote on last edited by
                      #31

                      I also used Fortran77 in tech school. You're right, I don't recall them saying anything about spaces being ignored in those columns. One of my cousins created (or co-created, I don't remember) PDE2D using Fortran. The latest Windows version uses v11, and the Linux and Mac version use various flavors of GNU GFortran.

                      If you think 'goto' is evil, try writing an Assembly program without JMP.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups