Home > other >  Assembly code can be displayed correctly in the bochs string, but in VirtualBox virtual machine show
Assembly code can be displayed correctly in the bochs string, but in VirtualBox virtual machine show

Time:01-09


problems have been found, to create the virtual machine hard disk should be set to PATA mode


As title, has written two small program, one of which is a user program, used to display a word; Another is loader, is located in the main boot sector, to the user program is loaded into memory and execute,

Now appear this problem, can only see the cursor flashing in VirtualBox, but does not see the string; With the bochs debugging finally can see the strings, the following is a program running in VirtualBox, respectively, in the bochs screenshot when debugging,







///////////////////////////////////////////////____ user program __________________________/////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

; The user program description:
; Code_entry program_length header contains the program length, entry points, relocation table item number and the relocation table

;===========================================================
SECTION header align=16 vstart=0
Program_length dd program_end; Length of program

Code_entry dw start; The entry point offset
Dd section. Code. Start; The entry point for the address

Realloc_tbl_len dw (header_end - code_segment)/4; Relocation table item

Code_segment dd section. Code. Start; Relocation table, code, data, stack segment segment address
Data_segment dd section. Data. Start
Stack_segment dd section. Stack. Start

Header_end:; At the end of the head


;===========================================================
SECTION data align=16 vstart=0

MSG dd 'Welcome to GoalPower workroom! '; Displayed on the screen of the string
Dd 0

;===========================================================
A SECTION of code align=16 vstart=0

Start:
Mov ax, [stack_segment]; Initialize the stack segment register
Mov ss, ax
Mov sp, stack_end; Initialize the stack pointer register

Mov ax, [data_segment]; Initialize the data segment registers (there is no initialization ES, because inside the loader has been set up)
Mov ds, ax

Mov bx, MSG. To show the offset address of the string is assigned to BX
Call put_string; Call shows that the process of the string

JMP $; Infinite loop

; -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
; According to the process of the string, the character one by one on the memory
; Input: BX=the first address of the string

Put_string:
Push ax
Push cx
Push dx
Push bx
Push si
Push the ds
Push es

Mov ax, 0 xb800
Mov es, ax
Mov ch, 0 x04
Xor si, si

Put_char:
Mov cl, [bx]
The or cl, cl
Jz. Exit
Mov word [ES: si], cx
The add si, 2
Inc bx
JMP. Put_char

Exit:

Pop es
Pop the ds
Pop si
Pop bx
Pop dx
Pop cx
Pop ax

Ret


;===========================================================
SECTION stack the align=16 vstart=0; The stack segment

The resb 0 x100

Stack_end:; At the end of the stack segment


;===========================================================
SECTION trail the align=16
Program_end:; At the end of the program




///////////////////////////////////////////////____ loader __________________________/////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

App_lba_start equ 100; The user program in the logical sector number

SECTION 16 vstart MBR align==0 x7c00

; Set the stack segment and stack pointer
Mov ax, 0
Mov ss, ax
Mov sp, ax

Mov ax, [cs: phy_base]; The logic of calculation used to load the user program segment address
Mov dx, [cs: phy_base + 0 x02]
Mov bx, 16
Div bx
Mov ds, ax; Set the DS and ES to point that to operate
Mov es, ax

; The following the start of a reader
Xor di, di
Mov si, app_lba_start; Program at the start of a hard disk logical sector,
Xor bx, bx; Loaded into the DS: 0 x0000
Call read_hard_disk_0

; The following determining how an entire program
Mov dx, [2]
Mov ax, [0]
Mov bx, 512;
512 bytes/sectorsDiv bx
CMP dx, 0
JNZ @ 1; Not clean, so the results less than the actual number of sectors 1
Dec ax; Have read a sector, the total number of sectors minus 1
@ 1:
CMP ax, 0; Considering the actual length less than or equal to 512 bytes
the condition of theJz direct

; Read the rest of the sector
Push the ds; The following will use and change the DS register

Cx, mov ax; Cycles (remaining sectors)
@ 2:
Mov ax, ds
The add ax, 0 x20; For the next to the 512 bytes for boundary segment address
Mov ds, ax

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related