Question:
Assembly Text Hardware IO?
Francis R
2011-06-14 20:13:47 UTC
Hi

I am new to assembly programming. Finally after reading about at least the first 3 or 4 chapters of about 10 different books I got to a stage where I can put "Hello World" on a dosbox console using MASM 6.11. Imagine my delight!!

The first version of my program used DOS Function 13h.
The second version of my program used BIOS Function 10h

I now want to do the third version using direct hardware output. I have read the parts of the books that explain the screen is divided into 80x25 on a VGA (not bothered about detecting CGA and all that so program uses memory address 0B800h for colour VGA, DOSBox being great and all, and my desire to move to Win Assembler sometime before im 90 years old) monitors. I have read that each character on the hardware screen is 2 bytes (1 for the attribute and one for the character itself, therefore you have 80x25x2=4000 bytes).

But my problem is this. No matter how I try, I cant get my program to output a simple black and white (which is just the attribute, I assume I can change this reasonably easily) string (which is just an array of bytes) 5 lines from the top of the screen, and 20 characters in from the left edge (which is just the number of blank characters away from a zero based index with 4000 bytes long).

How do I separate the attribute from the character (I got it to work partially but it only shows every second character, then a bunch of random junk (thats how I figured I need some sort of byte pair for the attribute and text), or how do I set it up such that both are recognised together or how is that done. How do I control he position of the text on the screen. Where am I going wrong.

I have tried looking around the web for this seemingly simple question but am unable to find a solution. Is there anyone who used to program in DOS and x86 Assembly that can tell me how to do this easy little program by not using BIOS or DOS functions, just with the hardware.

I would really appreicate a simple code snippet if possible. Or a refrence to some site or free e-book. I dont want buying a big book on dos console programming which will end up useless when I move to windows shortly. The only reason I am focused on this is because I want to learn true assembly, not some macro language or some pretensious high level language that claims to be assembly.

I am trying to build a library of routines that will make Assembly easier to learn so people dont have to work though all the 3 to 6 chapters across 10 books of theory esentially explaining again and again the same stuff when really all that is needed is enough to know how to get some output, assign values to variables, get some input, and do some loops and decisions. The theory can come along later, and by the time they get to loops and decisions most people will have done enough assembler to have all the theory anyway.

Can anyone out there please help!!
Three answers:
husoski
2011-06-14 22:23:18 UTC
It looks like you're getting access to at least an emulated video card. The area at B800:0000 is indeed the screen memory buffer when running in a CGA or CGA-compatible mode on an EGA, VGA, MCGA, etc. Each screen position is TWO bytes...one for the character and one for the character attributes. The characters are at even addresses, and the attributes are at odd addresses. For CGA mode, the attribute byte is:



bits 3,2,1,0 : character color in IRGB form

bits 6,5,4 : RGB background color

bit 7 : Either the I (bright) bit for the background color or blinking foreground



The one-bit RGB values are:

0=black, 1=blue, 2=green, 3=cyan, 4=red, 5=magenta, 6=yellow, 7=light gray



If the I bit is set (codes 8-15 instead of 0-7) then all the colors are "bright", with "bright black" (8) being "dark gray" and "bright light gray" (15) being "white".



The default hardware setting is for bit 7 to be a "blink" bit instead of the background I bit. Under WInXP, using CMD in a windowed console, the bit is always a bright bit (it's hard to blink in bitmapped raster graphics modes). In full-screen mode, it's sometimes bright and sometimes blink. You have been warned. I don't recall the hardware OUTs required to do a switch, or if there's a BIOS interrupt to do it and make it "stick".



Be aware that this is NOT truly "direct hardware access" unless you are running a real-mode OS like MS-DOS or FreeDOS. You do get a little of the flavor of programming back in the 8086 days, though...
2016-04-14 07:00:41 UTC
I'd assume gedit is already included in Ubuntu. vi surely is. If not, use your package installer app on the desktop. vi works everywhere, even on stupid old terminals over dialup modems. gedit needs a graphical console. emacs is more powerful and popular with many programmers. vi (vim) and emacs may have features to colour comments, auto-indent code blocks etc. Which may help, or be distracting when you are just starting.
Laurence I
2011-06-15 04:34:45 UTC
You can look on amazon for a book to help you

then find the sellers website and they usually have examples

its a good idea to buy a book they often give you clues to how not to do things!



alternatively i did this search on inet

"vga memory programming"



and i liked the look of the very first hit so here it is



http://www.brackeen.com/vga/basics.html


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...