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 5 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.
  • 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?

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #6

    I'm not using assembler much these days.

    trønderen wrote:

    Or do you follow the tradition from 50 years ago, with every instruction/statement left justified?

    But in the "old" days most assembler projects I worked on was exactly the opposite with each and every line indented and only the jump labels left justified.

    1 Reply 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?

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

      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

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

      P 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?

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #8

        No. Probably because the early assemblers I learned on didn't support it: column zero starts were a label, column 7 started an opcode, column 15 was a parameter. And also because it wouldn't have worked in most cases: spaghetti code is a "feature" of much assembly code (since you are trying to cram as much function into as little ROM space or processing time as possible) and you can't indent that in a meaningful way.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        J 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?

          W Offline
          W Offline
          Wizard of Sleeves
          wrote on last edited by
          #9

          Anyone who indents assembly code will be burned at the stake for such heresy.

          Nothing succeeds like a budgie without teeth. To err is human, to arr is pirate.

          D 1 Reply 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?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #10

            Labels start in column 1, instructions in column 11, operands in column 21, and comments in column 41 (although the semi-colon should be in column 39).

            1 Reply 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?

              D Offline
              D Offline
              den2k88
              wrote on last edited by
              #11

              YES. I indent everything, even my notes. But I did backport an habit from assembly: I align operators and operands on consecutive lines. Example

              longFunctionName(arg1, argument2);
              shortFunction (argument1, arg2 );

              Not only it makes it easier for me to parse the code but it's a boon when used with column editing. All the coworkers who have worked on my code appreciate it too.

              GCS/GE d--(d) s-/+ a C+++ U+++ P-- L+@ E-- W+++ N+ o+ K- w+++ O? M-- V? PS+ PE Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

              1 Reply Last reply
              0
              • W Wizard of Sleeves

                Anyone who indents assembly code will be burned at the stake for such heresy.

                Nothing succeeds like a budgie without teeth. To err is human, to arr is pirate.

                D Offline
                D Offline
                den2k88
                wrote on last edited by
                #12

                Considering gas prices (1.7€ / scm), collecting stakes to be burned is a solution.

                GCS/GE d--(d) s-/+ a C+++ U+++ P-- L+@ E-- W+++ N+ o+ K- w+++ O? M-- V? PS+ PE Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  No. Probably because the early assemblers I learned on didn't support it: column zero starts were a label, column 7 started an opcode, column 15 was a parameter. And also because it wouldn't have worked in most cases: spaghetti code is a "feature" of much assembly code (since you are trying to cram as much function into as little ROM space or processing time as possible) and you can't indent that in a meaningful way.

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                  J Offline
                  J Offline
                  jsc42
                  wrote on last edited by
                  #13

                  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.

                  OriginalGriffO T 2 Replies 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.

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #14

                    Oh gawd yes - dropped desk were a PITA. And you had to remember to leave gaps in teh sequence numbering so you could add code later ...

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    1 Reply 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?

                      F Offline
                      F Offline
                      Forogar
                      wrote on last edited by
                      #15

                      No, of course not. Assembler was supposed to be hard to read, nothing should make it easier! I also didn't indent FORTRAN - but then it didn't lend itself to that.

                      - I would love to change the world, but they won’t give me the source code.

                      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

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

                        Looks indented to me.

                        Kornfeld Eliyahu PeterK 1 Reply 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?

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

                          The last time I wrote assembly code was on an XT box (8088 processor) using edlin. I barely remember what I ate for dinner yesterday, much less code from 40 years ago. I do remember loving to code that close to the hardware. And thanks for reminding me that I'm old as dirt. :laugh:

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

                          1 Reply Last reply
                          0
                          • F Forogar

                            No, of course not. Assembler was supposed to be hard to read, nothing should make it easier! I also didn't indent FORTRAN - but then it didn't lend itself to that.

                            - I would love to change the world, but they won’t give me the source code.

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

                            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 1 Reply Last reply
                            0
                            • OriginalGriffO OriginalGriff

                              No. Probably because the early assemblers I learned on didn't support it: column zero starts were a label, column 7 started an opcode, column 15 was a parameter. And also because it wouldn't have worked in most cases: spaghetti code is a "feature" of much assembly code (since you are trying to cram as much function into as little ROM space or processing time as possible) and you can't indent that in a meaningful way.

                              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

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

                              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 1 Reply 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?

                                J Offline
                                J Offline
                                jeron1
                                wrote on last edited by
                                #20

                                Never, always been a tab then the op code. Labels start in the first column.

                                "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                                1 Reply Last reply
                                0
                                • P PIEBALDconsult

                                  Looks indented to me.

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

                                  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

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

                                  P 1 Reply Last reply
                                  0
                                  • 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
                                          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