標籤:組合語言學習筆記
編程:啟動程式實現很簡單的功能在螢幕中央 ;列印一行字串(彙編+c+red hat linux實現)
組合語言編寫:
boot.asm啟動程式碼:
;我們的啟動程式實現很簡單的功能在螢幕中央
;列印一行字串
org 07c00h ;org指令明確告訴編譯器我程式開始地址是07c00h,而不是
;原來的00000
;int彙編指令 int 10h
mov ax,cs
mov es,ax
mov bp,msgstr ;es:bp ;指向的內容就是我們要顯示的
字串的地址
mov cx,12 ;字串長度
mov dh,12 ;顯示的行號
mov dl,36 ;顯示的列號
mov bh,0 ;顯示的頁數
mov al,1 ;顯示的是串結構
mov bl,0ch ;顯示字元屬性 黑底紅字
mov ah,13h ;明確調用13h子程式
msgstr: db "hello my osi"
int 10h
times 210-($-$$) db 0 ;重複N次每次填儲值為0
dw 55aah
jmp $ ;不斷跳轉到當前位置是個死迴圈。註:$是當前地址。
彙編運行環境圖例:
650) this.width=650;" alt="啟動程式實現很簡單的功能在螢幕中央 ;列印一行字串(彙編+c+red hat linux實現) - 文豪 - WELCOME MY BLOG." src="http://img2.ph.126.net/rV3NSElSmle8ChWRehmk3g==/3245125006597545695.jpg" style="border:0px;margin:0px 10px 0px 0px;" />
虛擬機器系統:red hat linux運行環境下編寫c語言代碼實現:
將自己已經編譯好的彙編boot.asm啟動程式載入虛擬機器中,在虛擬機器中寫入c語言代碼實現boot.bin的512B啟動程式拷貝。
#include<stdio.h>
#include<fcnt1.h>
#include<sys/types.h>
#include<sys/stat.h>
int main(int argc,char *argv[])
{
int fd_source;
int fd_dest;
int read_count = 0;
char buffer[512]={0};
fd_source=open("boot.bin",0_RDONLY);
if(fd_source<0)
{
perror("open boot.bin error:");
return 0;
}
fd_dest=ope("virtual_floppy.vfd",0_RWONLY);
while ((read_count=read(fd_source,buffer,512))>0)
{
write(fd_dest,buffer,read_count);
memset(buffer,0,512);
}
printf("write image ok!");
return 0;
}
操作步驟圖例:
第一步:將我們在彙編寫好的空白boot啟動鏡像載入
接下來,我們在輸入此命令準備寫入c語言代碼
650) this.width=650;" alt="啟動程式實現很簡單的功能在螢幕中央 ;列印一行字串(彙編+c+red hat linux實現) - 文豪 - WELCOME MY BLOG." src="http://img1.ph.126.net/dOCnLnEut_HF_JP7_hNefA==/303148550017726501.jpg" style="border:0px;margin:0px 10px 0px 0px;" />
第二步:我們有了c語言基礎,那麼我們開始將512B的boot.bin的啟動程式開始進行拷貝
650) this.width=650;" alt="啟動程式實現很簡單的功能在螢幕中央 ;列印一行字串(彙編+c+red hat linux實現) - 文豪 - WELCOME MY BLOG." src="http://img0.ph.126.net/QtFhfjwRYAFWnbebDiBqVg==/4805622277481413032.jpg" style="border:0px;margin:0px 10px 0px 0px;" />
第三步:好了,我們已經將boot.bin寫好了
650) this.width=650;" alt="啟動程式實現很簡單的功能在螢幕中央 ;列印一行字串(彙編+c+red hat linux實現) - 文豪 - WELCOME MY BLOG." src="http://img2.ph.126.net/Is7gW5sSf3Bs9p0JqHY_-w==/705939241690819370.jpg" style="border:0px;margin:0px 10px 0px 0px;" />
650) this.width=650;" alt="啟動程式實現很簡單的功能在螢幕中央 ;列印一行字串(彙編+c+red hat linux實現) - 文豪 - WELCOME MY BLOG." src="http://img0.ph.126.net/Prd5g_8k_OSZ5m3jfv5XsQ==/4854880398405824049.jpg" style="border:0px;margin:0px 10px 0px 0px;" />
用winImage啟動下我們編寫好的程式。
650) this.width=650;" alt="啟動程式實現很簡單的功能在螢幕中央 ;列印一行字串(彙編+c+red hat linux實現) - 文豪 - WELCOME MY BLOG." src="http://img0.ph.126.net/CgYubwQRxzygwhZ-iEYZ6Q==/6597961470588608232.jpg" style="border:0px;margin:0px 10px 0px 0px;" />
作者註明:剛學習彙編,請大牛勿噴!!!
本文出自 “努力奮鬥,互相提高” 部落格,請務必保留此出處http://c10086.blog.51cto.com/6433044/1414030