Fun with Assembly

The war between wetware and hardware.
Pyrrho
Posts: 26351
Joined: Sat Jun 05, 2004 2:17 am
Title: Man in Black
Location: Division 6

Fun with Assembly

Way beyond me but here's the link, you bastards.

https://dev.to/miniharryc/a-little-fun- ... sembly-6dm
The flash of light you saw in the sky was not a UFO. Swamp gas from a weather balloon was trapped in a thermal pocket and reflected the light from Venus.

Rob Lister
Posts: 20197
Joined: Sun Jul 18, 2004 7:15 pm
Title: Incipient toppler
Location: Swimming in Lake Ed

Re: Fun with Assembly

8088 assembly was the second language I learned. I never learned it well. I did a few experimental things with it but it is far to tedious.

xouper
Posts: 9305
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA

Re: Fun with Assembly

Pyrrho wrote:Way beyond me but here's the link, you bastards.

https://dev.to/miniharryc/a-little-fun- ... sembly-6dm
Cute.

As a professional programmer, I got lots of stories about fun with assembly language programming.

Example: How I found a compiler bug by looking at the hex code. It was an Intel compiler that translated PL/M into 80286 assembler. According to my boss, that little trick earned me six months pay in less than an hour. (Details on request.)

Mentat
Posts: 10271
Joined: Tue Nov 13, 2007 11:00 pm
Location: Hangar 18

Re: Fun with Assembly

Rob Lister wrote:8088 assembly was the second language I learned. I never learned it well. I did a few experimental things with it but it is far to tedious.
I took a class in 8086 assembly. Great class, terrific teacher, but I am never touching that shit again. That way lies madness. The class was half coding, half studying things not to do when designing an architecture, and why intel did those things anyways.
It's "pea-can", man.

Lapis Sells . . . But Who's Buying?

xouper
Posts: 9305
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA

Re: Fun with Assembly

Mentat wrote:I took a class in 8086 assembly. Great class, terrific teacher, but I am never touching that shit again.
That's why some of us get paid the big bucks. Not only would I touch it again, I would volunteer. I have no trouble translating in my head from C to assembly. But there's not much demand for that anymore.

xouper
Posts: 9305
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA

Re: Fun with Assembly

Another example of fun with assembler:

Get in your wayback machine set to the mid 1980s.

I was job shopping for a Chicagoland supplier of some automation equipment to DuPont in Maryland. The code was all in 8085 assembly language. The previous programmer for the DuPont project had somehow lost the source code and all they had were the EPROMs that were in the machines in Maryland.

They were in a panic. DuPont wanted some revisions and no one had the source code to make any revisions to.

I suggested I could recover the source code from the EPROMs. The boss was of course dubious, but I said I could probably do it in two weeks. So they sent me to Maryland and I did it in two days.

All I had was an EPROM burner that let me read the hex values. I didn't even have a disassembler or debugger. But I cheated and used the source code from a similar machine from a different project and merely modified it to match the EPROMs in the DuPont machines.

This why they paid me the big bucks.

gnome
Posts: 22449
Joined: Tue Jun 29, 2004 12:40 am
Location: New Port Richey, FL

Re: Fun with Assembly

I think it's the same machine, for my 8088 I just stuck with gwbasic. Never had the patience for assembly language.
"If fighting is sure to result in victory, then you must fight! Sun Tzu said that, and I'd say he knows a little bit more about fighting than you do, pal, because he invented it, and then he perfected it so that no living man could best him in the ring of honor. Then, he used his fight money to buy two of every animal on earth, and then he herded them onto a boat, and then he beat the crap out of every single one. And from that day forward any time a bunch of animals are together in one place it's called a zoo! (Beat) Unless it's a farm!"
--Soldier, TF2

xouper
Posts: 9305
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA

Re: Fun with Assembly

gnome wrote:I think it's the same machine, for my 8088 I just stuck with gwbasic. Never had the patience for assembly language.
Exactly.

When a higher level language suffices, there really is no point in using assembly language.

However, I've always been curious about something.

I learned assembler first, and higher level languages later. Apparently that's backwards from most people's experience.

My deep understanding of assembler made it much easier to learn other languages. Or so it seems to me.

Example: Many people have trouble with pointers in the C language. However, because of my assembler experience, C pointers were immediately intuitive and I never had any problem at all learning shit like that.

I always seemed to know how the higher level languages were implemented at the machine code level. It was as if I had a compiler in my head. I could read a line of code in a higher level language and then immediate visualize in my head what the underlying assembler code would look like, more or less.

So my curiosity is this: For those who do not have a deep understanding of how assembler works, does that hinder the learning of higher level languages?

It is merely a pedagogical curiosity.

gnome
Posts: 22449
Joined: Tue Jun 29, 2004 12:40 am
Location: New Port Richey, FL

Re: Fun with Assembly

My last real lesson in programming was a FORTRAN class in the early 90s. I learned structured coding, which basically is all about avoiding "GOTO". I got decent at it but then never did a personal coding project again--mainly because by then BBSs and later, the Internet, removed most needs for personal coding. Anything I would code, someone with more time on their hands had already done better than I probably could
"If fighting is sure to result in victory, then you must fight! Sun Tzu said that, and I'd say he knows a little bit more about fighting than you do, pal, because he invented it, and then he perfected it so that no living man could best him in the ring of honor. Then, he used his fight money to buy two of every animal on earth, and then he herded them onto a boat, and then he beat the crap out of every single one. And from that day forward any time a bunch of animals are together in one place it's called a zoo! (Beat) Unless it's a farm!"
--Soldier, TF2

xouper
Posts: 9305
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA

Re: Fun with Assembly

gnome wrote:. . . Anything I would code, someone with more time on their hands had already done better than I probably could
I run into that a lot too. I use a lot of utilities written by others that I snarfed off the internet.

Nonetheless, sometimes I want to do things that have no readily available app. So I have no choice but to write my own.

One such project I am faced with having to do is a program that will compare two ebooks and show me what's different (and not just the text but also the metadata, etc) and then to edit one of them to remove (or alter) the stuff I don't want. I haven't yet found a program that already does that in the way I want to use it. If it was just the text to be compared, there apps for that. So it looks like I will be writing my own. Fortunately, I don't have to start from scratch, since I have the source code for Calibre.

xouper
Posts: 9305
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA

Re: Fun with Assembly

More fun with Assembly . . .

Another curiosity I've long had is why assemblers tend to use a syntax that's unnatural and sometimes obtuse. And yes, tedious.

Example: In 8086, if you want to add a constant to a register, in assembler you would use this syntax:

Code: Select all

ADD BX, 6
And that would add 6 to whatever was already in the BX register.

I always wondered, why aren't there any assemblers that use a more friendly syntax. Like why not this:

Code: Select all

BX = BX + 6
or better yet:

Code: Select all

BX += 6
which would add 6 to whatever was already in the BX register.

Once Upon A Time, I started experimenting with developing an assembler to use a C-like syntax, where each line of code translated into a single 8086 opcode. It seemed like it should be an easy thing to do. To me, it seemed every assembler instruction has an obvious C-like syntax, more or less.

But I quickly ran into the overwhelming desire to have certain lines of code be translated into two 8086 opcodes, something that most assemblers do not allow (assuming no macros).

For example, suppose you want to add a variable (in memory) to another variable (in memory).

In 8086, that takes two opcodes:

Code: Select all

MOV AX, [variable1]
ADD [variable2], AX
But I wanted my new assembler to allow this syntax:

Code: Select all

variable2 += variable1
Seems like a harmless extension, right?

(Actually it's not harmless, since it obscures the usage of a temporary register.)

But once I started doing that, there was no reason to stop until I had a fully functional C compiler.

In other words, I gave up.

Don't mind me, I'm just spittin' out whatever my neurons are telling me today.

gnome
Posts: 22449
Joined: Tue Jun 29, 2004 12:40 am
Location: New Port Richey, FL

Re: Fun with Assembly

It's OK, I feel good that I sort of understood all that.
"If fighting is sure to result in victory, then you must fight! Sun Tzu said that, and I'd say he knows a little bit more about fighting than you do, pal, because he invented it, and then he perfected it so that no living man could best him in the ring of honor. Then, he used his fight money to buy two of every animal on earth, and then he herded them onto a boat, and then he beat the crap out of every single one. And from that day forward any time a bunch of animals are together in one place it's called a zoo! (Beat) Unless it's a farm!"
--Soldier, TF2

Witness
Posts: 18273
Joined: Thu Sep 19, 2013 5:50 pm

Re: Fun with Assembly

Assembly? Piffle!
Fossbytes wrote:Google’s Machine Learning Software Can Create Code Better Than The Researchers Who Made It

Google’s AutoML system, which was introduced back in May, has recently produced machine-learning codes with higher efficiency than those made by the researchers themselves. Google developed AutoML to be an artificial intelligence that could help humans create other self-learning systems.

AutoML was developed because there are few experts with the knowledge to build highly complex AI systems. To meet the demand for experts, Google developed AutoML to create self-learning code, and in a way, clone itself.

Google reported in its official blog that AutoML can be trained and evaluated for quality on particular tasks. Feedback is generated to improve the proposals for the subsequent rounds. AutoML can run thousands of simulations to make appropriate changes, generate new architectures, and give recurring feedback.

Witness
Posts: 18273
Joined: Thu Sep 19, 2013 5:50 pm

Re: Fun with Assembly

One can also have fun with high-level languages:

Pyrrho
Posts: 26351
Joined: Sat Jun 05, 2004 2:17 am
Title: Man in Black
Location: Division 6

Re: Fun with Assembly

That is the algorithm for the Browns playbook.
The flash of light you saw in the sky was not a UFO. Swamp gas from a weather balloon was trapped in a thermal pocket and reflected the light from Venus.

xouper
Posts: 9305
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA

Re: Fun with Assembly

Witness wrote:
Tue Aug 21, 2018 1:44 am
One can also have fun with high-level languages:

Is someone trying to make C code look like Python*?

_______________________________________________________
* Footnote: But with the added burden of making it harder to find bugs in the brackets.

Abdul Alhazred
Posts: 72929
Joined: Mon Jun 07, 2004 1:33 pm
Title: Yes, that one.
Location: Chicago

Re: Fun with Assembly

That is the one true C style.
Any man writes a mission statement spends a night in the box.
-- our mission statement plappendale

xouper
Posts: 9305
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA

Re: Fun with Assembly

Abdul Alhazred wrote:
Tue Aug 21, 2018 2:10 pm
That is the one true C style.

Abdul Alhazred
Posts: 72929
Joined: Mon Jun 07, 2004 1:33 pm
Title: Yes, that one.
Location: Chicago

Re: Fun with Assembly

Remember the "obfuscated C" contests?
Any man writes a mission statement spends a night in the box.
-- our mission statement plappendale

xouper
Posts: 9305
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA

Re: Fun with Assembly

Abdul Alhazred wrote:
Tue Aug 21, 2018 2:15 pm
Remember the "obfuscated C" contests?
Yes I do. Boring.

Which reminds me: More fun if you obscure the swap using the xor algorithm instead (also no need to pass three args):

private static mangle(char* x, char* y) { *x ^= *y; *y ^= *x; *x ^= *y; }

and then call it with this: mangle(&a[n % 2 == 0 ? i : 0], &a[n]);

Warning: Don't pass x == y else you will zero them both out.