-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.s
More file actions
65 lines (52 loc) · 1.48 KB
/
hello.s
File metadata and controls
65 lines (52 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
STACK_SEG = 0x4000 #堆栈段的起始位置,预处理
VGA_SEG = 0xb800 #根据协议
SCREEN_SIZE = 4000 #25*80*2 每个字符两个字节,属性和内容
WHITE = 0x7 #可查vga手册,白色为0x7
.code16 #16位
.section ".bsdata","a"
hello_message:
.ascii "hello,JL16110020" #要显示的字符
.byte 0 #后面加个空字符
.section ".signature","a"
.globl sig
sig: .word 0xAA55 #offset 512
二进制文件末尾为aa55,才可以作为引导扇区代码,第一个扇区为512字节
.section ".bstext","ax"
.globl bootsect_start
bootsect_start:
jmp begin
.p2align 4 #边界对齐
begin:
cli #关中断
movw %cs,%ax #设置代码段位置
movw %ax,%ds
movw %ax,%es
movw $STACK_SEG,%ax #设置堆栈段位置
movw %ax,%ss
xorw %sp,%sp #清零
cld #开中断
clear: #清屏
movw $VGA_SEG,%ax #加载
movw %ax,%es
xorw %di,%di
movw $0000,%ax #初始位置
movw $SCREEN_SIZE,%cx #大小
rep stosb #重复执行
print_hello:
movw $hello_message,%si #加载字符串
movb $WHITE,%ah #加载颜色
movl $(11*80),%edx #加载大小
call print #调用输出函数
dead: jmp dead #死循环
print:
movw $VGA_SEG,%bx
movw %bx,%es
loop:
lodsb #读取第一个字符
andb %al,%al
jz end #如果标志寄存器z里面是0 则跳转
movw %ax,%es:0(,%edx,2)
incl %edx #自增1
jmp loop
end:
ret #函数调用返回