Fun with Assembly

The war between wetware and hardware.
User avatar
Pyrrho
Posts: 25679
Joined: Sat Jun 05, 2004 2:17 am
Title: Man in Black
Location: Division 6
Has thanked: 2684 times
Been thanked: 2730 times

Fun with Assembly

Post by Pyrrho » Fri Oct 13, 2017 11:31 pm

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.

User avatar
Rob Lister
Posts: 19794
Joined: Sun Jul 18, 2004 7:15 pm
Title: Incipient toppler
Location: Swimming in Lake Ed
Has thanked: 568 times
Been thanked: 578 times

Re: Fun with Assembly

Post by Rob Lister » Fri Oct 13, 2017 11:50 pm

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.

User avatar
xouper
Posts: 8621
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA
Has thanked: 213 times
Been thanked: 119 times

Re: Fun with Assembly

Post by xouper » Sat Oct 14, 2017 1:52 am

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.)

User avatar
Mentat
Posts: 10271
Joined: Tue Nov 13, 2007 11:00 pm
Location: Hangar 18
Has thanked: 37 times
Been thanked: 124 times

Re: Fun with Assembly

Post by Mentat » Sat Oct 14, 2017 2:43 am

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?

User avatar
xouper
Posts: 8621
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA
Has thanked: 213 times
Been thanked: 119 times

Re: Fun with Assembly

Post by xouper » Sat Oct 14, 2017 7:03 am

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.

User avatar
xouper
Posts: 8621
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA
Has thanked: 213 times
Been thanked: 119 times

Re: Fun with Assembly

Post by xouper » Sat Oct 14, 2017 7:33 am

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.

User avatar
gnome
Posts: 21945
Joined: Tue Jun 29, 2004 12:40 am
Location: New Port Richey, FL
Has thanked: 354 times
Been thanked: 373 times

Re: Fun with Assembly

Post by gnome » Sat Oct 14, 2017 8:32 pm

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

User avatar
xouper
Posts: 8621
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA
Has thanked: 213 times
Been thanked: 119 times

Re: Fun with Assembly

Post by xouper » Sat Oct 14, 2017 9:20 pm

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.

User avatar
gnome
Posts: 21945
Joined: Tue Jun 29, 2004 12:40 am
Location: New Port Richey, FL
Has thanked: 354 times
Been thanked: 373 times

Re: Fun with Assembly

Post by gnome » Sat Oct 14, 2017 9:29 pm

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

User avatar
xouper
Posts: 8621
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA
Has thanked: 213 times
Been thanked: 119 times

Re: Fun with Assembly

Post by xouper » Sat Oct 14, 2017 9:50 pm

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.

User avatar
xouper
Posts: 8621
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA
Has thanked: 213 times
Been thanked: 119 times

Re: Fun with Assembly

Post by xouper » Sat Oct 14, 2017 9:57 pm

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.

User avatar
gnome
Posts: 21945
Joined: Tue Jun 29, 2004 12:40 am
Location: New Port Richey, FL
Has thanked: 354 times
Been thanked: 373 times

Re: Fun with Assembly

Post by gnome » Sun Oct 15, 2017 1:07 am

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

User avatar
Witness
Posts: 16036
Joined: Thu Sep 19, 2013 5:50 pm
Has thanked: 1931 times
Been thanked: 2622 times

Re: Fun with Assembly

Post by Witness » Tue Oct 31, 2017 3:19 am

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.
https://fossbytes.com/google-automl-def ... tter-code/

User avatar
Witness
Posts: 16036
Joined: Thu Sep 19, 2013 5:50 pm
Has thanked: 1931 times
Been thanked: 2622 times

Re: Fun with Assembly

Post by Witness » Tue Aug 21, 2018 1:44 am

One can also have fun with high-level languages:

Image

User avatar
Pyrrho
Posts: 25679
Joined: Sat Jun 05, 2004 2:17 am
Title: Man in Black
Location: Division 6
Has thanked: 2684 times
Been thanked: 2730 times

Re: Fun with Assembly

Post by Pyrrho » Tue Aug 21, 2018 10:31 am

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.

User avatar
xouper
Posts: 8621
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA
Has thanked: 213 times
Been thanked: 119 times

Re: Fun with Assembly

Post by xouper » Tue Aug 21, 2018 2:04 pm

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

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


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

User avatar
Abdul Alhazred
Posts: 70350
Joined: Mon Jun 07, 2004 1:33 pm
Title: Yes, that one.
Location: Chicago
Has thanked: 3052 times
Been thanked: 1135 times

Re: Fun with Assembly

Post by Abdul Alhazred » Tue Aug 21, 2018 2:10 pm

That is the one true C style. :HoppingMad2:
Image "If I turn in a sicko, will I get a reward?"

"Yes! A BIG REWARD!" ====> Click here to turn in a sicko
Any man writes a mission statement spends a night in the box.
-- our mission statement plappendale

User avatar
xouper
Posts: 8621
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA
Has thanked: 213 times
Been thanked: 119 times

Re: Fun with Assembly

Post by xouper » Tue Aug 21, 2018 2:13 pm

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

User avatar
Abdul Alhazred
Posts: 70350
Joined: Mon Jun 07, 2004 1:33 pm
Title: Yes, that one.
Location: Chicago
Has thanked: 3052 times
Been thanked: 1135 times

Re: Fun with Assembly

Post by Abdul Alhazred » Tue Aug 21, 2018 2:15 pm

Remember the "obfuscated C" contests? :coolspecs:
Image "If I turn in a sicko, will I get a reward?"

"Yes! A BIG REWARD!" ====> Click here to turn in a sicko
Any man writes a mission statement spends a night in the box.
-- our mission statement plappendale

User avatar
xouper
Posts: 8621
Joined: Fri Jun 11, 2004 4:52 am
Location: HockeyTown USA
Has thanked: 213 times
Been thanked: 119 times

Re: Fun with Assembly

Post by xouper » Tue Aug 21, 2018 2:29 pm

Abdul Alhazred wrote:
Tue Aug 21, 2018 2:15 pm
Remember the "obfuscated C" contests? :coolspecs:
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.