Hello World bootloader not working

后端 未结 2 1252
余生分开走
余生分开走 2021-02-10 03:29

I\'ve been working through the tutorials on this webpage which progressively creates a bootloader that displays Hello World.

The 2nd tutorial (where we attempt to get

2条回答
  •  梦毁少年i
    2021-02-10 04:00

    I think the problem is likely to be related to the origin specified.

    [ORG 0x7C00]    ;Origin, tell the assembler that where the code will
    

    Based on the conversation we've been having it appears that the address isn't as predicted in some way. It might simply that DS the data segment register is not what you expect. You might actually be able to get the original listing from the web page to work by adding a push and pop of ds before the call to display the string like this,

     push cs
     pop ds
    

    If not the following code works.

     [ORG 0x000]    ; switched to 0 since we are going to try to correct it ourself
    
     call nextinstruction
     nextinstruction:    ; get the return address of the call into dx
     pop dx              ; which is essentially the start of the code + 3 (3 bytes for the call instruction)
     MOV SI, HelloString ;Store string pointer to SI
     add si, dx          ; add IP from start of program
     sub si, 3           ; subtract the 3 the call instruction probably took
     push cs
     pop ds              ; make ds the same as cs.  
     CALL PrintString   ;Call print string procedure
     JMP $      ;Infinite loop, hang it here.
    

    This code figures out the offset at runtime of the code being run and also makes sure DS is point to the same segment. Unless otherwise noted instructions involving SI generally also use DS as their code segment to reference the memory.

    DS is a segment register and you might want to read something like the Art of Assembly to learn more.

    Earlz is also doing the same sort of thing, just making sure the registers are correct so that the memory address is referenced correctly. It's just he knows more about the boot sector specifics than me.

提交回复
热议问题