Page 1 of 2
VGA Problem
Posted: Fri Sep 21, 2007 7:17 pm
by matias_beretta
Hello
Code: Select all
int_33:
push 0xb800
pop es
mov di, [XY]
mov [es:di], ax
add ax, 2
mov [XY], di
ret
XY: ;-> OFFSET
dw 0
How can I put a carriage return?
Re: VGA Problem
Posted: Fri Sep 21, 2007 7:20 pm
by raevin
matias_beretta wrote:Hello
Code: Select all
int_33:
push 0xb800
pop es
mov di, [XY]
mov [es:di], ax
add ax, 2
mov [XY], di
ret
XY: ;-> OFFSET
dw 0
How can I put a carriage return?
Well, wouldn't it be better if you break it off into two components...one X, another Y, and just increment Y for the carriage return?
Reply
Posted: Sat Sep 22, 2007 11:48 am
by matias_beretta
Is there any way of doing it without X and Y variables??????
Re: Reply
Posted: Sat Sep 22, 2007 11:59 am
by raevin
matias_beretta wrote:Is there any way of doing it without X and Y variables??????
Not exactly sure...don't think so, but I could be wrong.
Why do you want to make this harder than it actually is?
Reply
Posted: Sat Sep 22, 2007 12:00 pm
by matias_beretta
i just wanted to know... thanks
Posted: Sat Sep 22, 2007 1:31 pm
by bewing
You CAN do it with just one variable, but you would have to calculate the modulus of XY and 160, and then subtract from XY. Modulus is a VERY slow calculation, and I would not recommend it.
Reply
Posted: Sat Sep 22, 2007 6:51 pm
by matias_beretta
I don't understand this of the module.. Can you explain me??
Posted: Sat Sep 22, 2007 8:01 pm
by matias_beretta
please answer!!!!!
Posted: Sat Sep 22, 2007 8:43 pm
by raevin
matias_beretta wrote:please answer!!!!!
1) Chill...not everyone is on the boards 24/7...sheesh.
2) It's MODULUS, not MODULE...there's a difference...BIG difference in this case.
3) Modulus is dividing a number, and having the return value being the remainder.
4) Example: 5/4 = 1.25, so the modulus (returned value) will be 25.
5) You're welcome.
Posted: Sat Sep 22, 2007 9:15 pm
by Fear
Wouldn't 5 mod 4 be 1, not 25...
Posted: Sat Sep 22, 2007 9:40 pm
by pcmattman
raevin wrote:4) Example: 5/4 = 1.25, so the modulus (returned value) will be 25.
Wrong. That's the mantissa.
I have a 5 pizzas, with 4 people. How many pizzas do I have left over if everyone gets 1? That's what the remainder is. Remainder == modulus.
Posted: Sun Sep 23, 2007 12:29 am
by bewing
Yes, when you are operating in the 0xb8000 vga text memory, each line is 160 bytes long. Your variable XY seems to be the offset from 0xb8000. If you want to know how many lines down you are on the screen, you would do XY / 160, and store the number in a register. In C, the modulus operator is shown as %. It gives the "remainder" after a division operation. So, if the value of XY is 180, then XY / 160 = 1, and XY % 160 = 20. You would be on line #1 (if the top line is called line #0), and you would be at a horizontal offset of 20 on that line. If you wanted to move back to the beginning of the line, you could do: XY - (XY % 160).
On intel clone machines (which you are obviously on), the DIV opcode gives you both the dividend and the remainder (modulus).
Code: Select all
xor edx, edx ; need edx = 0
mov eax, [XY] ; number to divide
mov ebx, 160 ; divide by this
div ebx ; divides the qword edx:eax by ebx
sub [XY], edx ; modulus (remainder) gets stored in edx
but as I said -- the DIV opcode is VERY SLOW. Usually 20 times slower than any other opcode on the machine. You do not want to use it often if you can help it at all.
This code would move your "pointer" back to the beginning of the current line of text. Then if you want to move down a line, add 160.
thanks
Posted: Sun Sep 23, 2007 6:39 am
by matias_beretta
thanks , this helped me a lot, but remember, my os is just a real mode hobby os... so speed doesn't mind for me
Posted: Sun Sep 23, 2007 11:01 am
by JAAman
but as I said -- the DIV opcode is VERY SLOW. Usually 20 times slower than any other opcode on the machine. You do not want to use it often if you can help it at all.
only if you have a very old CPU...
on current CPUs
all ALU instructions can execute in a single cycle (iirc prescott can execute 8 DIV instructions in a single cycle...)
Posted: Sun Sep 23, 2007 2:22 pm
by bewing
AFAIK div instructions are pipelined -- that is, you get the result 8 (for example) clock cycles after you begin processing the opcode -- it's just that the CPU can perform 8 of them at the same time, each at a different point in the pipeline process.
Mathematically, division is a "guessing game". It is not as nicely (straightforwardly) deterministic as the other binary operators.