当前位置:网站首页>匯編實例解析--實模式下屏幕顯示
匯編實例解析--實模式下屏幕顯示
2022-07-03 16:49:00 【raindayinrain】
1.方式1
; 開機上電,先執行BIOS,再執行硬盤主引導程序,也即這裏。
; 此時屬於實模式,16比特模式,此時主引導程序所在的物理內存比特置是0x7c00
; 物理內存區域:0xb8000~0xbFFFF是顯存區域。
; 顯存模式80*25。每個字符占據2個字節,一個是字符ascii碼,一個是顯示格式。
mov ax,0xb800
mov es,ax
; es可用於數據物理內存尋址輔助段寄存器,默認是ds
mov byte [es:0x00],'L'
mov byte [es:0x01],0x07
mov byte [es:0x02],'a'
mov byte [es:0x03],0x07
mov byte [es:0x04],'b'
mov byte [es:0x05],0x07
mov byte [es:0x06],'e'
mov byte [es:0x07],0x07
mov byte [es:0x08],'l'
mov byte [es:0x09],0x07
mov byte [es:0x0a],' '
mov byte [es:0x0b],0x07
mov byte [es:0x0c],"o"
mov byte [es:0x0d],0x07
mov byte [es:0x0e],'f'
mov byte [es:0x0f],0x07
mov byte [es:0x10],'f'
mov byte [es:0x11],0x07
mov byte [es:0x12],'s'
mov byte [es:0x13],0x07
mov byte [es:0x14],'e'
mov byte [es:0x15],0x07
mov byte [es:0x16],'t'
mov byte [es:0x17],0x07
mov byte [es:0x18],':'
mov byte [es:0x19],0x07
; 進入主引導程序時候,cs內容是0x0000
mov cx,cs
mov ds,cx
mov ax,number
mov bx,10
mov dx,0
; dx:ax / bx,商放ax,餘數放dx
div bx
mov [0x7c00+number+0x00],dl ; 存儲餘數,這是個比特
xor dx,dx ; dx會被設置為0
div bx
mov [0x7c00+number+0x01],dl ; 存儲餘數,這是十比特
xor dx,dx
div bx
mov [0x7c00+number+0x02],dl ; 存儲餘數,這是百比特
xor dx,dx
div bx
mov [0x7c00+number+0x03],dl ; 存儲餘數,這是千比特
xor dx,dx
div bx
mov [0x7c00+number+0x04],dl ; 存儲餘數,這是萬比特
mov al,[0x7c00+number+0x04]
add al,0x30 ; 這是將萬比特的十進制數值轉化為ascii代碼
mov [es:0x1a],al ; 繼續向顯存寫入萬比特ascii
mov byte [es:0x1b],0x04
mov al,[0x7c00+number+0x03]
add al,0x30
mov [es:0x1c],al
mov byte [es:0x1d],0x04
mov al,[0x7c00+number+0x02]
add al,0x30
mov [es:0x1e],al
mov byte [es:0x1f],0x04
mov al,[0x7c00+number+0x01]
add al,0x30
mov [es:0x20],al
mov byte [es:0x21],0x04
mov al,[0x7c00+number+0x00]
add al,0x30
mov [es:0x22],al
mov byte [es:0x23],0x04
mov byte [es:0x24],'D'
mov byte [es:0x25],0x07
; 控制顯存顯示一段內容,接著顯示number,接著顯示D。
infi: jmp near infi
; 匯編語言支持標號,標號是一個數值。反映了指示比特置的偏移量。
; 這裏number反映了db所聲明的5個1字節數據起始比特置距離本程序起始比特置的距離
number db 0,0,0,0,0
; 匯編支持times前綴,用於錶示其後指令執行多少次。
; 聲明203個1字節數據,占據連續的203存儲空間。
times 203 db 0
; 主引導程序512字節,最後兩個字節需要為0x55 0xaa
db 0x55,0xaa
2.方式2
jmp near start
mytext db 'L',0x07,'a',0x07,'b',0x07,'e',0x07,'l',0x07,' ',0x07,'o',0x07,\
'f',0x07,'f',0x07,'s',0x07,'e',0x07,'t',0x07,':',0x07
number db 0,0,0,0,0
start:
mov ax,0x7c0
mov ds,ax
mov ax,0xb800
mov es,ax
cld
mov si,mytext
mov di,0
mov cx,(number-mytext)/2
; 將ds:si處,cx個字,正向移動到es:di處
rep movsw
mov ax,number
mov bx,ax
mov cx,5
mov si,10
digit:
xor dx,dx ; dx設置為0
div si ; dx:ax / si,商ax,餘數dx
mov [bx],dl ; 將個比特存儲到number標記的首個內存比特置
inc bx
loop digit ; 循環執行digit,算上一開始執行的,共執行cx次
mov bx,number
mov si,4
show:
mov al,[bx+si] ; number標記比特置第4個字節開始[從0計數]
add al,0x30 ; 轉化得到字節的ascii碼
mov ah,0x04 ; 顯示屬性
mov [es:di],ax ; 存儲到顯存中緊跟著前面標號字符串之後
add di,2
dec si
jns show ; 循環,直到dec si的結果變成負數,才停止循環繼續執行。
mov word [es:di],0x0744
jmp near $
times 510-($-$$) db 0 ; $代錶當前比特置距離起始比特置的偏移量。
db 0x55,0xaa
3.利用棧進行求和
jmp near start ; 跳轉
message db '1+2+3+...+100='
start:
mov ax,0x7c0
mov ds,ax
mov ax,0xb800
mov es,ax
mov si,message
mov di,0
mov cx,start-message
@g:
mov al,[si] ; 從物理內存到寄存器
mov [es:di],al ; 從寄存器到物理內存,因為不支持直接從物理內存1到物理內存2
inc di
mov byte [es:di],0x07
inc di
inc si ; di指向顯存比特置2個字節來顯示一個si處的字節
loop @g ; 通過cx控制次數
xor ax,ax ; ax清零
mov cx,1 ;
@f:
add ax,cx
inc cx
cmp cx,100
jle @f ; 只要比較結果是小於等於就繼續循環
xor cx,cx
mov ss,cx
mov sp,cx
mov bx,10
xor cx,cx
@d:
inc cx
xor dx,dx
div bx ; dx:ax / bx,商ax,餘數dx
or dl,0x30 ; 實現dl+0x30一樣的效果
push dx ;利用棧的存儲計算結果--個比特,十比特,...
cmp ax,0
jne @d ; 比較結果不是相等,繼續循環
@a:
pop dx
mov [es:di],dl ; 將出棧的ascii字符複制到顯存緊跟前面顯示部分之後
inc di
mov byte [es:di],0x07
inc di
loop @a ; 通過cx來控制循環次數,每次到loop這裏,cx先减去1,若此時cx為0,則無法繼續循環。否則,繼續循環。
jmp near $
times 510-($-$$) db 0
db 0x55,0xaa
边栏推荐
- arduino-esp32:LVGL项目(一)整体框架
- 2022.02.14_ Daily question leetcode five hundred and forty
- 浅谈拉格朗日插值及其应用
- [sword finger offer] 58 - I. flip the word order
- Mysql database DDL and DML
- CC2530 common registers for crystal oscillator settings
- [Jianzhi offer] 58 - ii Rotate string left
- Le zèbre a été identifié comme un chien, et la cause de l'erreur d'AI a été trouvée par Stanford
- Golang anonymous function use
- Shentong express expects an annual loss of nearly 1billion
猜你喜欢
word 退格键删除不了选中文本,只能按delete
Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer
ucore概述
Explore Netease's large-scale automated testing solutions see here see here
Netease UI automation test exploration: airtest+poco
UCORE overview
2022.02.14_ Daily question leetcode five hundred and forty
To resist 7-Zip, list "three sins"? Netizen: "is the third key?"
CC2530 common registers for ADC single channel conversion
CC2530 common registers for port interrupts
随机推荐
Client does not support authentication protocol requested by server; consider upgrading MySQL client
Basis of target detection (IOU)
[2. Basics of Delphi grammar] 2 Object Pascal data type
What kind of material is 14Cr1MoR? Analysis of chemical composition and mechanical properties of 14Cr1MoR
关于视觉SLAM的最先进技术的调查-A survey of state-of-the-art on visual SLAM
Visual SLAM algorithms: a survey from 2010 to 2016
Preventing/catching “IllegalArgumentException: parameter must be a descendant of this view” error
Arduino esp32: overall framework of lvgl project (I)
MySQL user management
Develop team OKR in the way of "crowdfunding"
RF analyze demo build step by step
CC2530 common registers
Kotlin学习快速入门(7)——扩展的妙用
IDEA-配置插件
What material is sa537cl2 equivalent to in China? Sa537cl2 corresponding material
Acwing game 58
数据分析必备的能力
Idea configuration plug-in
[Jianzhi offer] 57 - ii Continuous positive sequence with sum s
Daily code 300 lines learning notes day 10