Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - x86 Assembler

Reply to topic
Author Message
Chris
  • Guest
Reply with quote
x86 Assembler
Post Posted: Wed Aug 04, 1999 8:05 am
Well, my studying of assembler has been a huge success! It took countless tries but my formula for
ploting a pixel in 320x200x8 is memorized in my head! It will change resolution, print the pixel,
return to the text mode resolution, and exit to dos. It was written in Microsoft Assembler 6.0.
Here's my code:


DOSSEG
.MODEL SMALL
.STACK 200h

.DATA
.CODE

start:
mov ax, 0013h ;setting the video mode 320x200x8
int 10h

mov ax, 0A000h
mov es, ax ;the VGA segment
mov ax, 1 ;the X position

mov di, ax ;adding x to offset formula
mov ax, 2 ;the Y position
mov cl, 6
shl ax, cl ;multiplying the Y position by 64
add di, ax ;adding Y to offset formula
mov cl, 2
shl ax, cl
add di, ax ;adding Y to offset formula

mov bl, 0Fh ;white color
mov es:[di], bl ;attempting to plot pixel with white color

mov ax, 0003h ;setting the video mode back to text.
int 10h

mov ax, 4C00h ;exiting to dos
int 21h

end start

I had to send my shift data to a register before I could do a register shift. Why? I don't know. I also
had to write 0A000 to a register and then send it to my segment register. Why? Masm didn't like
this code:


MOV AX, 0A000h


Do you have any suggestions? Is there something that could be simplier to this piece of code?

Chris :o)
 
Nyef
  • Guest
Reply with quote
Post Posted: Wed Aug 04, 1999 12:53 pm
Quote
> Well, my studying of assembler has been a huge success! It took countless tries but my formula for
> ploting a pixel in 320x200x8 is memorized in my head! It will change resolution, print the pixel,
> return to the text mode resolution, and exit to dos. It was written in Microsoft Assembler 6.0.

Note that you can't actually see the pixel, because you forgot to wait for a keypress. :-)

Quote
> Here's my code:

>

Add a .286 here (I'm assuming that you don't have an 8088 to test this with).

Quote
> DOSSEG
> .MODEL SMALL
> .STACK 200h

> .DATA
> .CODE

> start:
> mov ax, 0013h ;setting the video mode 320x200x8
> int 10h

> mov ax, 0A000h
> mov es, ax ;the VGA segment
> mov ax, 1 ;the X position

> mov di, ax ;adding x to offset formula
> mov ax, 2 ;the Y position

With the .286 mentioned earlier, the next two lines can become "shl ax, 6".

Quote
> mov cl, 6
> shl ax, cl ;multiplying the Y position by 64
> add di, ax ;adding Y to offset formula

Same here as above.

Quote
> mov cl, 2
> shl ax, cl
> add di, ax ;adding Y to offset formula

> mov bl, 0Fh ;white color
> mov es:[di], bl ;attempting to plot pixel with white color

xor ax, ax ; I _think_ this is the call to wait for a key
int 16h

Quote
> mov ax, 0003h ;setting the video mode back to text.
> int 10h

> mov ax, 4C00h ;exiting to dos
> int 21h

> end start
>

> I had to send my shift data to a register before I could do a register shift. Why? I don't know. I also
> had to write 0A000 to a register and then send it to my segment register. Why? Masm didn't like
> this code:

>
> MOV AX, 0A000h
>


Don't you mean mov es, 0a000h? You can't do a mov SS, imm. The instruction set won't let you.

Quote
> Do you have any suggestions? Is there something that could be simplier to this piece of code?

Only the 3 I mentioned above. :-)

Quote
> Chris :o)

--Nyef
 
Chris
  • Guest
Reply with quote
Post Posted: Wed Aug 04, 1999 5:15 pm
The reason why I knew it worked is because the first time I did it I forgot to change back to text resolution
so it kept the screen in graphics mode and the text was friggin huge!!! So I edited it to change back
to text mode and that's why you can't see the pixel display. I haven't studied the keyboard interrupt
yet. I know from an 8086 simulation program that you test the status of the port and if there is
a keypress you compare the accumulator with what key you want to test:

out 01h
cmp al, 1A

Or something like that. I think that should check the status of the Enter key, I'm not sure.

I never knew you had to plug in which type of processor you were writing under. This whole time
I've been using plain 8086 when I could have been using .286 and .386. Thanks a lot. I couldn't
understand what I was doing wrong.

Chris :o)
 
  • Joined: 24 Jun 1999
  • Posts: 1732
  • Location: Paris, France
Reply with quote
Post Posted: Wed Aug 04, 1999 7:40 pm
Quote
> I also had to write 0A000 to a register and then send it to my segment register. Why?

It is the starting address where the video memory in VGA mode is mapped.
  View user's profile Send private message Visit poster's website
Chris
  • Guest
Reply with quote
Post Posted: Thu Aug 05, 1999 2:33 am
Quote
> > I also had to write 0A000 to a register and then send it to my segment register. Why?

> It is the starting address where the video memory in VGA mode is mapped.

I understand that 0A000 is the starting address but I couldn't understand why I couldn't send hex
to the es register. Later I found that you can only send data to it register to register. I also discovered
that the SHL statement has been updated over the years. So unless you tell the assembler what
processor you're writing for you'll encounter problems. I wrote this:

SHL AX, 6

That's a 286 instruction from what I've heard. It's an updated method to performing shifts. If I want
to use that new instruction in my assembler sources, I need to declare at the top before my code:

.286

or something above or the assembler won't assemble it. Without that .286 or higher statement it
will be as if I'm programming under a little 8086. It was fun while I was studying plain 8086 but
I want to play with the big toys now. Anyway, if I wanted to shift by 6 in plain 8086, I would've had
to have typed it like this:

mov cl, 6
shl ax, cl

or a long list of single shifts.

Chris :o)
 
Lin Ke-Fong
  • Guest
Reply with quote
Post Posted: Thu Aug 05, 1999 5:45 am
Quote
> > > I also had to write 0A000 to a register and then send it to my segment register. Why?
> > It is the starting address where the video memory in VGA mode is mapped.
> I understand that 0A000 is the starting address but I couldn't understand why I couldn't send hex
> to the es register. Later I found that you can only send data to it register to register. I also discovered
> that the SHL statement has been updated over the years. So unless you tell the assembler what
> processor you're writing for you'll encounter problems. I wrote this:

shl is not a statement, it's an *instruction*, the instruction set of x86s has been improved over the time.
And "shl ax, constant" is only available on 286 and newer chips.

I may recommend you to take a look at http://developer.intel.com.

Go to /design/PentiumII/manuals, and download the 3 volume (3 pdf files in fact!) Developer's Manual.
You can also call Intel's Literature Center, the toll free number is on their website, you can ask them
to send the three volumes, it's free of charge, but they aren't the latest revisions, I believe that they
haven't printed them yet.

Volume 1 will give you the needed basic understanding of the x86 processors, but it is mostly about
the protected mode, however I think the 3 vol. set manuals from Intel is the best reference.
 
Eric
  • Guest
Reply with quote
Post Posted: Thu Aug 05, 1999 3:48 pm
Quote
> Go to /design/PentiumII/manuals, and download the 3 volume (3 pdf files in fact!) Developer's Manual.
> You can also call Intel's Literature Center, the toll free number is on their website, you can ask them
> to send the three volumes, it's free of charge, but they aren't the latest revisions, I believe that they
> haven't printed them yet.

> Volume 1 will give you the needed basic understanding of the x86 processors, but it is mostly about
> the protected mode, however I think the 3 vol. set manuals from Intel is the best reference.

You can also get the Pentium III manuals: http://developer.intel.com/design/pentiumiii/manuals/

Volume 3 is the best reference. However, anyone unfamiliar with x86 assembly language should definitely read through Volume 1 first.

Understand, though, that these documents are not meant to teach assembly language. They are reference manuals.

Good luck.

Eric
 
  • Joined: 29 Jun 1999
  • Posts: 68
  • Location: Houston TX
Reply with quote
Post Posted: Thu Aug 05, 1999 9:33 pm
Quote
> I never knew you had to plug in which type of processor you were writing under. This whole time
> I've been using plain 8086 when I could have been using .286 and .386. Thanks a lot. I couldn't
> understand what I was doing wrong.

It prevents you from using illegal or advanced instructions. If you want to write for the 8086/8088 it would keep you from writing bad programs by using unsupported instructions.

And always remember, once you think you know assembly, there's always more to learn... Pipeline stalls, instruction interleaving, instruction prefixes.
  View user's profile Send private message Visit poster's website
Lin Ke-Fong
  • Guest
Reply with quote
Post Posted: Thu Aug 05, 1999 10:46 pm
[x86 programming documentations]
Quote
> > Volume 1 will give you the needed basic understanding of the x86 processors, but it is mostly about
> > the protected mode, however I think the 3 vol. set manuals from Intel is the best reference.
> You can also get the Pentium III manuals: http://developer.intel.com/design/pentiumiii/manuals/

Well actually they link to the same pdf files.
Too bad that the printed version is not up to date :(
 
Reply to topic



Back to the top of this page

Back to SMS Power!