-1

This is the structure of my project :

  • "boot.asm" : enters 64-bit mode, make a CHS read and load "kernel" to 0x100000, then jmp to 0x100000
  • "kernel.asm"

This is "kernel.asm" :

   [bits 64]
   msg:   db      "K"
   mov al, [msg]
   mov ah, 3 ; cyan
   mov word [0xb8000], ax
   jmp $

This code works when is put in "boot.asm". But only prints strange glyphs or an "S" when is put in "kernel.asm"... I don't know why. The problem seems to be with "msg" declaration. For example, when I replace " msg: db "K" " by " msg equ "K" " then it prints the good char, I can't figure out the problem, do you have any suggestions ?

Cheers,

user3166684
  • 199
  • 2
  • 7
  • 1
    I have a feeling of _deja vu_ I could have sworn I have answered this question recently ... anyway, you need to move the `msg` declaration out of the execution path because as it is, the poor cpu tries to execute it as code. For example, move it to after the `jmp $`. – Jester Nov 25 '14 at 19:24
  • @Jester :) This is not a dejà vu, I just made other tries with the code, but the problem is still the same when I move 'msg' declaration after the 'jmp $' – user3166684 Nov 25 '14 at 19:58
  • 1
    That probably means the actual load address and the address the assembler used are different. You could try `mov al, [rel msg]`, if that fixes it the problem was certainly the address mismatch. – Jester Nov 25 '14 at 20:56
  • @Jester: Thanks a lot Jester !! You're definitely the one who rescue my little project ! – user3166684 Nov 25 '14 at 21:04

2 Answers2

0

You have forgot to do a jump over msg. Unless the program performs a jump over msg, msg will be interpreted as a command. Try the following code:

[bits 64]
jmp start
msg:   db      "K"
start:
mov al, [msg]
mov ah, 3 ; cyan
mov word [0xb8000], ax
jmp $
Van Uitkon
  • 356
  • 1
  • 6
0

SOLVED : The solution is just to put [org 0x100000] in kernel.asm to mention nasm where to put code, so that it's sure all memory access are in absolut addressing.

user3166684
  • 199
  • 2
  • 7