当前位置:网站首页>匯編實例解析--實模式下屏幕顯示
匯編實例解析--實模式下屏幕顯示
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边栏推荐
- Mysql 将逗号隔开的属性字段数据由列转行
- Arduino esp32: overall framework of lvgl project (I)
- Recommendation of good books on learning QT programming
- CC2530 common registers for ADC single channel conversion
- CC2530 common registers
- CC2530 common registers for serial communication
- 【LeetCode】94. Middle order traversal of binary tree
- 【剑指 Offer 】57 - II. 和为s的连续正数序列
- PHP production website active push (website)
- CC2530 common registers for crystal oscillator settings
猜你喜欢

Google Earth engine (GEE) - daymet v4: daily surface weather data set (1000m resolution) including data acquisition methods for each day

8 cool visual charts to quickly write the visual analysis report that the boss likes to see

word 退格键删除不了选中文本,只能按delete

CC2530 common registers for timer 1

NLP四范式:范式一:非神经网络时代的完全监督学习(特征工程);范式二:基于神经网络的完全监督学习(架构工程);范式三:预训练,精调范式(目标工程);范式四:预训练,提示,预测范式(Prompt工程)

What is the material of 13mnnimor? 13mnnimor steel plate for medium and low temperature pressure vessels

Data driving of appium framework for mobile terminal automated testing

What material is sa537cl2 equivalent to in China? Sa537cl2 corresponding material

CC2530 common registers for serial communication

美团一面:为什么线程崩溃崩溃不会导致 JVM 崩溃
随机推荐
Necessary ability of data analysis
Hands on in-depth learning notes (XIV) 3.7 Simple implementation of softmax regression
NSQ source code installation and operation process
What material is sa537cl2? Analysis of mechanical properties of American standard container plate
网络安全web渗透技术
13mnnimo5-4 German standard steel plate 13MnNiMo54 boiler steel 13MnNiMo54 chemical properties
2022爱分析· 国央企数字化厂商全景报告
Golang anonymous function use
Leetcode binary search tree
Summary of three methods of PHP looping through arrays list (), each (), and while
【剑指 Offer】58 - I. 翻转单词顺序
The way of wisdom (unity of knowledge and action)
IDEA-配置插件
[2. Basics of Delphi grammar] 1 Identifiers and reserved words
NLP四范式:范式一:非神经网络时代的完全监督学习(特征工程);范式二:基于神经网络的完全监督学习(架构工程);范式三:预训练,精调范式(目标工程);范式四:预训练,提示,预测范式(Prompt工程)
【剑指 Offer】58 - II. 左旋转字符串
Google Earth engine (GEE) - daymet v4: daily surface weather data set (1000m resolution) including data acquisition methods for each day
Learn from me about the enterprise flutter project: simplified framework demo reference
什么是质押池,如何进行质押呢?
中南大学|通过探索理解: 发现具有深度强化学习的可解释特征