Skip to contentSkip to conversation

please help me

DISCUSSION Tu Ha 2 participants 3 messages Apr 24, 2006

lore
Share & tools
lore

Tu Ha

author
#0 lore raw

Hi,
I am a beginner writing a boot loader. I use gas to write it and got a weird issue. The following code just try to show out the screen the symbol "1" ten times

.code16
.section .text
.globl _start
_start:

        movw    $STACK_SEGMENT, %sp
        movw    %sp, %ss
        movw    $STACK_SIZE, %sp
        pushw   %cs
        popw    %ds
        pushw   $SCREEN_SEGMENT
        popw    %es
        jmp     show_banner

show_banner:

        movb    $0x07, %ah #white on black
        movb    char, %al  #show this char
        movw    $10,  %cx  #show this char 10 times
        movw    $0, %di    #show at 0,0
run_banner:
        movw    %ax, %es:(%di)
        inc     %di
        inc     %di
        loop    run_banner

die: jmp die

#.section .data
char: .ascii "1"
.org 510
boot_flag: .word 0xAA55

#constants

.equ STACK_SEGMENT     , 0x9000      # Top of conventional memory
.equ STACK_SIZE        , 0xffff      # 64K - 1 bytes of stack
.equ SCREEN_SEGMENT    , 0xb800

However, when running, it shows out a symbol in the extend ascii table instead of "1" !!!?
It seems I cannot reference to the "char" memory location. Why?

How can I debug the binary?

Any help is appreciated.

Tuha.

#1 lore raw

Tu Ha wrote:

...

Quoted 1 line

It seems I cannot reference to the "char" memory location. Why?

Wrong combination of ".org" and ds register, I think. Either use ".org 0x7C00", and load ds from cs (presumably zero) as you do (you'll have to adjust the .org on the signature, too). Or... leave it at ".org 0" (I assume that's what Gas defaults to), and load ds with 0x7C0. (bios loads us at 0x7C00, which can be represented as either 0000:7C00 or 07C0:0000).

Quoted 1 line

How can I debug the binary?

Bochs? I've never used it, but I understand it'll debug bootsectors...

Happy bootin',
Frank

author
#2 lore raw

Thanks a lot.
I got your point. Wrong assumption problem.
It runnnnnnnnnnnnnnnnnnns

Quoted 23 lines · Frank Kotler

Tu Ha wrote:

...

Quoted 1 line

It seems I cannot reference to the "char" memory location. Why?

Wrong combination of ".org" and ds register, I think. Either use ".org 0x7C00", and load ds from cs (presumably zero) as you do (you'll have to adjust the .org on the signature, too). Or... leave it at ".org 0" (I assume that's what Gas defaults to), and load ds with 0x7C0. (bios loads us at 0x7C00, which can be represented as either 0000:7C00 or 07C0:0000).

Quoted 1 line

How can I debug the binary?

Bochs? I've never used it, but I understand it'll debug bootsectors...

Happy bootin',
Frank

-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html