this is part of my code that works fine.

org 0x8000    ; code's start offset
    ; 16 Bit Code
..
..
..
..
mov si, msg_help
call _out_print_si 
   
mov si, msg_xdump_start
call _out_print_si 
..
..
..
_out_print_si:
  lodsb       
 
  or al, al 
  jz .done 

  mov ah, 0x0E 
  mov bh, 0x00 
  mov bl, 0x00 
  int 0x10     

  jmp _out_print_si
 
.done:
  ret
  ..
  ..
  ..
  ..
  welcome          db 'Welcome to OSX - Operation System !', 0x0D, 0x0A, 0
  copyright        db 'Patrick Carvalho - Copyright 2009', 0x0D, 0x0A, 0
  msg_helloworld  db 'OSX - Operation System!', 0x0D, 0x0A, 0
  badcommand      db 'Command Unknown.', 0x0D, 0x0A, 0
  prompt          db '>', 0
  cmd_hi          db 'hi', 0
  cmd_help        db 'help', 0
  cmd_shutdown   db 'shutdown', 0
  cmd_clear   db 'clear', 0
  cmd_load_a   db 'load a', 0
  msg_xdump_start  db 'xDump Registers', 0x0D, 0x0A, 0
  msg_help        db 'My OS: Commands: hi, help', 0x0D, 0x0A, 0     
  buffer times 32  db 0



For this code above the output is:
"My OS: Commands: hi, help
xDump Registers"

Everything OK !!

but if i add this:
msg_xdump_reg1  db 'AX = 0000 BX = 0000 CX = 0000', 0x0D, 0x0A, 0

this way:
  ...
  msg_xdump_start  db 'xDump Registers', 0x0D, 0x0A, 0
  msg_xdump_reg1  db 'AX = 0000 BX = 0000 CX = 0000', 0x0D, 0x0A, 0
  msg_help        db 'My OS: Commands: hi, help', 0x0D, 0x0A, 0 
  ...

so.. the output is:
"My OS: CommxDump Registers"

Why??
Posted on 2009-04-14 15:51:25 by patrickniceboy
Is there any limit for variable declaration ??

becuase to me it looks like i can use just for example 8 bytes...or something like this, so i can just use 8 vars.
just an example.
Posted on 2009-04-15 23:41:25 by patrickniceboy
What OS and libraries are you using exactly?
It appears you are using 16-bit, but the functions like _out_print_si aren't familiar to me. It's not DOS at any rate.
Posted on 2009-04-16 06:13:24 by Scali
1) You didn't post the complete source (at least the essential part). This aggravates analyzing.
2) You are using a "non-standard"-assembler (according to the hex digits: "0x??" instead of "??h")

For me there are two causes of failures:
1) The assembler has a bug.
2) Segment registers are messed up.

Recommendation: Try to create a binary with a different offset which can be run by an independent debugger, then debug your binary step-by-step with this debugger.
Posted on 2009-04-16 14:52:57 by TasmDev

1) You didn't post the complete source (at least the essential part). This aggravates analyzing.
2) You are using a "non-standard"-assembler (according to the hex digits: "0x??" instead of "??h")

For me there are two causes of failures:
1) The assembler has a bug.
2) Segment registers are messed up.

Recommendation: Try to create a binary with a different offset which can be run by an independent debugger, then debug your binary step-by-step with this debugger.


I thought NASM allowed us to use 0x... That's what I was doing with NASM before. I don't know if it has changed now.

From this bit of code:

org 0x8000    ; code's start offset
    ; 16 Bit Code

I am actually pretty sure it is NASM.
Posted on 2009-04-17 06:30:34 by XCHG
maybe part of msg_help gets pushed off to the next sector because you're adding msg_xdump_start before it and you aren't loading that sector when you load the file into memory?
Posted on 2009-04-17 07:48:39 by lone_samurai5
how can i read a sector?
Posted on 2009-04-17 14:15:37 by patrickniceboy

What OS and libraries are you using exactly?
It appears you are using 16-bit, but the functions like _out_print_si aren't familiar to me. It's not DOS at any rate.


It's my own function to print a string, from SI register, it uses int 10 to print !

look:


_out_print_si:
  lodsb       
 
  or al, al 
  jz .done 

  mov ah, 0x0E 
  mov bh, 0x00 
  mov bl, 0x00 
  int 0x10 
Posted on 2009-04-17 14:25:36 by patrickniceboy
post the complete code.. will be easier to look for the problem..
Posted on 2009-04-17 14:43:10 by lone_samurai5
here is boot.asm:

  org 0x7C00  ; set up start address of bootloader

; setup a stack and segment regs ;

    xor ax, ax
    mov ds, ax
    mov es, ax
    mov ss, ax
    mov sp, ax


mov bx, 0x8000    ; set up start address of kernel, the address to save return?
call _sysio_read_floppy

; Kernel
    jmp 0x0000: 0x8000  ; address of kernel. "jmp bx" might also work.

; data   
    times 480-($-$$) db 0 ;hlt
    SIGNATURE DW 0xAA55




now kernel.asm:



org 0x8000    ; code's start offset
    ; 16 Bit Code

SECTION .text ; code section

  xor ax, ax        ; set up segments
  mov es, ax
  mov ds, ax
  mov ss, ax
  mov sp, ax

  mov si, welcome
  call _out_print_si
 
  mov si, copyright
  call _out_print_si

loop:
  ; constant initial words for console
  mov si, prompt
  call _out_print_si

  mov di, buffer
  call get_string

  mov si, buffer
  cmp byte , 0  ; blank line?
  je loop          ; yes, ignore it

  mov si, buffer
  mov di, cmd_hi  ; "hi" command
  call strcmp
  jz .helloworld ;jc

  mov si, buffer
  mov di, cmd_help  ; "help" command
  call strcmp
  jz .help ; jc
 
  mov si, buffer
  mov di, cmd_shutdown ;  shutdown command
  call strcmp
  jz _reboot 
 
  mov si, buffer
  mov di, cmd_clear ;  clear screen command
  call strcmp
  jz _clrscr

  mov si, buffer
  mov di, cmd_load_a ;  load floppy a
  call strcmp
  jz _load_a
   
  ; command not found
  mov si,badcommand
  call _out_print_si
 
  jmp loop 

.helloworld:
  mov si, msg_helloworld
  call _out_print_si
  jmp loop

.help:
  mov si, msg_help
  call _out_print_si
  jmp loop
 

;-----------------------------------------------------------------------------------------

_reboot:
  jmp 0xf000:0xfff0 ; Reboot is this right?
 

_clrscr:
  mov ax, 0x0600
  xor cx, cx
  mov dx, 0x174F
  mov bh, 0x07
  int 0x10
  jmp loop

; ================
; calls start here
; ================

_out_print_si:
  lodsb        ; grab a byte from SI
 
  or al, al  ; logical or AL by itself
  jz .done  ; if the result is zero, get out

  ; VIDEO - TELETYPE OUTPUT,  AL = character to write
  mov ah, 0x0E  ; parameter 
  mov bh, 0x00  ; page number
  mov bl, 0x00  ; foreground color (graphics modes only)
  int 0x10      ; otherwise, print out the character!

  jmp _out_print_si
 
.done:
  ret


_out_print_ah:
push    ax      ; store registers...
push    si      ;

.next_char:
        mov    al,
        cmp    al, 0
        jz      printed
        inc    si
       
; VIDEO - TELETYPE OUTPUT,  AL = character to write
mov ah, 0eh ; teletype function.
mov bh, 0x00  ; page number
mov bl, 0x00  ; foreground color (graphics modes only)
        int    10h

        jmp    .next_char
printed:
pop    si      ; re-store registers...
pop    ax      ;
  ret

 
 


get_string:
  xor cl, cl ; the same character will not be printed again

.loop:
  mov ah, 0
  int 0x16  ; wait for keypress, return = al

  cmp al, 0x08    ; backspace pressed?
  je .backspace  ; yes, handle it

  cmp al, 0x0D  ; enter pressed?
  je .done      ; yes, we're done

  cmp cl, 0x3F  ; 63 chars inputted?
  je .loop      ; yes, only let in backspace and enter

  mov ah, 0x0E
  int 0x10      ; print out character

  stosb  ; put character in buffer
  inc cl
  jmp .loop

.backspace:
  cmp cl, 0 ; beginning of string?
  je .loop ; yes, ignore the key

  dec di
  mov byte , 0 ; delete character
  dec cl ; decrement counter as well

  mov ah, 0x0E
  mov al, 0x08
  int 10h ; backspace on the screen

  mov al, ' '
  int 10h ; blank character out

  mov al, 0x08
  int 10h ; backspace again

  jmp .loop ; go to the main loop

.done:
  mov al, 0 ; null terminator
  stosb

  mov ah, 0x0E
  mov al, 0x0D
  int 0x10
 
  mov al, 0x0A
  int 0x10 ; newline

  ret


_out_newline_feed:
 
  ; cler carry
  mov al, 0x0D
  int 0x10
 
  ; newline
  mov al, 0x0A
  int 0x10  
 
  ret
 
 
 
 
strcmp:
.loop:
  mov al,   ; grab a byte from SI
  mov bl,   ; grab a byte from DI
  cmp al, bl    ; are they equal?
  jne .notequal  ; nope, we're done.

  cmp al, 0  ; are both bytes (they were equal before) null?
  je .done  ; yes, we're done.

  inc di    ; increment DI
  inc si    ; increment SI
  jmp .loop  ; loop!

.notequal:
  clc  ; not equal, clear the carry flag
  ret

.done:
  stc  ; equal, set the carry flag
  ret

SECTION .data ; data section
 
  cmd_load_a   db 'load a', 0
  welcome        db 'Welcome to OSX - Operation System !', 0x0D, 0x0A, 0   
  copyright        db 'Patrick Carvalho - Copyright 2009', 0x0D, 0x0A, 0
  msg_helloworld  db 'OSX - Operation System!', 0x0D, 0x0A, 0
  badcommand      db 'Command Unknown.', 0x0D, 0x0A, 0
  prompt          db '>', 0
  cmd_hi          db 'hi', 0
  cmd_help        db 'help', 0
  cmd_shutdown   db 'shutdown', 0
  cmd_clear   db 'clear', 0
  msg_help        db 'My OS: Commands: hi, help', 0x0D, 0x0A, 0     
 
  buffer times 32  db 0
 
   
; Includes
%include "sysio.asm"
Posted on 2009-04-17 14:58:34 by patrickniceboy
Right off the bat, read-up on the Stack and how to use it.
Posted on 2009-04-17 15:18:59 by SpooK
so the problem is with the stack ?
Posted on 2009-04-17 16:29:23 by patrickniceboy

so the problem is with the stack ?


In general. It probably isn't causing a problem as of yet. Setting SS/SP both to 0, IIRC, should cause a wrap-around to the top of the first 64KB on initial use. If this is intentional, then that is fine. However, if there are any mismatched PUSH/POP sequences, you could start overwriting the IVT. Also, PUSHing too much data will cause the same effect. Keep that in mind if things start to "randomly" fail.

Another thing about traditional MBR's is that they are 512 bytes long, not 482 bytes long. You would want to use times 510-($-$$) db 0.

The above statements were just some general comments. I will take a glance at your code and see if anything catches my eye.
Posted on 2009-04-17 22:39:02 by SpooK
OK. One thing that immediately catches my attention, is that msg_help is at the end of kernel.asm. As lone_samurai5 mentioned, your symptom could be a result of a loading problem.

Double check your loading process and make that the entire kernel.asm file is being loaded into RAM.
Posted on 2009-04-17 22:53:24 by SpooK
Yes, i was loading just 1 sector, and my kernel has 2 !

Problem Solved !!
Posted on 2009-04-18 01:22:22 by patrickniceboy