Making "Good" Assembly Code

You can talk about almost anything that you want to on this board.

Moderator: Moderators

User avatar
pubby
Posts: 554
Joined: Thu Mar 31, 2016 11:15 am

Re: Making "Beautiful" Assembly Code

Post by pubby » Thu Jul 23, 2020 7:20 pm

I can't tell if you guys are joking, but XOR is pronounced "ex or" becuase it an abbreviation of EXclusive OR. Maybe the hamburgers, bikinis, and gun rights are getting to my head but I think it's a reasonable name.

rox_midge
Posts: 89
Joined: Mon Sep 19, 2005 11:51 am

Re: Making "Beautiful" Assembly Code

Post by rox_midge » Thu Jul 23, 2020 7:43 pm

pubby wrote:
Thu Jul 23, 2020 7:20 pm
I can't tell if you guys are joking, but XOR is pronounced "ex or"...
I always pronounced it "zor", like the first phoneme in "xylophone", because one syllable is easier than two.

lidnariq
Posts: 9510
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Making "Beautiful" Assembly Code

Post by lidnariq » Thu Jul 23, 2020 7:54 pm

I pronounce that "X" as "sh", so that I can be deliberately confusing about Shor.

(No I don't actually.)

Garth
Posts: 184
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: Making "Beautiful" Assembly Code

Post by Garth » Thu Jul 23, 2020 8:08 pm

It's weird but PUSH and POP seems to be the standard terms for stacks nowadays, despite PULL being the clear opposite of PUSH.
"Pop" suggests a small explosion, something rupturing instantly and sending a high-pressure wave through the air.
Pushing and pulling (and "popping" whatever that means) sounds like you are trying to push in or out something from the bottom or the middle of the stack, which is illegal according to the LIFO stack rules, and counter-intuitive to the whole stack metaphor.
Think of it as pushing new paper napkins into one of these spring-loaded dispensers in a restaurant, and then taking one out, always at the end.
Image
(except they often pack them in so tight that you can't get one out without tearing it!)
As for XOR, how do you even pronounce that?
I always say, "ecks-or."
In terms of making nice assembly code, there are some things:
  • You can use macros for many purposes (although I tend to avoid it when it makes the code inefficient).
Macros should very seldom be any less efficient than what you would do by hand. They should take the input parameters and lay down the same code you would do by hand, just without making you deal with the ugly internals every time.
http://WilsonMinesCo.com/ lots of 6502 resources

User avatar
nicklausw
Posts: 376
Joined: Sat Jan 03, 2015 5:58 pm
Location: ...
Contact:

Re: Making "Beautiful" Assembly Code

Post by nicklausw » Thu Jul 23, 2020 8:10 pm

Let's end the abbreviation wars once and for all with Verbose-Assembler: the vastly verbose assembler for the fully foreseeable future.

Code: Select all

Load accumulator with hexadecimal number 12. Store accumulator into zero page address hexadecimal number A2.
Supports every word you'd need, along with every synonym for each of those words listed in the thesaurus!

User avatar
aa-dav
Posts: 92
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: Making "Beautiful" Assembly Code

Post by aa-dav » Thu Jul 23, 2020 8:15 pm

In russian language letter X of international words is transliterated as 'ks'. So, XOR is without quesions 'ksor' among russian programmers. And xenomorphs are 'ksenomorphs' and so on and sometimes it's a little bit confusing like in names (Xena for example).

93143
Posts: 1197
Joined: Fri Jul 04, 2014 9:31 pm

Re: Making "Beautiful" Assembly Code

Post by 93143 » Thu Jul 23, 2020 10:14 pm

syntax_error.png
syntax_error.png (34.73 KiB) Viewed 758 times

Oziphantom
Posts: 861
Joined: Tue Feb 07, 2017 2:03 am

Re: Making "Beautiful" Assembly Code

Post by Oziphantom » Thu Jul 23, 2020 11:49 pm

Its Ehor see https://www.youtube.com/watch?v=cqQJtUbkAj4 note the E sound at the start. eh-OR

I think it does come down to metaphors. Of which I have mostly seen 2
1.) Train carriages. So you have a stack of trains carriages. A train will push 2 more carriages into the holding area. Then another train will come and pull 3 carriages out. Thus each carriage leaves in the reverse order it was pushed in.
2.) Stack of plates. So you have a plate stack and you place plates on top, then "pop" them off the top and hence they leave in the reverse order they were added. However this is also badly American as you "take" them off the top. So you have Place and Take.
The Stack of plates only works for the FILO buffer, while the FIFO buffer, the train works fine because you can have a train pick up from the front of the stack as well.

Macros do breed inefficiency

Code: Select all

MOV #0, $d020
MOV #0, $d021
looks good but expands to

Code: Select all

lda #0
sta $d020
lda #0
sta $d020
but then doing

Code: Select all

MOV #0, $d020
sta $d021
looks funny and is asking for bugs. As you will group similar things together, so one day you might do

Code: Select all

MOV #0, $d020
MOV #4, $d015
sta $d021
without thinking.

Then you have the

Code: Select all

MOV #0,$d020
MOV #0,$d021
MOV #2,$d022
MOV #1,$d023
MOV #10,$d024
type cases, here all seems well but if you actually write out the code the optimal way is to do

Code: Select all

ldx #0
stx $d020
stx $d021
inx
stx $d023
inx
stx $d022
lda #10
sta $d024
This is why I made MLA to sort and optimise these problems for me.

Garth
Posts: 184
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: Making "Beautiful" Assembly Code

Post by Garth » Fri Jul 24, 2020 12:20 am

Oziphantom wrote:
Thu Jul 23, 2020 11:49 pm
Macros do breed inefficiency

Code: Select all

MOV #0, $d020
MOV #0, $d021
If your assembler's macro capabilities allow varying numbers of parameters, you could say something like

Code: Select all

        PUT  0, in, $D020, and, $D021
and it would give you an LDA #0 and follow it with two STA's. Or better, since they're consecutive addresses, you can use a PUT2 macro and say

Code: Select all

        PUT2  0, in $D020
(where PUT2 understands the first parameter to be a 16-bit number) and have the macro check to see if the high byte and low byte are the same, and if so, not LDA# it again. Since I'm always using the 65c02, I have the macro watch for the 0, and if the parameter is a 0, omit the LDA and just do STZ (STore Zero). If A were not available but Y were available, you could have the optional parameter "using_Y" so it will assemble LDY# and STY.

Again, you can do loads of conditional assembly in macros; and then what they'll do automatically may be an optimization you'd forget to do if you were to write it all out by hand, or they may propagate a change you make elsewhere even if you forget to come back and improve the code here. But just because you don't have to look at the ugly internal details every time does not mean you don't need to know what they do.
http://WilsonMinesCo.com/ lots of 6502 resources

calima
Posts: 1160
Joined: Tue Oct 06, 2015 10:16 am

Re: Making "Beautiful" Assembly Code

Post by calima » Fri Jul 24, 2020 1:14 am

Push and pop made sense to me, thinking about the Pez candy dispensers. To add candy you push them down and taking candy you pop.

Pokun
Posts: 1492
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Making "Beautiful" Assembly Code

Post by Pokun » Fri Jul 24, 2020 2:50 pm

The tissue-dispenser, train and Pez metaphors makes sense. By stack I'm thinking of a pile of stuff stacked on top of each other vertically and held together with gravity, since that's what the Swedish word would mean (or actually it has a meaning closer to heap or haystack). But this changes everything. Pop is still kind of out of the blue though, and only works well with weird variants like Pez.

Swedish also always pronounces X as [ks] like in Greek, and never as [z] which doesn't even exists (the Z letter has the same sound as S), and I think a lot of Swedish people says "ksor" or possibly even "eksor" like Pubby said. Xylophone is said as ksylofon (spelled xylofon) and for some reason it doesn't sound as awkward as "ksor" does. Maybe it's just about getting used to it.

Xanadu is also pronounced as Ksanadu (especially in Faxanadu where it isn't awkward to say), but that's probably more due to not being aware of how to read it. Besides, it's pronounced Zanadu in Japanese although the Chinese pronunciation should be something like [sh] (Shàngdū in pinyin).

User avatar
Dwedit
Posts: 4333
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Making "Beautiful" Assembly Code

Post by Dwedit » Fri Jul 24, 2020 5:58 pm

Sometimes I get the idea that the word "Beautiful" appearing in the subject is attracting spambots.

Edit: I am convinced that this thread title is the sole reason why there is a sudden influx of porn spam links.
Last edited by Dwedit on Fri Jul 24, 2020 8:36 pm, edited 1 time in total.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

User avatar
aa-dav
Posts: 92
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: Making "Beautiful" Assembly Code

Post by aa-dav » Fri Jul 24, 2020 8:11 pm

I've read etimology and oxford dictionaries yesterday and got impression that 'pop' for native english-speaking people is mentally connected to it's first meaning 'make a light explosive sound'. That is it's highly suitable for processes where something cracks/quickly moves in/out with sound/clicks/clacks and so on. For example 'to pop pimple' is ideal application.
And because of this another guess appeared: maybe creator of these terms was inspired by military process: loading and unloading of automatic rifle magazine. It definitely clicks in any direction. And such corporations like IBM was connected to army from start, so...

User avatar
nicklausw
Posts: 376
Joined: Sat Jan 03, 2015 5:58 pm
Location: ...
Contact:

Re: Making "Beautiful" Assembly Code

Post by nicklausw » Fri Jul 24, 2020 9:09 pm

Dwedit wrote:
Fri Jul 24, 2020 5:58 pm
Sometimes I get the idea that the word "Beautiful" appearing in the subject is attracting spambots.

Edit: I am convinced that this thread title is the sole reason why there is a sudden influx of porn spam links.
Fixed to something less suggestive.

93143
Posts: 1197
Joined: Fri Jul 04, 2014 9:31 pm

Re: Making "Good" Assembly Code

Post by 93143 » Sat Jul 25, 2020 2:27 pm

Was my joke too subtle? I thought it was funny...

Post Reply