how to print a space in protected mode?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
beyondsociety

how to print a space in protected mode?

Post 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
Schol-R-LEA

Re:how to print a space in protected mode?

Post 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.
beyondsociety

Re:how to print a space in protected mode?

Post 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
Slasher

Re:how to print a space in protected mode?

Post 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
beyondsociety

Re:how to print a space in protected mode?

Post by beyondsociety »

Thanks!, Im going to see if it works, and then I'll get back to you.
beyondsociety

Re:how to print a space in protected mode?

Post 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!
Slasher

Re:how to print a space in protected mode?

Post by Slasher »

The
add [yposition],1
and
inc byte [yposition]
do the same thing but inc takes less bytes (i think ;D )
Post Reply