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.
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:
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?
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?
[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.
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: