Dark Bit Factory & Gravity
PROGRAMMING => Other languages => ASM => Topic started by: Shockwave on September 23, 2007
-
I searched to find some tutorials on the internet to do the most basic thing of all.. Plot a single pixel.
I could not find anything and I realise that a lot of people here like me have either a very basic understanding of asm and would like to know more.
So here is some code that just plots a dot :)
It's written with Fasm.
Now you can plot a dot you can do anything :)
;-------------------------------------------------------------------------------------------
; How to plot a pixel in assembly language.
; Written in Fasm by shockwave ^ s!p
; This is just a very, very basic tutorial
; Yes, it's simple but it needed doing :P
; To help newbies to get something actually drawn on screen.
;-------------------------------------------------------------------------------------------
org 100h ; Set up mode 13h (VGA 320 X 200 ).
mov ax,13h
int 10h
;-------------------------------------------------------------------------------------------
colour db 10 ; Colour number (byte).
xposi dw 120 ; Xpos to plot (word).
yposi dw 120 ; Ypos to plot (word).
main: ; Main Loop.
;-------------------------------------------------------------------------------------------
plot:
mov ah,0ch ; We need to put 0ch into ah to tell it it's plotting a pixel.
mov al,[colour] ; The square brackets indicate that we load the contents and NOT the address.
mov bh,0 ; Page number.
mov cx,[xposi] ; Put the Xpos to plot into cx.
mov dx,[yposi] ; And the Ypos into dx.
int 10h
;-------------------------------------------------------------------------------------------
in al,60h ; Escape Pressed?
dec al
jnz main ; If not, go back to main.
;-------------------------------------------------------------------------------------------
mov ax, 4c00h ; Put things back to normal so we don't get an error on exit.
int 21h
-
please note that its old 16 bit coding... and 13h screenmode, which is not up to date... its nothing you can use for DX, OGL or something... so i think its nearly useless today... probally only usefull if someone still code DOS 13h mode related stuff...
-
You are wrong there. Plenty of 256 byte intros are released in 13h.
-
And in fact it's something I am very interested in doing for myself... Ok, the best tiny code intros use GL + DX, but unless I am mistaked, there is absolutely no way to initialise DX or GL in 256 bytes and it's this discipline of code that I am really interested in exploring.
If you think it is outdated, go to intro-inferno and search for anything by wamma.
-
ah, if its for 256 byte intro then i have nothing said ^^
-
I really think that Tiny code is having a huge revival.
The cutting edge stuff at 1-4kb is being done by guys like Chris, Mentor and Rbraz, there is a whole culture of sceneres who write things in <512 bytes, like yObi, Pirx, Tigrou, etc etc..
For me, it seems logical to explore this, because I have a lot of interest in pixel bashing :)
-
I agree there is plenty of life left in DOS tiny code is the only way to get demos down to tiny size. I was very impressed by the tiny code over at Intro Inferno
-
OK on this subject, lets say I've decided to dance with the devil and would like to spend the next year learning assembler. Specifically I want to add 32 bit (windows) ASM to my windows C programs. OK given that...can anyone recommend a _good_ book on learning ASM? The top rated book at amazon is geared towards GCC which is not my interest right now.
Chris
-
@Chris:
Some years ago I also tried to learn some assembly and searched in our library
for some printed books. Didn't really find something interesting. Here are some
tutorials in the internet - which I bookmarked. The best thing I can recommend
is the e-book by Dr.Paul Carter. This was really useful for me and I printed this
out. But I guess this might be far too basic (especially the first chapters) for you.
Anyway, here are some links :
http://www.drpaulcarter.com/pcasm/ (http://www.drpaulcarter.com/pcasm/)
http://www.df.lth.se/~john_e/fr_contrib.html (http://www.df.lth.se/~john_e/fr_contrib.html)
http://www.csn.ul.ie/~darkstar/assembler/ (http://www.csn.ul.ie/~darkstar/assembler/)
-
Download the manuals from Intel. http://www.intel.com/products/processor/manuals/index.htm (http://www.intel.com/products/processor/manuals/index.htm)
Intel® 64 and IA-32 Architectures Software Developer's Manual, Volumes 1,2A,2B,3A,3B contain everything about the Intel CPUs.
Next thing then is to look up Windows ABI, so you can call the functions in there.
You're looking for stdcall if you want to call Windows stuff.
http://www.programmersheaven.com/2/Calling-conventions (http://www.programmersheaven.com/2/Calling-conventions)
Jim
-
All I have done is look at a few simple tutorials about the registers and interrupts, I guess I'll be looking at the manuals that jim suggested myself as a next step.
-
Interrupts, all of them http://www.ctyme.com/rbrown.htm (http://www.ctyme.com/rbrown.htm) :)
Jim
-
sweet shockwave!
i have a wierd issue though, maybe its just something that isnt supposed to be done...
if i add,
add [colour], 1
and/or
inc [xposi]
it works, but i cannot exit. is that because its looping too much or overflowing the memory or something?
thanks for the help guys
donvito
-
I can't see how that program works at all ???
Won't the data variables be interpreted as opcodes, and executed as such when control returns from initial int 10h ?
I think maybe a jmp over them is needed, or locate them after the executable code.
-
Well spotted Smith I think you got it
-
hmm thats wierd...
i dont really fully understand the code, but if you inc the color or coords, it will make a cool looking "bars" effect. its just wierd because i was in class and i tried that and it worked without a lockup, but on my comp at home, it locked up hard, and i had to do a hard-reboot.
donvito
-
There's a bug in there as Agent Smith says. You need to add 'jmp main' after 'int 10h', and then you need to make sure you modify the colour in the right place ie.
;-------------------------------------------------------------------------------------------
; How to plot a pixel in assembly language.
; Written in Fasm by shockwave ^ s!p
; This is just a very, very basic tutorial
; Yes, it's simple but it needed doing :P
; To help newbies to get something actually drawn on screen.
;-------------------------------------------------------------------------------------------
org 100h ; Set up mode 13h (VGA 320 X 200 ).
mov ax,13h
int 10h
jmp main ;Jim added this else it executes the data below as instructions!
;-------------------------------------------------------------------------------------------
colour db 10 ; Colour number (byte).
xposi dw 120 ; Xpos to plot (word).
yposi dw 120 ; Ypos to plot (word).
main: ; Main Loop.
;-------------------------------------------------------------------------------------------
plot:
mov ah,0ch ; We need to put 0ch into ah to tell it it's plotting a pixel.
mov al,[colour] ; The square brackets indicate that we load the contents and NOT the address.
mov bh,0 ; Page number.
mov cx,[xposi] ; Put the Xpos to plot into cx.
mov dx,[yposi] ; And the Ypos into dx.
int 10h
;Jim - modify the colour values here. If you do it later you will not be able to exit properly.
;-------------------------------------------------------------------------------------------
in al,60h ; Escape Pressed?
dec al
jnz main ; If not, go back to main.
;-------------------------------------------------------------------------------------------
mov ax, 4c00h ; Put things back to normal so we don't get an error on exit.
int 21h
Jim
-
If you just wanna have a look at asm I suggest looking up emu8086
http://www.emu8086.com/
comes with lotsa examples and a great debugger (one of the best debugger around) sadly it doesnt support 32bit instructions but its a nice easy sandbox to learn basic asm stuff. If you still like it try FASM.
The advantage with emu8086 for learning is that you can run each instruction examine what has happened then run the next instruction so you will soon see what is going wrong