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

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
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

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

Post 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.
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post 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
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post 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!
C8H10N4O2 | #446691 | Trust the nodes.
Post Reply