Page 1 of 1
Pmode print in asm
Posted: Sun Feb 27, 2005 12:00 am
by kattmat
Hey there!
I have been playing around with making OSs for a little while now. Made my own 16bit prompt which could handle some commands and stuff.
Now I'm going to do the same thing in protected mode, but with more features.
It's all written in ASM (I know C, but I want to learn the pure basics), and there is a problem I've had for like a week now and still haven't been able to solve:
How to print stuff to the screen from ASM?
Code: Select all
mov si, MyString
call Print
nop
Print:
pusha
.NextChar:
lodsb
mov byte [0xB8000+bx], al
inc bx
mov byte [0xB8000+bx], 0x07
cmp al, al
jz .Return
jmp .NextChar
.Return
popa
ret
That stuff just doesn't work.. No output to the screen whatsoever..[/code]
Re: Pmode print in asm
Posted: Sun Feb 27, 2005 12:00 am
by bubach
< swedish >hej kattmat</ swedish >
I guess that you are from sweden with that name.
You can have a look on my source to see how i have done it..
http://bos.asmhackers.net/
Re: Pmode print in asm
Posted: Sun Feb 27, 2005 12:00 am
by kattmat
<Swedish> Bingo-lingo. =) Kul att det finns svenskar som h?ller p? och meckar! </Swedish>
I'll check it out. I guess it'll work out just fine. Cheers!
Re: Pmode print in asm
Posted: Sat Mar 05, 2005 12:00 am
by kattmat
Okey, I have been trying and trying and trying now, without any success whatsoever.
The cls (clearscreen) function works just fine, but none of the print functions work at all.
What's wrong?
I'm compiling with nasm, but the only difference as far as I can tell is
use32 -> [BITS 32]
org xxx -> [ORG xxx]
Help!
Re: Pmode print in asm
Posted: Sat Mar 05, 2005 12:00 am
by kattmat
Code: Select all
print:
push ax
push bx
push eax
mov bh, al
mov eax, 0x00
.displaychar:
lodsb
or al, al
jz .done
mov [(eax*2) + 0xB8000], al
mov [(eax*2) + 0xB8001], bh
inc eax
jmp .displaychar
.done:
pop eax
pop bx
pop ax
ret
Why isn't it working?[/code]
Re: Pmode print in asm
Posted: Mon Mar 14, 2005 12:00 am
by frizzz
I just published my own assembler OS. You will find there a lot of examples, how to write to the screen in VGA3-mode. Look at my homepage:
www.rcfriz.de
But in fact it is very simple:
mov ax,[attribute_and_letter] ; attribute is H-byte
mov WORD [es:esi+0B800h],ax ;...and You will see it
You need to store a selector in es, which adresses a descriptor with absolute startadress 0
The value in esi ranges from 0...0F00h
... seems to me, that You forgot the selector in es...
Re: Pmode print in asm
Posted: Tue Mar 15, 2005 12:00 am
by bubach
I took a break from osdev for about 6 months becasue i couldn't get my text output to work, so you are not alone!
First you will need some way of handling where the cursor is on the screen. In my example code I'll just have a variable which contains the cursor position.
You should have "get_cursor" and "set_cursor" functions later on (to update the cursor on screen, not only your variable)...
Then you move the content of bx, which is char and color, to the adress of the cursor position that you have stored multiplied with 2 (1 byte char+1 byte attribute=cursor position*2) + 0xB8000 which is the text mode memory.
Formula: (cursor position*2)+0xB8000=char+attribute
Example:
Code: Select all
cursor_offset dw 0
;-----------------------------------------;
; print char ;
; in: bl = char, bh = attrib ;
;-----------------------------------------;
print_char:
push eax
cmp bl, 13
jne .cont
; call new_line ; This is where you should call your "new_line"
jmp .done
.cont:
cmp bl, 10 ; ignore
je .done
mov ax, word [cursor_offset] ; somehow get the cursor
; position and add it to eax
mov [es:(eax*2 + 0xB8000)], bx
add [cursor_offset], 1 ; add 1 to cursor position
.done:
pop eax
ret
To test this code you do like this:
Code: Select all
mov bh, 0x07
mov bl, 'T'
call print_char
mov bh, 0x07
mov bl, 'e'
call print_char
mov bh, 0x07
mov bl, 's'
call print_char
mov bh, 0x07
mov bl, 't'
call print_char
I hope that it helps you..
/ Christoffer
Re: Pmode print in asm
Posted: Wed Mar 16, 2005 12:00 am
by bubach
Another note:
Code: Select all
print:
push ax
push bx
push eax
mov bh, al
mov eax, 0x00
.displaychar:
push eax ; added: save eax
lodsb ;this gets a byte from esi and puts it
or al, al ; into al, which mess up the cursor position
jz .done ;better save and restore eax....
mov bl, al ; added: move value to bl instead of al
pop eax ; added: restore cursor position
mov [(eax*2) + 0xB8000], bx ; like this
inc eax
jmp .displaychar
.done:
pop eax
pop bx
pop ax
ret