nasm汇编写的一个例子--显示内存内容

jmp load_kernel
db "---Bit System V0.01---"

change_mode:
mov ax,0x0012
int 10h
ret

print_char_hex:
push bx
mov ah, 0x0e
mov bl, al
add bl, 5

mov dl, al

mov cl, 4
shr al, cl

add al, 48
cmp al, 58
jc noadd
add al, 7
noadd:
int 10h

mov al, dl

and al, 0x0f

add al, 48
cmp al, 58
jc noadd2
add al, 7
noadd2:
int 10h

mov al, ' '
int 10h
int 10h
pop bx
ret

load_kernel:
call change_mode

mov bx, 0x0100
mov es, bx
mov bx, 0x0000

mov ax, 0x0201
mov cx, 0x0002
mov dx, 0x0080
int 0x13

mov ax, 0x0
mov bx, 0x0
loop:
mov es, ax

printmem:
mov ax, [es:bx]
call print_char_hex
add bx, 1
cmp bx, 578

jc printmem

mov dx,100
mov cx,100

mov bx,0
linea:
mov ax,0x0c19
add cx,1
int 10h
cmp cx,540
jc linea

lineb:
mov ax,0x0c19
add dx,1
int 10h
cmp dx,380
jc lineb

linec:
mov ax,0x0c19
sub cx,1
int 10h
cmp cx,100
jnc linec

lined:
mov ax,0x0c19
sub dx,1
int 10h
cmp dx,100
jnc lined

mov ax,es
mov al,ah
call print_char_hex
mov ax,es
call print_char_hex

key_press:
in al, 0x60
cmp al,65
jnc key_press

call change_mode

mov ax,es
add ax,28
jmp loop






















lgdt [gdt_descriptor]

cli

in al, 92h
or al, 00000010b
out 92h, al

mov eax, cr0
or eax, 0x1
[SECTION .s32]
mov cr0, eax

sti

mov ah, 0x0e

mov al, 'H'
mov bl,10
int 10h

mov al, 'e'
mov bl,2
int 10h

mov al, 'l'
mov bl,3
int 10h

mov al, 'l'
mov bl,4
int 10h

mov al, 'o'
mov bl,22
int 10h

loo:

;printchar
mov ah, 0x0e
mov bl,10
int 10h

in al, 0x60

gdt_start:
dd 0x0, 0x0
dw 0xffff, 0x0, 0x0
db 10011010b, 11001111b, 0x0

dw 0xffff, 0x0, 0x0
db 10010010b, 11001111b, 0x0
gdt_end:

gdt_descriptor:
dw gd

sys.s

nasm sys.s

得到二进制的sys文件

把sys文件写入引导扇区,然后在最后加上55AA就可以启动了。

我这里制作了一个读写扇区的工具,当sys.s文件发生改变的时候就会自动写入/dev/sdc第一个扇区,并自动重启虚拟机。但要手动修改到你sys.s和虚拟机文件的实际位置。请谨慎操作,丢失数据概不负责:

https://download.csdn.net/download/weixin_35867652/85126162

你可能感兴趣的:(开发语言)