Page 1 of 1

Assembly Woes in Simple Put_char Function......

Posted: Mon Apr 02, 2007 7:57 pm
by Alboin
I'm working on creating a HAL type layer for my OS that communicates directly with the hardware, and creates a base layer for a C based layer above it. However.....My assembly is somewhat failing me at the moment and I have not been able to figure out what's wrong...This is what I've been working with:

Code: Select all

use32

;This is our main; My boot loader jumps here.
main:
     mov al, 'S'
     call print_char

     mov al, 'W'
     call print_char

     hang:
           jmp hang

;This keeps track of where we are on the screen....
char_place: dd 0xb8000, 0

; Print the char in al
; This takes the char to print in al.
print_char:
	push ebx
	push edx
	
	; Load the address.
	xor ebx, ebx
	mov ebx, [char_place]
	
	; Move the data in.
	mov byte [ebx], al
	inc ebx 
	mov byte [ebx], 7
	inc ebx
	
	; Advance our place
	mov dword [char_place], ebx
	
	; Pop!
	pop edx
	pop ebx
	ret
I am using fasm...and bochs for testing.

At the moment it doesn't print anything.
Any ideas?

Thanks.

Posted: Mon Apr 02, 2007 8:29 pm
by XCHG
That code must work. Check the Base Address bits of your Data Segment in the Global Descriptor Table and make sure that those bits are all zero. That way you will get your Protected Flat memory and you will be able to address 0x000B8000 as it is.

And while we are at it, why not something like this?

Code: Select all

[BITS 32]
[SECTION .text]
  ; -------------------
  char_place        DD        0x000B8000
  ; -------------------
  %DEFINE PTR
  %DEFINE OFFSET
  ; -------------------
  __PrintChar:
    ; __PrintChar (EAX = Character); FastCall;
    PUSH    EAX                             ; Push the accumulator onto the stack
    PUSH    EBX                             ; Push the base index onto the stack
    MOV     EBX , DWORD PTR [char_place]    ; Get the segment
    MOV     AH , 0x07                       ; AH = Back/Foreground color
    MOV     WORD PTR [EBX] , AX             ; EBX = Pointer, move to it
    ADD     DWORD PTR [char_place] , 0x02   ; Adjust the cursor
    POP     EBX                             ; Restore the base index
    POP     EAX                             ; Restore the accumulator
    RET                                     ; Return to the calling procedure

Posted: Mon Apr 02, 2007 8:39 pm
by Alboin
XCHG wrote:That code must work. Check the Base Address bits of your Data Segment in the Global Descriptor Table and make sure that those bits are all zero. That way you will get your Protected Flat memory and you will be able to address 0x000B8000 as it is.
Oh....ah.....Aha! Okay...I went through what little code I currently have and found that I had forgotten one line:

Code: Select all

org 0x100000
I wasn't aware that this was necessary, but I guess I forgot that I'm no longer using a linker which does this for me. :wink:

Thanks XCHG!