Author Topic: Introduction to ASM  (Read 10072 times)

0 Members and 1 Guest are viewing this topic.

Offline jokkmokk

  • ZX 81
  • *
  • Posts: 6
  • Karma: 2
    • View Profile
Introduction to ASM
« on: November 07, 2010 »
So hello there, I am jOkkmOkk from dhc-crew, and to start with, dhc is a active demogroup that got banned from POUET because of ex. daemon from our group who spammed around with childish behaviour, so we kicked him off, hiring new coders and wiping off all the stuff he put us in during these days.

As a small tribute, I would like to present to you a small "demo-effect" with just a flickering screen in different colors. Nothing too important. It is going to be done in .286 assembler, and you can use FASM, NASM or any preferable assembler compiler. So, let's go..!  :updance:

First of all, we would like to start at an adress. I am often using 0x100 as starting adress so let's go with that. Type "org 0x100" to define that we start at that adress, like this;

Code: [Select]
org 0x100Easy right?

Nothing much is gonna happen when you compile this, so let's move along. Now we want to enter the infamous "Mode-X", and we can do so by typing;

Code: [Select]
mov ax,13h
int 10h

The "mov" command followed by "ax,13h" is simply a command which lets us head into "Mode 13", and "int 10h" is simply a interrupt to do what is in ax (accumulator register)

Your still with me? Awesome!

If you compile this now, everything that happens is that it goes into VGA mode, so what we will do now is to add some awesome pixels, and we are going to do this by entering what I call drawmode, this is to add the code;

Code: [Select]
les bp,[bx]

Now here is a small scheme that we have when entering this "draw mode", and im just giving you the most simple ones;

CX = X
DX = Y
AL = Color

That's simple, eh? :)

Now... Make a loop, you can simple do this by typing

Code: [Select]
loop1:

Or you can give your loop a somewhat more creative name. ;)
Why are we making a loop, you ask? Well because now we are going to do the simplest of the most simple, and that is to draw! ;D

Type this into you code or copy this snippet;

Code: [Select]
loop1:
inc cx
stosb
cmp cx,64000
jne loop1
inc al
jmp loop1

Yes sir, this is the source code for our effect! Now what does it do?

Let me explain...

I already explained the "Loop1:" part, yeah, all this is doing is giving us the opportunity to loop a snippet of code.

Now "inc cx", will just increase the CX value, remember CX = X, this meaning taking a step to the right. When it comes to pixel 359, all to the right, it will begin to the left again a row down.

"stosb" is a command I use to display what we do, that is if any changes happened in the "background", call stosb or int 10h to see the changes. Hard to explain, but in short words, it simple stores a byte.

Now, "cmp cx, 64000" is a easy one, what it will do is comparing if X = 64000. Remember that I said that it will start a row down. And in VGA mode, 64000 is the the bottom right of the screen, this is that it just checks if X is at the bottom right.

"jne loop1" is also something very easy. JNE stands for "Jump if Not Equal" and will jump to specified value, this is "Loop1" if CX is not equal to 64000. In other words, it will continue to draw until it is at the bottom right corner.

Also "inc al" is placed under the "jne loop1" which means that it will increase the color by one. This happens when CX = 64000.

And at last, I guess you know this one.

"jmp loop1" means just to jump back to the loop.

The good thing is that you will not run into some overflow error if CX or AL in these cases goes beyond it's limits. The registers will just reset. That is if you now compile and run this, you should see the screen smoothly increase into all kinds of colors, and when the colors reaches it's limits, they will just start all over.

So yeah, I don't know if anyone will get any use of this tutorial, but anyhow I hope I cleared up the basics. If there is any questions, just ask and I will try to anwser them.  :clap:

And to conclude, here is the full source once again. Try to experiment with different values and stuff! Best luck to you, and show me your effects and stuff you make! :)


Full source-code;

Code: [Select]
org 0x100
mov ax,13h
int 10h
les bp,[bx]
loop1:
inc cx
stosb
cmp cx,64000
jne loop1
inc al
jmp loop1

This should compile to as small as around 15 - 25 bytes. :)

Thank you so much for reading this small tutorial!  :clap:

/jOkkmOkk^DHC[DrunkenHobbitCoders]

Offline maracuja

  • C= 64
  • **
  • Posts: 31
  • Karma: 4
    • View Profile
Re: Introduction to ASM
« Reply #1 on: July 07, 2011 »
Nice Ms-DOS Tutos !
Thanks to you, i remember of my last days on DOS com program file. :D With the org 100 to make some space for PSP [1] . :D

[1] http://board.flatassembler.net/topic.php?t=7915
[2] http://board.flatassembler.net/topic.php?t=3057&start=0

Offline bj

  • ZX 81
  • *
  • Posts: 20
  • Karma: 10
    • View Profile
Re: Introduction to ASM
« Reply #2 on: July 07, 2011 »
I lost interest in x86 asm when I got rid of my XP-powered computer about 2 years ago and could no longer do org100h. Has anyone done a Windows 7 wrapper so I can run mini asm progs like this on my new laptop?

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Introduction to ASM
« Reply #3 on: July 07, 2011 »
I lost interest in x86 asm when I got rid of my XP-powered computer about 2 years ago and could no longer do org100h. Has anyone done a Windows 7 wrapper so I can run mini asm progs like this on my new laptop?

I'm sure that Rain_Storm posted a framework for this that he'd made, but for the life of me I can't find it!
It's here somewhere though I know it.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline padman

  • Senior Member
  • Pentium
  • ********
  • Posts: 990
  • Karma: 260
    • View Profile
Re: Introduction to ASM
« Reply #4 on: July 07, 2011 »
You could use Dosbox to run your oldskool org100h programs on Windows 7. http://www.dosbox.com/
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Introduction to ASM
« Reply #5 on: July 08, 2011 »
512b GDI Framework will allow you to push some pixels on Windows 7.

BTW this is very misleading...
Quote
Now we want to enter the infamous "Mode-X", and we can do so by typing;
Mode X is a number of non standard compliant video modes including 320x240 up to 360x480 and operates in planar memory (unchained) mode. The video mode used in this tutorial is Mode 13h which is 320x200 chained. Mode X is only possible by bypassing int 10h and setting up the video mode manually by manipulating the VGA registers.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Introduction to ASM
« Reply #6 on: July 08, 2011 »
At work, we used to call mode-X "spaz mode".  Are we going to hell?  :o

Jim
Challenge Trophies Won:

Offline bj

  • ZX 81
  • *
  • Posts: 20
  • Karma: 10
    • View Profile
Re: Introduction to ASM
« Reply #7 on: July 08, 2011 »

512b GDI Framework works a treat for me.  :updance: Maybe time for me to give FASM a go again!

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Introduction to ASM
« Reply #8 on: July 09, 2011 »
That's good news :)

Looking forward to seeing what you come up with!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline jace_stknights

  • Amiga 1200
  • ****
  • Posts: 399
  • Karma: 32
  • PEEK & POKE are not MOVEM!
    • View Profile
    • ST Knights WebSite
Re: Introduction to ASM
« Reply #9 on: September 09, 2011 »
Mode X is a number of non standard compliant video modes including 320x240 up to 360x480 and operates in planar memory (unchained) mode. The video mode used in this tutorial is Mode 13h which is 320x200 chained. Mode X is only possible by bypassing int 10h and setting up the video mode manually by manipulating the VGA registers.

Hu hu that reminds me good old time, with Pmode, Gravis Ultrasound, and so on... the beginning!
Challenge Trophies Won:

Offline lee_5657

  • ZX 81
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
Re: Introduction to ASM
« Reply #10 on: October 12, 2011 »
Cheers.

I'll try this out.