flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Printing a character

Author
Thread Post new topic Reply to topic
manfred



Joined: 28 Feb 2009
Posts: 43
Location: Racibórz, Poland
manfred
Hello!

I'm trying to print character in protected mode, but character doesn't print. I noticed that the value ecx is incorrect (for example 0xf000fea5, what isn't value of video_mem variable).

Code:
Code:
format BINARY

include './macros.inc'

use32
kmain:
  mov al, 'a'
  mov ah, 7
  call putc
  jmp $
  
; void putc(al = char, ah = color)  
putc:
  mov ecx, dword [ds:video_mem]
  mov [ecx], al
  mov [ecx + 1], ah
  add dword [ds:video_mem], 2
  ret

;data
  video_mem dd 0B8000h    

_________________
Sorry for my English...
Post 07 Mar 2009, 18:07
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17719
Location: In your JS exploiting you and your system
revolution
Are you using a 32bit OS? You need a 32bit OS to use native 32bit instructions.
Post 07 Mar 2009, 18:31
View user's profile Send private message Visit poster's website Reply with quote
manfred



Joined: 28 Feb 2009
Posts: 43
Location: Racibórz, Poland
manfred
32bit OS? I don't understand... I've entered into protected mode in bootloader and jumped to kernel... Other 32-bit instructions works. If i write ie. something like that:
Code:
mov ecx, 0xB8000
mov byte [ecx], 'a'
mov byte [ecx+1], 7    
it works. Only that one value is incorrect. Or, if you talking about this, I'm compiling under 32bit OS...

_________________
Sorry for my English...
Post 07 Mar 2009, 20:59
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17719
Location: In your JS exploiting you and your system
revolution
Okay, if you are in 32bit protected mode then that is fine.

You can check out that your ds segment is setup to map 1:1 with the cs segment and also that the memory you are accessing is in the paging tables.
Post 08 Mar 2009, 00:23
View user's profile Send private message Visit poster's website Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos
Code:
  mov ecx, dword [ds:video_mem]
  ...
  add dword [ds:video_mem], 2
  ...
  video_mem dd 0B8000h    
What it means? Usually character output is made relative to cursor position. Additionally, you are using video_mem variable, but I don't see where you defined the starting displacement (using ORG directive).
Post 08 Mar 2009, 09:11
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3056
Location: vpcmipstrm
bitRAKE
DS is the default segment.
What does your GDT look like?
What has been loaded into DS?
Post 08 Mar 2009, 10:32
View user's profile Send private message Visit poster's website Reply with quote
manfred



Joined: 28 Feb 2009
Posts: 43
Location: Racibórz, Poland
manfred
After setting origin it works. Thanks egos!

_________________
Sorry for my English...
Post 08 Mar 2009, 10:34
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.