Making "Good" Assembly Code

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

Moderator: Moderators

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

Re: Making "Good" Assembly Code

Post by 93143 » Wed Jul 29, 2020 4:55 pm

MOV sucks. It contains no implications about which parameter is the source and which the destination, and different processors use different conventions.

I believe the obvious way to do it is MOV src, dest - unfortunately either Intel or Motorola (can't be bothered trying to remember which one) didn't think so, and now we're hosed...

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

Re: Making "Good" Assembly Code

Post by lidnariq » Wed Jul 29, 2020 6:28 pm

Both Motorola and Intel.

Only GNU/AT&T/MIT syntax seems to think src,dest makes sense :p

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

Re: Making "Good" Assembly Code

Post by Pokun » Thu Jul 30, 2020 5:55 am

I'm not sure why one would make more sense than the other. If simply basing it on English grammar it's just a matter of using the right preposition particles "from" and "to". The word order does not decide on its own what is source and what is destination in English.
Thus the following two sentences has identical meanings:

Move from carriage to storage.
Move to storage from carriage.



lidnariq wrote:
Wed Jul 29, 2020 11:13 am
<off-topic> Words that were borrowed directly from Greek into English usually pronounce an initial X as Z, such as xylophone, xeroscape, and xenon. "Xavier" should probably be "Shave-ee-er" but English just loves stealing words from other languages and pronouncing them differently.
Kind of strange because I thought that the Greek X is always pronounced like [ks] in classic Greek. But I guess [ks] sounds awkward to start a word with since no English words do that.
Changing words to use sounds available in the language is probably very common in any language. And the sh-like sound for the Spanish J and X letters simply doesn't exists in English. The English [sh] sound would be a better approximation than [z] though.

Bananmos
Posts: 532
Joined: Wed Mar 09, 2005 9:08 am
Contact:

Re: Making "Good" Assembly Code

Post by Bananmos » Thu Jul 30, 2020 12:24 pm

93143 wrote:
Wed Jul 29, 2020 4:55 pm
MOV sucks. It contains no implications about which parameter is the source and which the destination, and different processors use different conventions.

I believe the obvious way to do it is MOV src, dest - unfortunately either Intel or Motorola (can't be bothered trying to remember which one) didn't think so, and now we're hosed...
I've always maintained that "MOV dst, src" as used by Intel CPUs makes a lot more sense and is more obvious, based on it being more logical for arithmetic operations.
* Subtractions are read in that order. i.e., "a - b" translates more naturally to "SUB a, b" in the human mind
* ...but then again, in a two operand CPU the subtraction is really "a -= b". Again, this looks close to "SUB a, b" than "SUB b, a"
* ...and same for "a += b" being closer to "ADD a, b"
* Minor point: It also happens to be the order of the C stdlib memcpy

So yeah, with a mindset of the CPU doing mostly additions and subtractions, "MOV dst, src" on Intel CPUs just happens to be consistent with what makes sense for arithmetic. Arm CPUs happens to use the same order as well (though instructions typically have 3 operands there).

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

Re: Making "Good" Assembly Code

Post by Pokun » Thu Jul 30, 2020 2:23 pm

That about a += b and a -= b is probably just an affect of the fact that the assignment operator used in high level languages usually have the destination = source type of syntax, and I believe that is taken from assembly rather than the other way around.

But the fact that SUB a, b translates well to math syntax a - b is a very good point I think.

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

Re: Making "Good" Assembly Code

Post by 93143 » Thu Jul 30, 2020 3:20 pm

lidnariq wrote:
Wed Jul 29, 2020 6:28 pm
Both Motorola and Intel.
Well, I've checked, and it seems 68000 MOVE operations are always src, dest. It's Intel that did it the other way around.
Pokun wrote:
Thu Jul 30, 2020 5:55 am
I'm not sure why one would make more sense than the other. If simply basing it on English grammar it's just a matter of using the right preposition particles "from" and "to". The word order does not decide on its own what is source and what is destination in English.
Thus the following two sentences has identical meanings:

Move from carriage to storage.
Move to storage from carriage.
The most obvious conversion is the one requiring the least number of extra words added to form a complete sentence. The first preposition is not necessary and therefore not implicit. This results in the most intuitive interpretation being "Move A to B", because the reverse ("Move A from B") is bad English.

This requires a slight conflation between "A" and "the contents of A", but that's routine in 65xx so...

Anyway, that's how my brain works, as a native English speaker.
Bananmos wrote:
Thu Jul 30, 2020 12:24 pm
* Subtractions are read in that order. i.e., "a - b" translates more naturally to "SUB a, b" in the human mind
No, that's orthogonal. Subtraction has conceptually nothing to do with copying data between locations, and the notational convention that "a - b" means "subtract B from A" has no obvious mapping to MOV[E] syntax.

Besides, if you stick "from" in between the operands in your example, they end up the wrong way around...

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

Re: Making "Good" Assembly Code

Post by Pokun » Thu Jul 30, 2020 3:45 pm

Good point. Move from A to B is a more common sentence pattern than Move to A from B anyway, and therefore probably feels more natural.
Math syntax is simply reverse from common English syntax in this case.

strat
Posts: 376
Joined: Mon Apr 07, 2008 6:08 pm
Location: Missouri

Re: Making "Good" Assembly Code

Post by strat » Thu Jul 30, 2020 6:23 pm

I prefer the Intel syntax (mov dst, src) because the first thing I see is the register to be modified. This issue basically doesn't exist in 6502 because you know from the operation if the reg or mem is affected, so at least that's on the leftmost part of the instruction.

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

Re: Making "Good" Assembly Code

Post by Oziphantom » Thu Jul 30, 2020 11:00 pm

Move from A to B is technically correct but not something you would say, Move A to B is all you would say or write. Japanese loves its particles, English doesn't ;)
Move to B from A is not a valid sentence. Take to B from A. Move is from the current location, Take is from another location.
You can say Move To B with out then specifying an A because Move means current location.

So you
Take 'a coffee' to work
Take a pamphlet from the stack
Move to 'the lounge room'
you don't
Move to work a coffee
Move a pamphlet to your pocket
Take to the lounge room

But if both objects are away from a person you then have
Move X from A to B
Where me move the topic to X and then establish where X is, once we have the frame of reference for the move we can then set the destination.

However computers are glorified calculators and maths is not English, its mostly French from Greek and Latin and Babylonian so A = X + Y we tend to write assignments as dest = src, to the engineers who made the CPU it's doing maths

mov AX,BX is really AX = 0 + BX
cmp AX,BX is really Flags = AX-BX
add AX,BX is really AX = AX + BX
etc

6502 is based on 6809 which uses the LD<register> form but in 6809 we combine the letters to make a single opcode
LDA #value
LDX #value
LDY #value
although the 68 also does
LDAA
LDAB so you can specify which accumulator you want

while Z80 separates it and lists them as the same opcode with different params
LD A,B
LD C,D
but as LD A,? will give a set of fixed values, i.e the A selection in the register will always be the same, you could just as easily say
LDA B/C/D/E/F and then list them as we do in 68/65

Then Motarola decided to change it for 68K I guess thinking that
MOVE BX, AX is more natural for left to right reading. Or it would make people accustomed to their way which is different to the other way, so programmers would find it hard to switch and hence form some lock-in and help stem of competition once they got a market. Knowing Motarola its probably a bit of both.

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

Re: Making "Good" Assembly Code

Post by Garth » Fri Jul 31, 2020 1:20 am

Oziphantom wrote:
Thu Jul 30, 2020 11:00 pm
Move from A to B is technically correct but not something you would say
"Move from A to B" is very normal in English. "Maths" however is not a word we use in the U.S.. (I think England uses it though.) In the U.S., it's always "math," like "dirt" or "air," never plural.
6502 is based on 6809 which uses the LD<register> form but in 6809 we combine the letters to make a single opcode
I expect you mean the 6800, not 6809. The 6809 came out three years after the 6502.
http://WilsonMinesCo.com/ lots of 6502 resources

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

Re: Making "Good" Assembly Code

Post by Oziphantom » Fri Jul 31, 2020 4:42 am

Yes 6800 not the 6809.

Move from A to B is not. Move {something} from A to B is. {something} moved from A to B is.

But you might have 'Move from A to B' as a response to another statement or problem as you have established the context already.

A : I hate this weather
B : Move from Seattle to Miami then

However
B : Move to Miami then
would be just as valid as the other person should know where they are. But in the case of you hearing it, typically in a movie or other story construct you insert the "from Seattle" to give the reader/viewer context and impart knowledge to them.

Math is not a word. It is again another odd americaninzation.
An abbreviation of a plural keeps the pluralization.
You lean Mathamatics in that it has multiple branches and fields. So you study Maths.
Only America says Math, in all other English speaking territories we use Maths.

I'm curious though, where do you take your showers to, and more importantly how do you transport them?

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

Re: Making "Good" Assembly Code

Post by Pokun » Fri Jul 31, 2020 4:02 pm

Ah, yes of course, even if the subject is implied, it still must be replaced by an "it" in English (and other Germanic languages). In programming languages the subject may be implied to be a copy of the content of the source though, and thus be left out.

The main exception to the a-subject-is-always-required-rule in English are clauses/sentences that uses an imperative verb, which is the case with "Move from Seattle to Miami then", I think. It doesn't have to be a response, it can be an order or anything else that uses an imperative verb.

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

Re: Making "Good" Assembly Code

Post by 93143 » Fri Jul 31, 2020 6:59 pm

Oziphantom wrote:
Thu Jul 30, 2020 11:00 pm
Move to B from A is not a valid sentence.
Yes it is. It's just not usual in most contexts. In the context of "moving" as in changing place of residence, it's just as normal as the other way around, probably because the destination is more important than the source in that context.
Math is not a word.
Canadian here; yes it is.

Probably because it's about 37 times easier to say...
I'm curious though, where do you take your showers to, and more importantly how do you transport them?
Ah. Now that would be telling...

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

Re: Making "Good" Assembly Code

Post by Oziphantom » Fri Jul 31, 2020 11:44 pm

93143 wrote:
Fri Jul 31, 2020 6:59 pm
Oziphantom wrote:
Thu Jul 30, 2020 11:00 pm
Move to B from A is not a valid sentence.
Yes it is. It's just not usual in most contexts. In the context of "moving" as in changing place of residence, it's just as normal as the other way around, probably because the destination is more important than the source in that context.
You've stumbled over the issue. Move is present tense. So you don't move from another destination while you are in that location. The problem is B is where you are, A is in the past. So you can't move to B as you are in B as A is from which is in the past and you are no longer there.
I moved to B from A
I'm moving to B from A
I will move to B from A
I have moved to B from A
You should move to B from A
If you are giving both locations, you can't be in both locations at the same time and hence you need to add extra context to it to show which tense it is. Either you are moving, future tense, or moved, past tense. You don't move in 2 locations in the present tense. Although moving can take some time so you say 'currently moving' to imply you are en route.
93143 wrote:
Math is not a word.
Canadian here; yes it is.
You are suppose to be of the Commonwealth and know better. However youtube has shown me you have succumbed to using "that" and "there" all over the place as well. But I'm told you don't have "Sophomores" at least.. seems every school needs to have them and they are possibly some form of Marshmallow.

93143 wrote:Probably because it's about 37 times easier to say...
Odd I find it much harder to say. You have to extend the a like you are Tom Hanks, then you do the hard Th and your tongue has nowhere to go leading to this long harsh pause after you say it, as if you are trying to do a dramatic pause, so your tongue can rearrange it self. While throwing an 'es' sound on the end gives you a smooth transition back so you can move on to the next word. maths flows much easier then a hard math.

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

Re: Making "Good" Assembly Code

Post by lidnariq » Sat Aug 01, 2020 12:48 am

I'm trying to keep myself from continuing to tangent on this thread but here I go anyway...

Evidently, it turns out that
1- "Maths" and "Math" didn't originate in the countries where they're currently most common
2- The modern usages are recent, only appearing in the past 110-140 years
3- "Maths" or "Math" is a mass noun anyway, so it doesn't really matter that the etymology ultimately comes from a plural form of a word in Greek

More: English StackExchange:Why is math always pluralized in British English but singular in American English?
The abbreviation Math. goes back to at least 1795, and the abbreviation Maths. to at least 1839, but occurrences do not strictly follow today's regional preferences: the two earliest instances of Math. that I found are from England, and the two earliest instances of Maths. are from the United States.

Post Reply