Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginner's problem

Status
Not open for further replies.

popohoma

Programmer
Oct 20, 2002
5
US
Hi everybody,

I am a beginner of assembly language. I have a hard time to program this things. My professor ask me to write a program which can display all the ASCII code(from 0 to 255). I try to write by myself, however, I have no clue how it works. Here is my program(not finish yet).

;Beginning of the program

code segment
assume cs:code,ds:code
org 100h
mov ah,0
mov al,3
int 10h

start: mov ax,0B800h
mov es,ax
mov bx,0d
mov ax,0
l:
mov es:[bx],ax
mov byte ptr es:[bx+1],17h
inc bx
inc ax
cmp ax,256
jne l
mov ah,4ch
int 21h
code ends
end start
; end of the program

There are few problems in the program:
1. I want to print out all the ASCII code, however, I only can print half of them. For example, I can see 'B', but not 'C', or I can see
'D', but not 'E'. I guess it's something wrong with the "byte" problem of operand or register???
2. I don't know how to go to another line. It's like "\n" in C++ and Java.
3. The program suppose have white in foreground and blue in background, however, I can see various of strange color with respect to each ASCII code, why is that??

Moreover, I don't know if there is some web site has good resource of how to write beginner's language. I need both tutorial notes and plus good example(program) to support the argument. Please let me know if you have. Thanks for everybody. This is my assignment of my class, it's due on monday, so I hope you guys can help me out as soon as possible. Thanks again.

From Allen
 
well, man, all ur problems come from one source:
in text mode in video mem each byte to display takes 2 bytes: one for ascii, one for attribute.

u keep storing ur AL values once to ascii code, once to attribute. just change:

INC BX to INC BX
INC BX

or ADD BX,02

this must work..

or use ES:DI pair and STOSW command to store the whole of ax and increment DI by 2

concerning new line, definetely there is no new line char when u keep storing byte to video mem directly.
u can change the position setting ur pointer to appropriate value: in 80x25 mode u will have second line at 161 (decimal).

as far as i recall, there are also INT 10 services on this point. finally, if u go up to DOS screen services, many of them (all?) understand CR LF pair (0Dh, 0Ah)

good luck
 
You are directly accessing the screen. You shouldn't be bothering about newlines - you can place anything you want, anywhere!

The general formula for this (in 80-column mode) is:
address = line * 160 + column * 2

So for instance, if you want to print to line 3, column 0, you must point to address 480 to put your character in. The next byte, 481, is the attribute byte for that character.

Take note that the second line starts at address 160 decimal, not 161 - 161 is the attribute byte for that character.

Also, for your problem, I would recommend that you ignore newlines at first. This means that you will print 256 characters on the entire 80-column screen. If you need to, say, print 64 characters a line, that would be more difficult. You must count from 0 to 63 (keeping a register for the index by adding 2), then add 160 to ANOTHER index register while resetting your inner loop index - so you have two indices, or rather one base and one index since you're in 16-bit mode. More advanced technique would be to keep using one index, but the number to be added for each 64-character batch would not be 160.

"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top