这次实验涉及一些汇编知识,不过指导书上写的还是比较清楚的,抄一抄上面的代码,基本就ok了。
实验主要需要改3个文件
build.c 只要吧文件末尾稍微改成这样
if ((id=open(argv[3],O_RDONLY,0)) >= 0) //就是打开文件的一个函数,失败的话会返回-1哦~
{for (i=0 ; (c=read(id,buf,sizeof buf))>0 ; i+=c )
if (write(1,buf,c)!=c)
die("Write call failed");
close(id);
fprintf(stderr,"System is %d bytes.\n",i);
if (i > SYS_SIZE*16)
die("System is too big");}
return(0);
build.c 原来是这样的
if ((id=open(argv[3],O_RDONLY,0))<0)
die("Unable to open 'system'");
// if (read(id,buf,GCC_HEADER) != GCC_HEADER)
// die("Unable to read header of 'system'");
// if (((long *) buf)[5] != 0)
// die("Non-GCC header of 'system'");
for (i=0 ; (c=read(id,buf,sizeof buf))>0 ; i+=c )
if (write(1,buf,c)!=c)
die("Write call failed");
close(id);
fprintf(stderr,"System is %d bytes.\n",i);
if (i > SYS_SIZE*16)
die("System is too big");
return(0);
bootsect.s 基本不用过动,如果觉得无聊可以改一改输出的那个字符串。
msg1:
.byte 13,10 !这个好像是伪指令 byte和ascii是两种数据的表示方法
.ascii "fuck..."
.byte 13,10,13,10
主要需要改动的是setup这个文件。
首先解释一下,输出一条字符串的代码。
!print the message
MOV AX,#SETUPSEG
MOV ES,AX !赋值给ES不能直接赋值,需要用AX做中转
MOV AH,#0X03 !下三行为读入光标位置
XOR BH,BH
INT 0X10
MOV CX,#25 !字符串长度,设大一点没关系~
MOV BX,#0X0007
MOV BP,#MSG2
MOV AX,#0X1301
INT 0X10
ES 和 BP 分别是段寄存器和,偏移地址,把ES设#SETUPSEG是内存中存放setup.s开始的地方,BP表示存放#MSG2的偏移地
<