Page 1 of 1
how to print a space in protected mode?
Posted: Fri Sep 27, 2002 8:21 pm
by beyondsociety
I originally had some code that would let me create a space for each message in real mode. I am now in protected mode and want to do the same thing.
How would I do this?
Heres the code I used before:
newline:
push ax ; pushes the stack onto the ax register
mov ah,0x0E ; set function to teletype mode
mov al,0x0D ; load a carriage return
int 0x10 ; and print it
mov al,0x0A ; load a line feed
int 0x10 ; and print it
ret ; return
Re:how to print a space in protected mode?
Posted: Sat Sep 28, 2002 10:48 pm
by Schol-R-LEA
beyondsociety wrote:
I originally had some code that would let me create a space for each message in real mode. I am now in protected mode and want to do the same thing. How would I do this?
Basically, what you need to to do is reset the cursor horizonal to zero (a carriage return, in other words) and the increment the cursor vertical by one (a line feed). Assuming the print32 function from your earlier post, you could just use the following macro, which behaves more or less as the old version did:
Code: Select all
CR equ 0x0A ; carriage return
LF equ 0x0D ; line feed
%macro newline 0
push ax
mov al, CR ; leave atribute as is, set 'character' to CR
call print32
mov al, LF ; perform a line feed
call print32
pop ax
%endmacro
However, this would be both moreefficient and less likely to cause side effects:
Code: Select all
newline:
mov [xposition], 0
inc byte [yposition]
call hardware_move_cursor
ret
This could have been a macro, too, but it would mean exposing the xposition and yposition variables, so it is better to code it as a function.
BTW, I noticed that your own code you consistently use "ADD byte [yposition], 1" rather than "INC byte [yposition]". Was there any particular reason for that? Just curious.
Re:how to print a space in protected mode?
Posted: Sun Sep 29, 2002 11:36 am
by beyondsociety
when I use this:
newline:
mov [xposition], 0
inc byte [yposition]
call hardware_move_cursor
ret
Nasm complains about a operation size not specified with this line. Why is this?
mov [xposition],0
Re:how to print a space in protected mode?
Posted: Sun Sep 29, 2002 11:45 am
by Slasher
add byte before the 0
eg
if xposition is defined as a byte in your code
xposition db 0
then it should be
mov [xposition],byte 0
if its a word dw 0
then mov [xposition],word 0
etc ;D
Re:how to print a space in protected mode?
Posted: Sun Sep 29, 2002 11:50 am
by beyondsociety
Thanks!, Im going to see if it works, and then I'll get back to you.
Re:how to print a space in protected mode?
Posted: Sun Sep 29, 2002 12:00 pm
by beyondsociety
It works, thanks codeslasher!
Schol-R-LEA, I dont know why I used [add byte [yposition],1. Whats the difference between the two?
Thanks for your help!
Re:how to print a space in protected mode?
Posted: Sun Sep 29, 2002 12:05 pm
by Slasher
The
add [yposition],1
and
inc byte [yposition]
do the same thing but inc takes less bytes (i think ;D )