Making "Good" Assembly Code

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

Moderator: Moderators

turboxray
Posts: 83
Joined: Thu Oct 31, 2019 12:56 am

Re: Making "Good" Assembly Code

Post by turboxray » Sat Aug 01, 2020 10:59 am

Oziphantom wrote:
Fri Jul 31, 2020 11:44 pm
93143 wrote:
Math is not a word.
Canadian here; yes it is.
You are suppose to be of the Commonwealth and know better.
Wooow. That's not insulting at all :lol:

"Maths" just sounds like something a 4 year old would say though. It's like saying "stuffs", or "monies" (yes I know people use the last one, but why??? Money is already plural). If you want to refer to multiple disciplines of math, then why not just say "math disciplines"?


MOVE or MOV is used on the NEC RISC processors too. Just like other processors, LD/ST are used for direct memory access (loading a value into a register), but MOV is to work within registers. I find that a little strange when you could have used MOV for any sort of similar action.


Also, operation src, dest makes much more sense. The whole SUB #3, reg syntax makes perfect sense; it's a read-modify-write operation if you think about it. Get 'reg', subtract 'src', stow 'reg'. Same for AND, ADD, OR, etc.


More on topic, I've done some "object oriented programming" in assembly (for PCE). I used macros as "new" equivalent, to instantiate an object. I used macros for help with polymorphism and inheritance on class files, although both were pretty basic.

tepples
Posts: 22020
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Making "Good" Assembly Code

Post by tepples » Sat Aug 01, 2020 3:01 pm

In my opinion, a compare instruction (that is, a subtract affecting flags but not a register) is slightly more confusing with destination last.

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

Re: Making "Good" Assembly Code

Post by Oziphantom » Sun Aug 02, 2020 12:13 am

turboxray wrote:
Sat Aug 01, 2020 10:59 am
Oziphantom wrote:
Fri Jul 31, 2020 11:44 pm
93143 wrote: Canadian here; yes it is.
You are suppose to be of the Commonwealth and know better.
Wooow. That's not insulting at all :lol:

"Maths" just sounds like something a 4 year old would say though. It's like saying "stuffs", or "monies" (yes I know people use the last one, but why??? Money is already plural). If you want to refer to multiple disciplines of math, then why not just say "math disciplines"?
Stuffs is bad I concur. However Monies is needed, as dumb as it sounds. As it refers to multiple forms of money.
Say you have $CAD, $US, Japanese Yen in your wallet, then you have Monies in your wallet as you have multiple currencies.
But Money is not a plural it's a substance.
For example Rice is not a plural, you have a pile of "rice" which means the thing the pile is made out of is rice. But you have a rice grain, and in the pile there are multiple rice grains. But if you have say Jasmin Rice and Basmati Rice and Sushi Rice in your cupboard you have Rices. Same as with Pasta, Dirt, Tea etc
But you would have a plate of Burgers not Burger because a Hamburger is a complex item made from other elements and hence is a self contained thing. And you have burgers because you have multiple hamburger on the plate and the abbreviation keeps the plural and thus burgers.

turboxray wrote:MOVE or MOV is used on the NEC RISC processors too. Just like other processors, LD/ST are used for direct memory access (loading a value into a register), but MOV is to work within registers. I find that a little strange when you could have used MOV for any sort of similar action.
I think this is a valid seperation that may be important for the programmer to be aware of. Similar to how in C++ a direction object is referenced by . and a pointer is -> you could argue why can't the compiler just take . and work it out for me. To which my response is, you need to be aware that you have a pointer not a stack object as they behave differently with different ownership and lifecycles. To which maybe memory operations have a wait cycle upon them or there is some other access limit, perhaps you are on a multi core system where accessing or modifying RAM might have implications. I'm not familar with the specific chip but it is common on RISC systems to have the fetch of data be half the system bus or at least smaller than because you have fixed length instructions. So are the internal MOV instructions the full bus width say 32 bits in 1 op. While the LD and ST have LDL and LDH version so you can pull in the upper and lower halfs of the data?

turboxray wrote:Also, operation src, dest makes much more sense. The whole SUB #3, reg syntax makes perfect sense; it's a read-modify-write operation if you think about it. Get 'reg', subtract 'src', stow 'reg'. Same for AND, ADD, OR, etc.
I wonder if Stack operations is involved somehow, most of the engineers would have been using calculators a lot and possibly prone to punching cardboard in Forth.
dest
src
op
but now you do
op dest src

User avatar
Jarhmander
Formerly ~J-@D!~
Posts: 501
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Re: Making "Good" Assembly Code

Post by Jarhmander » Sun Aug 02, 2020 6:29 am

Two pages ago, someone asked for a CPU with a math-like syntax (or C-style syntax), instead of a "COBOL" like syntax (oops, mixing things up with the other thread).

Here it is, my friends: CSR's Kalimba processor. Just look at the assembly code, it really looks like C at times. Not too surprisingly, it is a DSP.
((λ (x) (x x)) (λ (x) (x x)))

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

Re: Making "Good" Assembly Code

Post by Pokun » Sun Aug 02, 2020 8:44 am

For future reference, the other thread.


I would have thought that "money" was an uncountable noun (like "water") and that if you wanted to refer to multiple forms of money you would just rewrite it using another noun like "currency". But looking it up, both "moneys" and "monies" are correct plural forms according to dictionaries.

turboxray
Posts: 83
Joined: Thu Oct 31, 2019 12:56 am

Re: Making "Good" Assembly Code

Post by turboxray » Sun Aug 02, 2020 9:04 am

Pokun wrote:
Sun Aug 02, 2020 8:44 am
I would have thought that "money" was an uncountable noun (like "water") and that if you wanted to refer to multiple forms of money you would just rewrite it using another noun like "currency". But looking it up, both "moneys" and "monies" are correct plural forms according to dictionaries.
I've only really seen monies in the context of financial terms. As in, monies referring to having your money invested in different financial mechanisms, and thus monies is the collection of the distributed investments. Otherwise for his example, I would have used currency.

@Pokun: that's for the link, I moved my response to over there.

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

Re: Making "Good" Assembly Code

Post by lidnariq » Sun Aug 02, 2020 11:21 am

It's a mass noun, like "water".

You can talk about waters, plural, in the sense of multiple bodies of water.

More reading:
https://en.wikipedia.org/wiki/Mass_noun
https://en.wikipedia.org/wiki/Collective_noun

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

Re: Making "Good" Assembly Code

Post by Dwedit » Sun Aug 02, 2020 3:04 pm

Ja I am made of dur butter und you are worth 2K monies.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

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

Re: Making "Good" Assembly Code

Post by Pokun » Sun Aug 02, 2020 4:57 pm

Haha!
Wow that's entirely different from Swedish! ...Or so I thought. Looking it up it appears that there are two types of "vatten" (water), one that is an an uncountable mass word (referring to the substance or element), and one that is countable (referring to bodies of water). The uncountable type has no singular or plural and the countable one has both of them. It's just that the indefinite singular and indefinite plural forms are identical, and only the two definitive forms are different. I guess it's basically the same in English.

As a side note, the Swedish word "matematik" (mathematics) is totally uncountable and has no singular or plural forms. Its abbreviated/slang form is "matte" (double-T means the vowel before it (A) is short and the T consonant is long, probably added to make it easier to say).

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

Re: Making "Good" Assembly Code

Post by 93143 » Mon Aug 03, 2020 1:40 am

Oziphantom wrote:
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.
You're overthinking this. Tense has nothing to do with it; that information is conveyed in the form of the verb, not what follows it. Something like "I am moving to B from A" is a perfectly valid sentence, quite apart from the question of whether or not anybody cares where you're moving from, or even whether the statement happens to be true at the moment. The infinitive form "to move to B from A" isn't a complete sentence, but as a phrase it's valid English.

And of course, "Move to B from A", specifically, is also a valid sentence. It's a command, using the imperative form of the verb. Which is of course what every opcode in an assembly language is... Mind you, since there's no object given, the sentence does provide what appears to be unnecessary information. In the case of this particular verb, the intransitive form effectively makes the subject also the object, and if he's not at A why would he have to go there first before moving to B? Maybe there's an Indiana Jones-style trap that requires this specific pattern of motion...

Anyway, the problem in assembly language is not the verb form. The lack of prepositions introduces a serious ambiguity, and if one wishes to turn a MOV dest, src instruction into an English sentence without changing its meaning, an object is one of the necessary additions. "Move data to B from A" is perfectly fine, but "Move to B from A" is only valid English if "move" is taken as intransitive, which makes no sense in the context of a CPU instruction, since the CPU cannot move.

So I guess technically your statement "Move to B from A is not a valid sentence" could be considered correct, given the additional stipulation that "move" in this case is transitive; that is, the subject of the verb is expected to move something. Unfortunately "move" and "move" are spelled the same, so this distinction is easy to miss...

...

(Also, you don't move from a destination. A destination is somewhere you move to, by definition. Unless it's the secondary meaning of "place it's trendy to go to", which is a little specific for our purposes...)

Trust me; I'm in probably the top 0.000001% of engineers when it comes to skill in and understanding of English. Not that that's saying much... I may get careless or colloquial from time to time, but I like to think I know what I'm doing.

turboxray wrote:LD/ST are used for direct memory access (loading a value into a register), but MOV is to work within registers.
Oh yeah, that reminds me - 65xx uses "transfer" to copy data between registers: TAX, TXY, TCD, etc. And the order of arguments is always src, dest...

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

Re: Making "Good" Assembly Code

Post by Oziphantom » Mon Aug 03, 2020 7:16 am

93143 wrote:Something like "I am moving to B from A" is a perfectly valid sentence,
As it appears I was not clear
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
Are examples of valid sentences, my point being you need to add these aditional words or rearange the structure to make it valid, while "Move to B from A" in it self is not a valid sentence.
93143 wrote:
Mon Aug 03, 2020 1:40 am
And of course, "Move to B from A", specifically, is also a valid sentence. It's a command, using the imperative form of the verb. Which is of course what every opcode in an assembly language is... Mind you, since there's no object given, the sentence does provide what appears to be unnecessary information. In the case of this particular verb, the intransitive form effectively makes the subject also the object, and if he's not at A why would he have to go there first before moving to B? Maybe there's an Indiana Jones-style trap that requires this specific pattern of motion...
No, This is not valid. You probably can argue its "poor grammar rather than completely wrong" but as you are not located in A you do not move from it. In this form you use "via". Move to B via A. As in "Go to the train station via the post office and get me a book of stamps.". Enter the office via the left side entrance.

93143 wrote:
Mon Aug 03, 2020 1:40 am
turboxray wrote:LD/ST are used for direct memory access (loading a value into a register), but MOV is to work within registers.
Oh yeah, that reminds me - 65xx uses "transfer" to copy data between registers: TAX, TXY, TCD, etc. And the order of arguments is always src, dest...
Good catch.

turboxray
Posts: 83
Joined: Thu Oct 31, 2019 12:56 am

Re: Making "Good" Assembly Code

Post by turboxray » Mon Aug 03, 2020 8:52 am

Oziphantom wrote:
Mon Aug 03, 2020 7:16 am
Are examples of valid sentences, my point being you need to add these aditional words or rearange the structure to make it valid, while "Move to B from A" in it self is not a valid sentence.
No you do not. "Move to B" is a command. No different than "Sit down". Not only is it grammatically correct, it's not even "awkward" speech. Just because the subject is implied, doesn't make it incorrect grammar.

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

Re: Making "Good" Assembly Code

Post by Oziphantom » Mon Aug 03, 2020 9:15 am

well yes you can also remove words to make a sentence that is valid. However "Move To A" is not the same sentence as it doesn't mention B. You could also equally make it "Move From B", i.e "Move from the chair" which is not the same sentence as you don't mention A anymore.

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

Re: Making "Good" Assembly Code

Post by Pokun » Mon Aug 03, 2020 2:28 pm

Removing B is not the point. "Move to B from A" is still a perfectly grammatically correct sentence. Like I said earlier, it uses the imperative form of the verb, which means the subject can be dropped (so no need to say who/what is moving), and the verb is also an intransitive verb, which means the verb doesn't take a direct object (which in this case also would be what is moved) like 93143 said.

Post Reply